Sandboxes

Secure code execution for AI agents and developer tools

Run untrusted code in isolated environments. Give your AI agents, code interpreters, and developer tools a secure place to execute code, install packages, and interact with the filesystem.
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.

How Sandboxes work

Background Pattern
SDK-driven control

Import `@cloudflare/sandbox` and manage the entire sandbox lifecycle from your Worker. Clone repos, execute commands, read/write files — all via simple async methods.

Background Pattern
Built on Containers

Sandboxes run on Cloudflare Containers, so you get the same global placement, automatic scaling, and pay-per-use pricing.

Background Pattern
Real-time streaming

Stream stdout and stderr live from long-running commands. Get immediate feedback without polling.

Background Pattern
Code interpreter built-in

Run Python or JavaScript code directly with `runCode()`. Rich outputs like charts, tables, and images are parsed automatically.

Background Pattern
Sandboxes

Secure execution for any workload

Use Sandboxes to:

View docs

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.

Simple APIs for complex workloads

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,
    });
  },
};

Containers Pricing

Run any language in secure, global containers (also applies to Sandboxes). View Compute pricing details

Memory

Free

25 GiB-hrs included

Paid

$0.0000025 / GiB-second

CPU

Free

375 vCPU-min included

Paid

$0.000020 / vCPU-second

Disk

Free

200 GB-hrs included

Paid

$0.00000007 / GB-second

Network Egress (NA/EU)

Free

1 TB included

Paid

$0.025 / GB

Powerful primitives, seamlessly integrated

Built on systems powering 20% of the Internet, Sandboxes run on the same infrastructure Cloudflare uses to build Cloudflare. Enterprise-grade reliability, security, and performance are standard.

Build without boundaries

Join thousands of developers who've eliminated infrastructure complexity and deployed globally with Cloudflare. Start building for free — no credit card required.