What is a sandbox instance?
A sandbox instance is an isolated container environment running on Cloudflare’s edge. Each sandbox is backed by a Durable Object that manages the container lifecycle, providing persistent identity and state management.Sandbox lifecycle
Sandboxes progress through several states during their lifetime:Starting
The container VM is being provisioned and the application is starting up. This can take several minutes on first deployment.
Running
The container is active and ready to execute commands. All file system changes and running processes exist in memory.
Sleeping
After a period of inactivity (default 10 minutes), the container sleeps. The file system and all running processes are lost.
Configuration options
Configure sandbox behavior when creating an instance:Sleep timeout
Control when the container sleeps due to inactivity:Duration after which the sandbox sleeps if no requests are received. Can be:
- String:
"30s","3m","5m","1h"(seconds, minutes, hours) - Number: seconds (e.g.,
180for 3 minutes)
The
sleepAfter option is ignored when keepAlive is enabled.Keep alive mode
Prevent automatic shutdown. The container stays alive indefinitely until you explicitly call
sandbox.destroy().Container timeouts
Configure startup behavior for heavy containers or fail-fast applications:SANDBOX_INSTANCE_TIMEOUT_MSSANDBOX_PORT_TIMEOUT_MSSANDBOX_POLL_INTERVAL_MS
Sandbox identity
Each sandbox is identified by a string ID that maps to a Durable Object:Base URL configuration
Specify a base URL for the sandbox API (rarely needed):Container architecture
Each sandbox runs in an isolated VM with:- Ubuntu 22.04 base image
- Python 3.11 with common data science libraries (matplotlib, numpy, pandas)
- Node.js 20 LTS for JavaScript/TypeScript execution
- Bun runtime powering the container HTTP server
- Common utilities: git, curl, wget, jq, and more
Platform context
Sandboxes leverage Cloudflare’s infrastructure:- VM-based isolation: Each sandbox runs in its own secure VM
- Edge distribution: Sandboxes run geographically close to users
- Durable Objects: Provide container lifecycle management and persistent identity
- Auto-scaling: Containers provision on-demand and sleep when inactive