Cloudflare Sandbox SDK

Secure, isolated code execution at the edge. Run untrusted code in Docker containers while maintaining full control over the execution environment.

🔒

Secure Isolation

Run Python, JavaScript, and shell commands in isolated Docker containers

🌐

Edge-Native

Runs on Cloudflare's global network using Durable Objects for state

📁

Full Filesystem

Read, write, stream, and manage files within the sandbox environment

⚙️

Background Processes

Launch and manage long-running services with real-time log streaming

🔗

Port Exposure

Expose internal services with token-authenticated preview URLs

🐍

Code Interpreter

Execute Python/JS with rich output: variables, plots, structured results

Quick Start

import { getSandbox } from '@cloudflare/sandbox';

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    // Get or create a sandbox instance
    const sandbox = getSandbox(env.Sandbox, 'my-sandbox');

    // Execute a command
    const result = await sandbox.exec('echo "Hello from the sandbox!"');

    return Response.json({
      output: result.stdout,
      exitCode: result.exitCode,
      success: result.success
    });
  }
};

Powers These AI Agents

Claude CodeOpenAI Agents SDKOpenCodeCustom AI Agents