| [ Web Proxy ] |
| Viewing: https://workers.cloudflare.com/products/sandboxes/ | [Back] [Original] |
Sandboxes
Fully isolated
Each sandbox runs in its own secure container. Execute AI-generated or user-submitted code with zero risk to your infrastructure.
Fast spin-up
Sandboxes start in milliseconds, not minutes. Execute code immediately without waiting for cold starts.
Bring your own images
Use standard container images with your own dependencies, tools, and runtimes. Full flexibility without lock-in.
Import @cloudflare/sandbox and manage the entire sandbox lifecycle from your Worker. Clone repos, execute commands, read/write files all via simple async methods.
Sandboxes run on Cloudflare Containers, so you get the same global placement, automatic scaling, and pay-per-use pricing.
Stream stdout and stderr live from long-running commands. Get immediate feedback without polling.
Run Python or JavaScript code directly with runCode(). Rich outputs like charts, tables, and images are parsed automatically.
AI agent code execution
Give your agents a secure environment to write and run code, install packages, and interact with the filesystem.Interactive development environments
Spin up complete dev environments on-demand for testing, CI/CD, or collaborative coding.Code interpreters
Run user-submitted Python or JavaScript with automatic output parsing for charts, tables, and rich content.Clone repos, execute commands, manage files, and run code all with a few lines of TypeScript.
[Background Pattern] import { getSandbox } from '@cloudflare/sandbox';export { Sandbox } from '@cloudflare/sandbox';
export default { async fetch(request: Request, env: Env) { const sandbox = getSandbox(env.Sandbox, 'test-runner');
await sandbox.gitCheckout('https://github.com/cloudflare/agents'); const result = await sandbox.exec('npm test');
return Response.json({ passed: result.exitCode === 0, output: result.stdout, }); },};import { getSandbox } from '@cloudflare/sandbox';export { Sandbox } from '@cloudflare/sandbox';
export default { async fetch(request: Request, env: Env) { const sandbox = getSandbox(env.Sandbox, 'file-ops');
await sandbox.mkdir('/workspace/src', { recursive: true }); await sandbox.writeFile( '/workspace/package.json', JSON.stringify({ name: 'my-app', type: 'module', }), );
const result = await sandbox.readFile('/workspace/package.json'); return Response.json({ content: result.content }); },};import { getSandbox } from '@cloudflare/sandbox';export { Sandbox } from '@cloudflare/sandbox';
export default { async fetch(request: Request, env: Env) { const sandbox = getSandbox(env.Sandbox, 'interpreter'); const ctx = await sandbox.createCodeContext({ language: 'python' });
const result = await sandbox.runCode( `import mathfor i in range(5): print(f"Step {i}: {math.pi * i:.2f}")`, { context: ctx }, );
return Response.json({ output: result.logs?.stdout?.join('\n') }); },};Clone and run tests
Clone a repository and execute shell commands with a simple SDK. Get exit codes, stdout, and stderr.Create and manage files
Read, write, and organize files in the sandbox filesystem. Perfect for scaffolding projects or processing uploads.Run Python or JavaScript
Execute code with automatic output parsing. Charts, tables, and images are extracted for you.Join thousands of developers who've eliminated infrastructure complexity and deployed globally with Cloudflare. Start building for free no credit card required.
| Web Proxy Viewer | New URL | Original Page |