The Sandbox SDK provides a comprehensive API for executing code, managing files, running processes, and exposing services in isolated sandboxes.
Lifecycle
Create and manage sandbox containers. Get sandbox instances, configure options, and clean up resources.
Commands
Execute commands and stream output. Run scripts, manage background processes, and capture execution results.
Files
Read, write, and manage files in the sandbox filesystem. Includes directory operations and file metadata.
File watching
Monitor real-time filesystem changes using native inotify. Build development tools, hot-reload systems, and responsive file processing.
Code interpreter
Execute Python and JavaScript code with rich outputs including charts, tables, and formatted data.
Ports
Expose services running in the sandbox via preview URLs. Access web servers and APIs from the internet.
Tunnels
Expose services on zero-config *.trycloudflare.com URLs via
sandbox.tunnels.get(port). Best for quick development and .workers.dev
deployments.
Storage
Mount S3-compatible buckets (R2, S3, GCS) as local filesystems for persistent data storage across sandbox lifecycles.
Backups
Create point-in-time snapshots of directories and restore them with copy-on-write overlays. Store backups in R2.
Sessions
Create isolated execution contexts within a sandbox. Each session maintains its own shell state, environment variables, and working directory.
Terminal
Connect browser-based terminal UIs to sandbox shells via WebSocket, with the xterm.js SandboxAddon for automatic reconnection and resize handling.