A minimal Cloudflare Worker that demonstrates the core capabilities of the Sandbox SDK.
- Command Execution: Execute Python code in isolated containers
- File Operations: Read and write files in the sandbox filesystem
- Simple API: Two endpoints demonstrating basic sandbox operations
This example provides two simple endpoints:
/run- Executes Python code and returns the output/file- Creates a file, reads it back, and returns the contents
GET http://localhost:8787/runRuns python -c "print(2 + 2)" and returns:
{
"output": "4\n",
"success": true
}GET http://localhost:8787/fileCreates /workspace/hello.txt, reads it back, and returns:
{
"content": "Hello, Sandbox!"
}- From the project root, run:
npm install
npm run build- Run locally:
cd examples/minimal # if you're not already here
npm run devThe first run will build the Docker container (2-3 minutes). Subsequent runs are much faster.
# Test command execution
curl http://localhost:8787/run
# Test file operations
curl http://localhost:8787/filenpm run deployAfter first deployment, wait 2-3 minutes for container provisioning before making requests.
This minimal example is the starting point for more complex applications. See the Sandbox SDK documentation for:
- Advanced command execution and streaming
- Background processes
- Preview URLs for exposed services
- Custom Docker images