Initialize Docker sandbox for a course's code execution environment
Creates a Docker-based isolated sandbox for a course with compilers, testing tools, and security constraints. Use this to set up safe code execution environments for C++, Rust, Python, Go, or multi-language courses.
/plugin marketplace add NathanJGaul/plugins/plugin install dev-course-builder@njg-marketplace[course] - Course to set up sandbox for (e.g., 'cpp-fundamentals')Initialize a Docker-based isolated development environment for compiling, running, testing, linting, and debugging code in course materials.
Which course needs a sandbox environment?
[1] C++ Fundamentals (Junior Developers)
[2] [Other configured courses...]
[3] Specify course directory path
Please select an option:
Select the sandbox template for this course:
[1] C++ Sandbox (GCC 13, Clang 17, CMake, GDB, Valgrind, clang-tidy)
[2] Rust Sandbox (rustc, cargo, clippy, rustfmt, miri)
[3] Python Sandbox (Python 3.12, pytest, mypy, ruff, black)
[4] Go Sandbox (Go 1.23, gofmt, staticcheck, delve)
[5] C Sandbox (GCC 13, Clang 17, Make, GDB, Valgrind)
[6] Multi-Language Sandbox (C, C++, Python, Go, Rust)
[7] Custom (I'll provide a Dockerfile)
Please select an option:
Configure sandbox settings:
Container Name: course-sandbox-{course-id}
Memory Limit: [1] 1GB [2] 2GB [3] 4GB [4] Custom
CPU Limit: [1] 1 CPU [2] 2 CPUs [3] 4 CPUs
Network Access: [1] Disabled (recommended) [2] Enabled
Please select options:
Before proceeding, verify Docker is available:
# Check Docker is installed and running
docker --version
docker info
If Docker is not available, provide installation guidance.
Create the .sandbox/ directory structure in the course:
{course-directory}/
└── .sandbox/
├── Dockerfile
├── docker-compose.yml
├── .dockerignore
└── scripts/
├── setup.sh
├── validate.sh
└── cleanup.sh
Language-specific Dockerfile from the sandbox-templates skill, customized for the course:
Container orchestration with security constraints:
version: '3.8'
services:
sandbox:
build:
context: ..
dockerfile: .sandbox/Dockerfile
container_name: course-sandbox-{course-id}
volumes:
- ..:/workspace
working_dir: /workspace
stdin_open: true
tty: true
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
deploy:
resources:
limits:
memory: {memory-limit}
cpus: '{cpu-limit}'
network_mode: {none|bridge}
Excludes unnecessary files from the build context:
setup.sh - Post-creation initialization:
#!/bin/bash
# Verify container is running
# Install any additional dependencies
# Set up environment variables
validate.sh - Validate all code examples:
#!/bin/bash
# Find all code files
# Compile each one
# Run and capture output
# Compare to expected output
# Generate report
cleanup.sh - Clean up temporary files:
#!/bin/bash
# Remove compiled binaries
# Clear /tmp
# Reset container state
cd {course-directory}
docker build -t course-sandbox-{course-id}:latest -f .sandbox/Dockerfile .
docker run -d \
--name course-sandbox-{course-id} \
-v "$(pwd):/workspace" \
-w /workspace \
--cap-drop=ALL \
--security-opt=no-new-privileges \
--memory=2g \
--cpus=2 \
--network=none \
course-sandbox-{course-id}:latest \
tail -f /dev/null
# Check container is running
docker ps --filter "name=course-sandbox-{course-id}"
# Test a simple command
docker exec course-sandbox-{course-id} echo "Sandbox ready!"
# Test compiler (for C++)
docker exec course-sandbox-{course-id} g++ --version
Once the sandbox is set up, use these commands:
/run-code - Compile and execute code files/test-code - Run tests in the sandbox/lint-code - Lint code with language-appropriate tools/debug-code - Start debugging session/validate-examples - Validate all code examples in coursedocker ps -a --filter "name=course-sandbox-{course-id}"
docker start course-sandbox-{course-id}
docker stop course-sandbox-{course-id}
docker rm -f course-sandbox-{course-id}
docker build -t course-sandbox-{course-id}:latest -f .sandbox/Dockerfile .
# Then run the create command again
docker rm -f course-sandbox-{course-id}
docker rmi course-sandbox-{course-id}:latest
# Then rebuild from scratch
After setup, the course profile should be updated to include sandbox configuration:
## Sandbox Configuration
**Container:** course-sandbox-{course-id}
**Template:** {template-name}
**Status:** Configured
### Quick Commands
- Build: `docker build -t course-sandbox-{course-id}:latest -f .sandbox/Dockerfile .`
- Start: `docker start course-sandbox-{course-id}`
- Stop: `docker stop course-sandbox-{course-id}`
- Shell: `docker exec -it course-sandbox-{course-id} /bin/bash`
Error: Cannot connect to Docker daemon
Solution: Start Docker daemon or Docker Desktop
Error: Permission denied while trying to connect to Docker
Solution: Add user to docker group: sudo usermod -aG docker $USER
Error: Dockerfile build failed
Solution: Check Dockerfile syntax, network connectivity for package downloads
Error: Container exits immediately
Solution: Check container logs: docker logs course-sandbox-{course-id}
--cap-drop=ALL)--security-opt=no-new-privileges)--network=none)