Cloudflare Sandbox SDK adds streaming, code interpreter, Git support, process control
The @cloudflare/sandbox SDK now includes persistent Python and JavaScript code interpreters with streaming output, rich visual support, file system access, Git operations, background process control, and the ability to expose services via public URLs. This enables building AI agents, CI runners, and developer tools without managing infrastructure.
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.
Code interpreter (Python, JS, TS)
Create persistent code contexts with support for rich visual + structured outputs.
createCodeContext(options)
Creates a new code execution context with persistent state.
// Create a Python context
const pythonCtx = await sandbox.createCodeContext({ language: "python" });
// Create a JavaScript context
const jsCtx = await sandbox.createCodeContext({ language: "javascript" });
Options:
- language: Programming language ('python' | 'javascript' | 'typescript')
- cwd: Working directory (default: /workspace)
- envVars: Environment variables for the context
runCode(code, options)
Executes code with optional streaming callbacks.
// Simple execution
const execution = await sandbox.runCode('print("Hello World")', {
context: pythonCtx,
});
// With streaming callbacks
await 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
Real-time streaming output
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
Rich output handling
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 sns
import 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);
}
Preview URLs from Exposed Ports
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);
Full process lifecycle control
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 process
const 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
Git integration
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.
Source: original entry ↗
More from Cloudflare
Follow Cloudflare to get its new changes in your feed and email digest.
Cloudflare One Client for macOS 2026.8.2100.0
GA release for macOS Cloudflare One Client with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster connects with lower memory use, and numerous reliability fixes across DNS, reauthentication, and client stability.
Cloudflare One Client for Windows 2026.8.2100.0
This GA release improves split tunnel reliability, adds support for non-RFC 1918 local networks, optimizes connection performance with faster reconnections and lower memory usage, and includes numerous bug fixes for DNS, registration, and network handling. The client now features a service recovery mechanism that automatically restarts on system unlock and better handles large hosts files without blocking traffic.
Cloudflare One Client for Linux 2026.8.2100.0
New GA release for Linux with improved split tunnel handling that no longer briefly blocks traffic during reconnects, support for non-RFC 1918 local IPv4 networks, faster tunnel reconnections, and lower memory usage. Includes numerous stability and reliability fixes for DNS, reconnection behavior, and crash issues.