sandboxsandboxsandboxsandboxsandboxsandboxsandboxsandboxsandboxsandboxsandbox
Meet Cloudflare Sandboxes.
Execute commands, manage files, run services, and expose them via public URLs - all within secure, sandboxed containers. Get Started
import { getSandbox } from "@cloudflare/sandbox";
// Export the Sandbox class in your Worker
export { Sandbox } from "@cloudflare/sandbox";
export default {
async fetch(request: Request, env: Env) {
const sandbox = getSandbox(env.Sandbox, "test-env");
// Clone a repository
await sandbox.gitCheckout(
"https://github.com/cloudflare/agents"
);
// Run tests
const testResult = await sandbox.exec("npm test");
return new Response(
JSON.stringify({
tests: testResult.exitCode === 0
? "passed"
: "failed",
output: testResult.stdout,
})
);
},
};FeaturesFeaturesFeaturesFeatures
Long-running processes
Safely execute tasks that require extended computation or monitoring without risking system stability or security.
Real time streaming
Listen to standard output & error streams live when executing long-running commands
Preview URLs
Instantly expose any container port as a public URL with automatic subdomain routing
Code interpreter
Run Python/JavaScript code directly, with rich outputs (charts, tables, images) parsed automatically for you
File system
Easy methods for basic filesystem operations and cloning git repositories on the container filesystem
Command execution
Run any shell command with proper exit codes, streaming, and error handling
WebSockets
Enable real-time, bidirectional communication by connecting directly to WebSocket servers running in the sandbox
ExamplesExamplesExamplesExamples
import { getSandbox } from '@cloudflare/sandbox';
export default {
async fetch(request: Request, env: Env) {
const sandbox = getSandbox(env.Sandbox, 'user-123');
// Create a project structure
await sandbox.mkdir('/workspace/project/src', {
recursive: true
});
// Write files
await sandbox.writeFile(
'/workspace/project/package.json',
JSON.stringify({ name: 'my-app', version: '1.0.0', });
// Read a file back
const content = await sandbox.readFile(
'/workspace/project/src/package.json'
);
return Response.json({ content });
}
};TestimonialsTestimonialsTestimonialsTestimonials
The sandbox SDK is a core part of our infrastructure at Iterate. It's made giving our agents a 'computer' really easy to do, saving us weeks of effort. The team has been very responsive and helpful when dealing with us throughout the implementation process.
Nick Blow
Founding Engineer · Iterate
The developer experience is well-thought-out and built on layers of nice abstractions you can override as needed.
Seve Ibarluzea
Co-Founder · tscircuit.com
Sandbox-sdk has made it possible to orchestrate and manage running insecure user apps so much easier. You can simply launch a sandbox, expose port and it would handle all the proxying, allocation for you.
Ashish Kumar
Engineer · VibeSDK