Cloudflare Sandbox SDK adds streaming, code interpreter, Git support, process control and more
We’ve shipped a major release for the @cloudflare/sandbox ↗ SDK, turning it into a full-featured, container-based execution platform that runs securely on Cloudflare Workers.
This update adds live streaming of output, persistent Python and JavaScript code interpreters with rich output support (charts, tables, HTML, JSON), file system access, Git operations, full background process control, and the ability to expose running services via public URLs.
This makes it ideal for building AI agents, CI runners, cloud REPLs, data analysis pipelines, or full developer tools — all without managing infrastructure.
Create persistent code contexts with support for rich visual + structured outputs.
Creates a new code execution context with persistent state.
// Create a Python contextconst pythonCtx = await sandbox.createCodeContext({ language: "python" });
// Create a JavaScript contextconst jsCtx = await sandbox.createCodeContext({ language: "javascript" });
Options:
- language: Programming language ('python' | 'javascript' | 'typescript')
- cwd: Working directory (default: /workspace)
- envVars: Environment variables for the context
Executes code with optional streaming callbacks.
// Simple executionconst execution = await sandbox.runCode('print("Hello World")', { context: pythonCtx,});
// With streaming callbacksawait sandbox.runCode( `for i in range(5): print(f"Step {i}") time.sleep(1)`, { context: pythonCtx, onStdout: (output) => console.log("Real-time:", output.text), onResult: (result) => console.log("Result:", result), },);
Options:
- language: Programming language ('python' | 'javascript' | 'typescript')
- cwd: Working directory (default: /workspace)
- envVars: Environment variables for the context
Returns a streaming response for real-time processing.
const stream = await sandbox.runCodeStream( "import time; [print(i) for i in range(10)]",);// Process the stream as needed
Interpreter outputs are auto-formatted and returned in multiple formats:
- text
- html (e.g., Pandas tables)
- png, svg (e.g., Matplotlib charts)
- json (structured data)
- chart (parsed visualizations)
const result = await sandbox.runCode( `import seaborn as snsimport matplotlib.pyplot as plt
data = sns.load_dataset("flights")pivot = data.pivot("month", "year", "passengers")sns.heatmap(pivot, annot=True, fmt="d")plt.title("Flight Passengers")plt.show()
pivot.to_dict()`, { context: pythonCtx },);
if (result.png) { console.log("Chart output:", result.png);}
Start background processes and expose them with live URLs.
await sandbox.startProcess("python -m http.server 8000");const preview = await sandbox.exposePort(8000);
console.log("Live preview at:", preview.url);
Start, inspect, and terminate long-running background processes.
const process = await sandbox.startProcess("node server.js");console.log(`Started process ${process.id} with PID ${process.pid}`);
// Monitor the processconst logStream = await sandbox.streamProcessLogs(process.id);for await (const log of parseSSEStream<LogEvent>(logStream)) { console.log(`Server: ${log.data}`);}
- listProcesses() - List all running processes
- getProcess(id) - Get detailed process status
- killProcess(id, signal) - Terminate specific processes
- killAllProcesses() - Kill all processes
- streamProcessLogs(id, options) - Stream logs from running processes
- getProcessLogs(id) - Get accumulated process output
Clone Git repositories directly into the sandbox.
await sandbox.gitCheckout("https://github.com/user/repo", { branch: "main", targetDir: "my-project",});
Sandboxes are still experimental. We're using them to explore how isolated, container-like workloads might scale on Cloudflare — and to help define the developer experience around them.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Products
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark