Secure, isolated code execution at the edge. Run untrusted code in Docker containers while maintaining full control over the execution environment.
Run Python, JavaScript, and shell commands in isolated Docker containers
Runs on Cloudflare's global network using Durable Objects for state
Read, write, stream, and manage files within the sandbox environment
Launch and manage long-running services with real-time log streaming
Expose internal services with token-authenticated preview URLs
Execute Python/JS with rich output: variables, plots, structured results
import { getSandbox } from '@cloudflare/sandbox';
export default {
async fetch(request: Request, env: Env): Promise<Response> {
// Get or create a sandbox instance
const sandbox = getSandbox(env.Sandbox, 'my-sandbox');
// Execute a command
const result = await sandbox.exec('echo "Hello from the sandbox!"');
return Response.json({
output: result.stdout,
exitCode: result.exitCode,
success: result.success
});
}
};