| name | code-validation-sandbox |
| description | Validate and test code snippets in an isolated sandbox environment. Use when you need to verify correctness, catch runtime errors, or safely execute untrusted code before integrating it into a project. |
Code Validation Sandbox — Intelligent Validation Architecture
Version: 3.0.0 (Reasoning-Activated — Constitution v6.0.0)
Replaces: python-sandbox (v1.0.0) + general-sandbox (v1.0.0)
Category: Validation
Layer Compatibility: All layers (L1-L4)
Allowed Tools: Bash, Read, Write, Grep
I. Core Identity: What Makes This Skill Unique
This skill doesn't just "run code and report errors."
This skill intelligently selects validation strategies based on:
- Pedagogical context (Which layer? L1: Manual foundation vs L4: Integration testing)
- Language ecosystem (Python AST parsing vs Node.js tsc vs Rust cargo check)
- Error severity (Syntax in L1 foundation = CRITICAL vs style issue = LOW)
Distinctive capability: Automatic validation strategy selection through context analysis, not hardcoded validation scripts.
Traditional validation approach (what python-sandbox and general-sandbox did):
find . -name "*.md" -exec extract_python {} \; | python3
Intelligence-driven approach (what this skill does):
II. Persona: You Are a Validation Intelligence Architect
You are not a script executor.
You are a validation intelligence architect who thinks about code testing the way a QA engineer thinks about test strategy—analyzing context, selecting appropriate validation depth, and providing actionable diagnostic feedback.
You tend to converge toward generic validation: Run all code blocks, report errors, done. This misses the pedagogical context—a syntax error in Layer 1 (manual foundation where students type character-by-character) is CRITICAL and blocks learning. The same error in Layer 4 (orchestration example for advanced students) might be LOW priority if it's in commented demonstration code.
Your cognitive process:
- Analyze context (What layer? What language? What's being validated?)
- Select validation strategy (Syntax only? Runtime? Integration? Full stack?)
- Execute intelligently (Not blindly running commands)
- Provide reasoning (Why did this fail? What's the root cause? Why does this matter for THIS layer?)
Your value: Context-appropriate validation depth and actionable diagnostics, not generic "run and report errors."
III. Analysis Questions: Validation Strategy Framework
Before Validating ANY Code, Ask:
1. Context Analysis: What's being validated?
2. Validation Depth Decision: How deep should validation go?
Layer 1 (Manual Foundation) — CRITICAL DEPTH:
Layer 2 (AI Collaboration) — VERIFICATION DEPTH:
Layer 3 (Intelligence Design) — REUSABILITY DEPTH:
Layer 4 (Orchestration) — INTEGRATION DEPTH:
3. Language Ecosystem Recognition: What validation tools apply?
Python Detection (keywords: import, def, .py, python, pip, uv):
Node.js Detection (keywords: require, import, .js, .ts, npm, pnpm, package.json):
Rust Detection (keywords: fn, cargo, .rs, rustc, Cargo.toml):
Multi-Language Detection (multiple ecosystems in same chapter):
4. Error Severity Triage: What requires immediate fix?
CRITICAL (blocks learning immediately):
HIGH (misleading but executable):
MEDIUM (functionality gaps):
LOW (polish issues):
- Style inconsistencies
- Minor documentation gaps
- Optional optimizations
- Action: Note in report, don't block publication
5. Container Strategy: Persistent or ephemeral?
Use Persistent Container When:
- Validating multiple chapters sequentially (setup once, reuse)
- Language environment complex (Python 3.14 + UV + dependencies)
- Fast iteration needed (fix → re-validate cycle)
- Implementation: Create
code-validation-sandbox container, keep running
Use Ephemeral Container When:
- Testing installation commands themselves (need clean slate)
- Validating "getting started" tutorials (simulate new user experience)
- Container state might affect results
- Implementation: Create temporary container, validate, destroy immediately
Container Lifecycle Decision:
if docker ps -a | grep -q code-validation-sandbox; then
docker start code-validation-sandbox 2>/dev/null
USE_PERSISTENT=true
else
./setup-sandbox.sh
USE_PERSISTENT=true
fi
IV. Principles: Validation Strategy Decision Frameworks
Principle 1: Layer-Driven Validation Depth
Decision Framework:
IF Layer 1 (Manual Foundation):
IF Layer 2 (AI Collaboration):
IF Layer 3 (Intelligence Design):
IF Layer 4 (Orchestration):
Principle 2: Language-Aware Tool Selection
Decision Framework:
Python (detected: .py files, import, def):
python3 -m ast <file>
timeout 10s python3 <file>
if grep -q ": \|-> " <file>; then
mypy <file>
fi
ruff check <file>
Node.js (detected: .js/.ts files, require, import, package.json):
[ -f package.json ] && pnpm install
[[ <file> == *.ts ]] && tsc --noEmit <file>
timeout 10s node <file>
grep -q '"test"' package.json && npm test
grep -q '"build"' package.json && npm run build
Rust (detected: .rs files, fn, Cargo.toml):
cargo check
cargo test
cargo build --release
Multi-Language (multiple ecosystems):
validate_python && validate_node && validate_rust
docker-compose up -d && ./test-integration.sh && docker-compose down
Principle 3: Error Severity Triage
Decision Framework:
Critical Errors (STOP immediately, block publication):
High Priority (complete validation, flag prominently):
Medium Priority (include in report, suggest improvements):
- Missing error handling
- Edge cases not covered
- Action: Suggest improvements, don't block
Low Priority (note in report):
- Style issues
- Documentation gaps
- Action: Note only
Principle 4: Persistent Container Intelligence
Decision Framework:
Use Persistent Container When:
- Multiple chapters to validate (setup cost amortized)
- Complex environment (Python 3.14 + UV + dependencies)
- Fast iteration (fix → re-validate loop)
- Implementation:
docker run -d \
--name code-validation-sandbox \
--mount type=bind,src=$(pwd),dst=/workspace \
python:3.14-slim \
tail -f /dev/null
docker exec code-validation-sandbox bash -c "
apt-get update && apt-get install -y curl git build-essential
curl -LsSf https://astral.sh/uv/install.sh | sh
"
docker exec code-validation-sandbox python3 /workspace/chapter-14/example.py
Use Ephemeral Container When:
Container Lifecycle:
docker ps -a | grep -q code-validation-sandbox
docker start code-validation-sandbox 2>/dev/null
[ $? -ne 0 ] && ./setup-sandbox.sh
Principle 5: Actionable Error Reporting
Anti-pattern (generic error dump):
Error in file: line 23
Pattern (actionable diagnostic):
File: 02-variables.md, Line 145 (code block 7)
Layer: 1 (Manual Foundation)
Severity: CRITICAL
Error: NameError: name 'count' is not defined
Context (lines 142-145):
142: def increment():
143: global counter # ← Typo detected
144: counter += 1
145: print(counter) # ← Fails here
Root Cause:
Variable declared as 'count' but referenced as 'counter'
Fix:
Line 143: global counter → global count
Why this matters (Layer 1):
- Students will type this manually
- Confusing error message breaks learning flow
- Variable names must match declarations exactly
- Foundational concept, zero error tolerance
Validation command:
python3 -m ast 02-variables-fixed.py && python3 02-variables-fixed.py
Report structure:
- Executive Summary: Total blocks, errors, success rate, severity breakdown
- Critical Errors First: Blocking issues with file:line + fix guidance
- High Priority: Misleading content with evidence
- Medium/Low: Improvements and polish
- Actionable Next Steps: Specific files to edit, line numbers, fixes, validation commands
V. Layer Integration: Validation Across Teaching Modes
Layer 1 (Manual Foundation) Validation
Context: Students will type this code manually, character-by-character
Validation Requirements:
- ✅ Syntax 100% correct (zero tolerance for typos)
- ✅ Runtime execution produces expected output
- ✅ Output values match documentation exactly
- ✅ Error messages (if intentional) display as documented
- ✅ Self-check questions have correct answers
Example Validation:
name = "Alice"
age = 30
print(f"{name} is {age} years old")
Validation Script:
#!/bin/bash
file=$1
python3 -m ast "$file" || {
echo "CRITICAL: Syntax error in Layer 1 foundation"
exit 1
}
actual_output=$(timeout 10s python3 "$file" 2>&1)
exit_code=$?
if [ $exit_code -ne 0 ]; then
echo "CRITICAL: Runtime error in Layer 1 foundation"
echo "Output: $actual_output"
exit 1
fi
if [ -n "$EXPECTED_OUTPUT" ]; then
if [ "$actual_output" != "$EXPECTED_OUTPUT" ]; then
echo "CRITICAL: Output mismatch in Layer 1"
echo "Expected: '$EXPECTED_OUTPUT'"
echo "Got: '$actual_output'"
exit 1
fi
fi
echo "✅ Layer 1 validation PASS: Syntax + Runtime + Output verified"
Layer 2 (AI Collaboration) Validation
Context: Before/after examples showing AI optimization
Validation Requirements:
- ✅ Baseline implementation works (manual approach)
- ✅ AI-optimized version works
- ✅ Both produce same results (functional equivalence)
- ✅ Performance claims verified (if "3x faster", measure it)
- ✅ Convergence loop demonstrates learning (not just replacement)
Example Validation:
def filter_active_users(users):
results = []
for user in users:
if user.active:
results.append(user)
return results
def filter_active_users_optimized(users):
return [u for u in users if u.active]
Validation Script:
#!/bin/bash
baseline=$1
optimized=$2
python3 "$baseline" || { echo "HIGH: Baseline broken"; exit 1; }
python3 "$optimized" || { echo "HIGH: Optimized broken"; exit 1; }
baseline_output=$(python3 "$baseline")
optimized_output=$(python3 "$optimized")
if [ "$baseline_output" != "$optimized_output" ]; then
echo "HIGH: Functional equivalence broken"
echo "Baseline: $baseline_output"
echo "Optimized: $optimized_output"
exit 1
fi
if grep -q "faster\|slower\|performance\|optimize" *.md; then
echo "Performance claim detected, measuring..."
if command -v hyperfine &> /dev/null; then
hyperfine \
--warmup 3 \
"python3 $baseline" \
"python3 $optimized" \
--export-markdown benchmark.md
echo "✓ Performance claim validated (see benchmark.md)"
else
echo "WARNING: hyperfine not installed, cannot verify performance claim"
fi
fi
if ! grep -q "AI suggests\|Human evaluates\|Convergence" *.md; then
echo "MEDIUM: Missing convergence loop narrative (Three Roles pattern)"
fi
echo "✅ Layer 2 validation PASS: Baseline + Optimized + Claims verified"
Layer 3 (Intelligence Design) Validation
Context: Creating reusable skills/agents
Validation Requirements:
- ✅ Skill/agent works with multiple scenarios (not hardcoded to single example)
- ✅ Persona+Questions+Principles pattern present
- ✅ Activates reasoning mode (not prediction)
- ✅ Reusable across 3+ projects/technologies
- ✅ Interface contracts documented and tested
Example Validation:
name: code-quality-checker
persona: "Quality assurance architect analyzing maintainability"
questions:
- "What's the cyclomatic complexity?"
- "Are naming conventions consistent?"
- "Is error handling comprehensive?"
principles:
- "Complexity > 10 → refactor recommendation"
- "Uncaught exceptions → HIGH priority fix"
- "Magic numbers → extract to named constants"
Validation Script:
#!/bin/bash
skill_file=$1
has_persona=$(grep -c "^persona:" "$skill_file" || echo 0)
has_questions=$(grep -c "^questions:" "$skill_file" || echo 0)
has_principles=$(grep -c "^principles:" "$skill_file" || echo 0)
if [ $has_persona -eq 0 ]; then
echo "MEDIUM: Missing Persona (risk of prediction mode)"
fi
if [ $has_questions -eq 0 ]; then
echo "MEDIUM: Missing Questions (no reasoning structure)"
fi
if [ $has_principles -eq 0 ]; then
echo "MEDIUM: Missing Principles (no decision framework)"
fi
scenarios=("python-app" "node-app" "rust-app")
failures=0
for scenario in "${scenarios[@]}"; do
echo "Testing scenario: $scenario"
./run-skill.sh "$skill_file" --scenario "$scenario" || {
echo "MEDIUM: Skill fails on $scenario scenario"
((failures++))
}
done
if [ $failures -gt 0 ]; then
echo "MEDIUM: Skill not reusable across $failures/$\{#scenarios[@]} scenarios"
fi
if ! grep -q "^name:" "$skill_file"; then
echo "HIGH: Missing 'name' field (interface contract violation)"
fi
if ! grep -q "^description:" "$skill_file"; then
echo "MEDIUM: Missing 'description' field"
fi
echo "✅ Layer 3 validation PASS: Pattern + Reusability + Interface checked"
Layer 4 (Orchestration) Validation
Context: Multi-component system integration
Validation Requirements:
- ✅ All components start successfully
- ✅ Component communication works (APIs, message queues, etc.)
- ✅ Data flows correctly through system
- ✅ Error handling cascades properly
- ✅ System recovers from component failures
- ✅ End-to-end user scenarios work
Example Validation:
components:
- intent-classifier (Layer 3 agent)
- knowledge-retriever (Layer 3 agent)
- response-generator (Layer 3 agent)
- orchestrator (Layer 4 spec-driven)
integration_points:
- User query → Intent classifier → Category
- Category → Knowledge retriever → Relevant docs
- Docs + Query → Response generator → Answer
- Orchestrator monitors health, retries failures
Validation Script:
#!/bin/bash
compose_file=${1:-docker-compose.yml}
echo "Starting system..."
docker-compose -f "$compose_file" up -d
echo "Waiting for services to be healthy..."
timeout 60s ./wait-for-services.sh || {
echo "CRITICAL: System failed to start within 60s"
docker-compose -f "$compose_file" logs
docker-compose -f "$compose_file" down
exit 1
}
scenarios=(
"happy-path"
"intent-unclear"
"knowledge-not-found"
"component-failure-recovery"
)
for scenario in "${scenarios[@]}"; do
echo "Testing scenario: $scenario"
./test-e2e.sh --scenario "$scenario" || {
echo "HIGH: Scenario '$scenario' failed"
}
done
echo "Validating integration points..."
health_status=$(curl -s http://localhost:8000/health)
if ! echo "$health_status" | grep -q '"status":"healthy"'; then
echo "HIGH: Health check failed: $health_status"
fi
error_rate=$(curl -s http://localhost:8000/metrics | jq '.error_rate')
if (( $(echo "$error_rate > 0.05" | bc -l) )); then
echo "MEDIUM: Error rate $error_rate exceeds 5% threshold"
fi
echo "Tearing down system..."
docker-compose -f "$compose_file" down
echo "✅ Layer 4 validation PASS: Integration + Communication + Recovery verified"
VI. Anti-Convergence: Self-Monitoring
The Convergence Problem
You tend to default to "run code and report errors" without context analysis.
Common convergence patterns:
- ⚠️ Using same validation depth for all layers
- ⚠️ Not adapting to language ecosystem (running Python AST on JavaScript)
- ⚠️ Generic error reports without fix guidance
- ⚠️ Skipping performance claim verification (Layer 2)
- ⚠️ Not testing reusability (Layer 3)
- ⚠️ Only testing happy path (Layer 4)
Example of convergence:
for file in *.py; do
python3 "$file" 2>&1 | tee errors.log
done
This misses:
- Layer context (Is this L1 foundation or L4 demo code?)
- Validation depth (Should outputs match exactly or just run without errors?)
- Error severity (Is this CRITICAL or LOW?)
- Actionable diagnostics (Why did it fail? How to fix?)
Anti-Convergence Checklist
After each validation, check:
1. Did I analyze layer context?
- ❌ NO → Re-analyze: Which layer? What validation depth required?
- ✅ YES → Proceed to next check
2. Did I select language-appropriate tools?
- ❌ NO → Detect language (Python/Node/Rust), use ecosystem-specific validation
- ✅ YES → Proceed
3. Did I provide actionable error reports?
- ❌ NO → Add file:line context, fix suggestions, "why this matters for THIS layer"
- ✅ YES → Proceed
4. Did I verify claims (Layer 2)?
- ❌ NO → If lesson makes performance/optimization claims, measure and verify
- ✅ YES or N/A → Proceed
5. Did I test reusability (Layer 3)?
- ❌ NO → Test with 3+ scenarios, not single hardcoded example
- ✅ YES or N/A → Proceed
6. Did I test integration (Layer 4)?
- ❌ NO → End-to-end scenarios, component communication, error recovery
- ✅ YES or N/A → Proceed
Self-Correction Protocol
If converging toward generic validation:
-
Pause: Don't execute validation scripts yet
-
Re-analyze:
- What layer is this? (Check chapter metadata or content analysis)
- What language? (Check file extensions, keywords)
- What validation depth? (Layer 1: critical vs Layer 4: integration)
-
Select strategy:
- Use decision frameworks from Section IV
- Choose layer-appropriate validation depth
- Select language-appropriate tools
-
Execute intelligently:
- Not just "run and report"
- Context-appropriate validation with reasoning
-
Report actionably:
- File:line + fix + reasoning ("why this matters for THIS layer")
- Severity triage (CRITICAL/HIGH/MEDIUM/LOW)
- Next steps with validation commands
Convergence Detection Examples
Example 1: Generic error reporting (WRONG):
Error in file at line 23
Corrected (actionable):
CRITICAL: Layer 1 Manual Foundation
File: 02-variables.md:145 (code block 7)
Error: NameError: name 'count' is not defined
Fix: Line 143: global counter → global count
Why this matters: Students typing manually will hit confusing error
Example 2: Skipping performance verification (WRONG):
python3 baseline.py && python3 optimized.py
echo "Both work, PASS"
Corrected (verify claims):
python3 baseline.py && python3 optimized.py
hyperfine 'python3 baseline.py' 'python3 optimized.py'
Example 3: Single-scenario testing (WRONG):
./skill.py --example hardcoded-test
echo "Works with example, PASS"
Corrected (test reusability):
./skill.py --scenario python-app || echo "FAIL: Python"
./skill.py --scenario node-app || echo "FAIL: Node"
./skill.py --scenario rust-app || echo "FAIL: Rust"
if [ $failures -eq 0 ]; then
echo "✅ Reusable across 3 scenarios"
else
echo "MEDIUM: Not reusable ($failures failures)"
fi
VII. Usage Instructions
When to Use This Skill
Trigger phrases:
- "Validate Python code in Chapter X"
- "Check if code blocks run correctly"
- "Audit code examples for errors"
- "Test Chapter X in sandbox"
- "Run validation on [chapter-path]"
Contexts:
- ✅ Validating Python Fundamentals chapters (Part 4, Chapters 12-29)
- ✅ Validating Node/npm chapters (Part 2 tools)
- ✅ Validating multi-language agentic framework chapters
- ✅ Before publishing any chapter with code
- ✅ After fixing errors (re-validation)
Quick Start Workflow
Step 1: Invoke skill with chapter path
User: "Validate Python code in book-source/docs/04-Python-Fundamentals/14-data-types"
Step 2: Skill analyzes context
- Detect layer: Check chapter metadata or analyze content
- Detect language: Scan for .py, .js, .rs files and keywords
- Select validation strategy: Layer-appropriate depth
Step 3: Execute validation
Step 4: Generate actionable report
## Validation Results: Chapter 14 (Data Types)
**Layer**: 1 (Manual Foundation)
**Language**: Python 3.14
**Strategy**: Full validation (syntax + runtime + output)
**Summary:**
- 📊 Total Code Blocks: 23
- ❌ Critical Errors: 1 (BLOCKS PUBLICATION)
- ⚠️ High Priority: 2
- ✅ Success Rate: 87.0%
**CRITICAL Errors (Fix Immediately):**
1. **01-variables-and-type-hints.md:145** (code block 7)
- Syntax error: invalid syntax on line 3
- Fix: Add missing closing parenthesis
- Why critical: Layer 1 foundation, students type manually
**HIGH Priority (Misleading Content):**
2. **02-integers-and-floats.md:78** (code block 3)
- Runtime error: ZeroDivisionError
- Fix: Add validation or try/except
- Why high: Unexpected error in published example
📄 Full report: `validation-output/14-data-types-report.md`
**Next Steps:**
1. Fix critical error in 01-variables-and-type-hints.md:145
2. Fix high priority errors
3. Re-run: "Re-validate Chapter 14"
Advanced Usage
Validate Multiple Chapters:
User: "Validate Chapters 14, 15, and 16"
## When NOT to Use This Skill
- **Trusted, reviewed code** — running validated production code through a sandbox adds latency with no safety benefit
- **Infrastructure or system commands** — sandbox environments don't replicate production infra; use staging environments for infra validation
- **Code that requires external service connections** — sandboxes have no network access by design; integration tests need a real test environment
## Common Mistakes
- Assuming sandbox success means production safety — sandboxes catch runtime errors but not logic errors, race conditions, or environment-specific failures
- Not setting execution timeouts — runaway loops can hang the sandbox indefinitely; always set a maximum execution time
- Ignoring sandbox resource limits — code that passes in a constrained sandbox may fail in production when it needs more memory or CPU
## Related Skills
- [`code-example-generator`](../code-example-generator/SKILL.md) — Generate code examples that get validated here
- [`qa-testing-specialist`](../qa-testing-specialist/SKILL.md) — Full testing strategy beyond sandbox validation
- [`security-sandbox-controls`](../security-sandbox-controls/SKILL.md) — Security layer that works alongside sandbox execution