---
title: Vercel Sandbox vs Cloudflare Sandbox
description: Compare Vercel Sandbox and Cloudflare Sandbox as AI agent sandboxes, including isolation, persistence, network controls, SDKs, and deployment options.
keywords: ["Vercel Sandbox","Cloudflare Sandbox","AI agent sandbox","untrusted code execution","Firecracker microVM"]
url: "https://vercel.com/kb/guide/vercel-sandbox-vs-cloudflare-sandbox"
published: 2026-11-23
last_updated: 2026-11-23
authors: Ben Sabic
related_resources:
  - title: "Vercel Sandbox vs E2B"
    url: "/kb/guide/vercel-sandbox-vs-e2b"
    description: "A detailed guide to Vercel Sandbox vs E2B: compute lifecycle, security controls, code execution, pricing, and when to choose each sandbox for your AI agent workloads."
  - title: "Vercel Sandbox vs Upstash Box"
    url: "/kb/guide/vercel-sandbox-vs-upstash-box"
    description: "Compare Vercel Sandbox and Upstash Box as AI agent sandboxes, including isolation, persistence, network controls, SDKs, and deployment regions."
  - title: "How Vercel Sandbox duration and persistence work"
    url: "/kb/guide/vercel-sandbox-duration-and-persistence"
    description: "Session duration and persistence are two separate controls in Vercel Sandbox. The timeout option keeps a single run alive for up to 24 hours, while snapshots and persistent sandboxes carry state across runs for long-running agents and pipelines."
install_vercel_plugin: npx plugins add vercel/vercel-plugin
search_with_vercel_cli: npx vercel@latest kb search "<query>"
read_with_vercel_cli: "npx vercel@latest kb inspect vercel-sandbox-vs-cloudflare-sandbox"
---

[Vercel Sandbox](https://vercel.com/docs/sandbox) and [Cloudflare Sandbox](https://developers.cloudflare.com/sandbox/) are AI sandboxes for running generated code in Linux environments backed by Firecracker microVMs. Vercel is a standalone service you call from your application. Cloudflare's Linux sandboxes run inside containers controlled by Durable Objects in your Worker.

Choose Vercel Sandbox for automatic file persistence, declarative egress controls, and SDK access from your existing backend. Cloudflare Sandbox fits applications built around Workers and Durable Objects, especially when you want request-driven lifetimes or egress policy in Worker code.

## How Vercel Sandbox and Cloudflare Sandbox compare

This comparison covers Cloudflare's Linux environment and [Sandbox SDK 1.0](https://developers.cloudflare.com/sandbox/sdk/migrate/), where your Durable Object controls the container through `this.ctx.container`. Cloudflare also offers [Dynamic Workers](https://developers.cloudflare.com/sandbox/concepts/) for generated code that calls defined methods, using a different execution model.

### Compute and resources

Vercel gives each sandbox [its own Firecracker microVM and kernel](https://vercel.com/docs/sandbox/concepts/security). Cloudflare runs each Container instance [in a Firecracker microVM with its own kernel and network](https://developers.cloudflare.com/containers/concepts/architecture/), and your image runs as a Linux container inside that VM.

The isolation boundary is the same kind on both, so the differences that decide a choice are in sizing, access, and lifecycle.

| **Concern**             | **Vercel Sandbox**                                                                              | **Cloudflare Sandbox**                                                                                                                                                                                              |
| ----------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Isolation               | Firecracker microVM with its own kernel                                                         | Firecracker microVM with its own kernel and network; the image runs as a Linux container inside it                                                                                                                  |
| Base environment        | [Ubuntu or Arch images](https://vercel.com/docs/sandbox/concepts/images), or a custom OCI image | [Managed Debian image or a custom image](https://developers.cloudflare.com/containers/configuration/scheduling-policy/)                                                                                             |
| vCPUs                   | 1 vCPU or an even number; default 2. Maximums: 4 (Hobby), 8 (Pro), 32 (Enterprise).             | Named types from 1/16 vCPU (`lite`, the default) to 4 vCPUs (`standard-4`), or a custom size. [Higher per-instance limits](https://developers.cloudflare.com/containers/platform/limits/) are available on request. |
| Memory                  | 2 GB per vCPU. Limits: Hobby 8 GB, Pro 16 GB, Enterprise 64 GB.                                 | Named types from 256 MiB (`lite`, the default) to 12 GiB (`standard-4`), or a custom size. Higher per-instance limits are available on request.                                                                     |
| Disk                    | 64 GB of ephemeral NVMe with SDK 3.0.0+ or a custom image                                       | Set by the instance type, from 2 GB (`lite`) to 20 GB (`standard-4`)                                                                                                                                                |
| Concurrent environments | Hobby: 10. Pro and Enterprise: 10,000.                                                          | No separate instance-count quota under this policy. Concurrent usage is bounded by account CPU, memory, and disk limits.                                                                                            |
| SDKs and tools          | TypeScript SDK, sync/async Python SDK, Sandbox CLI, Vercel CLI, and Vercel REST API             | TypeScript API in a Worker: `this.ctx.container` plus `@cloudflare/sandbox` helpers (`Files`, `S3Mount`, `DirectoryBackup`)                                                                                         |
| Authentication          | Project-scoped Vercel OIDC token, or an access token with team and project IDs                  | Durable Object binding in your Worker. You authenticate callers in the Worker.                                                                                                                                      |
| Plan                    | Hobby, Pro, and Enterprise                                                                      | Workers Paid plan                                                                                                                                                                                                   |

Vercel's default universal image includes Node.js 24 and Python 3.14 on Ubuntu 26.04. Cloudflare's managed Debian Trixie slim image includes Node.js 24.20.0. For other runtimes or tools, use a custom AMD64 Linux image.

Cloudflare's default account limits allow 15,000 vCPUs, 60 TiB of memory, and 300 TB of disk across running instances.

Vercel's [resource limits](https://vercel.com/docs/sandbox/pricing#resource-limits) reach 8 vCPUs on Pro and 32 on Enterprise in one environment, above Cloudflare's default maximum of 4 vCPU and 12 GiB, which Cloudflare raises on request. In the other direction, Cloudflare's `lite` and `standard-1` types give a sandbox less than one vCPU, while Vercel's smallest sandbox has 1 vCPU and 2 GB of memory. Sandbox containers on Cloudflare accept `lite` and `standard-1` through `standard-4`, but not the `basic` type.

### Lifecycle

Vercel Sandbox limits each session's duration and saves the filesystem when a persistent session stops. Cloudflare's instance lifetime follows its Durable Object's activity and configured inactivity timeout. Stopping a Cloudflare instance ends its processes and discards its local filesystem.

| **Concern**           | **Vercel Sandbox**                                                                                                                          | **Cloudflare Sandbox**                                                                                                                                                                                                         |
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Session end           | Default 5 minutes. Extend to 45 minutes on Hobby or 24 hours on Pro and Enterprise with `sandbox.extendTimeout()`.                          | Shortly after the Durable Object goes inactive, or after the time set with [`setInactivityTimeout()`](https://developers.cloudflare.com/containers/api/durable-object-container/), up to 6 hours. 1.0 sets no default timeout. |
| What keeps it running | The session timeout, which your code can extend                                                                                             | Requests, alarms, streamed responses, and accepted WebSockets on the Durable Object. Work inside the instance doesn't count.                                                                                                   |
| State kept by default | Filesystem and configuration [snapshotted on stop](https://vercel.com/docs/sandbox/concepts/persistent-sandboxes)                           | None. The disk and processes end with the instance.                                                                                                                                                                            |
| Running processes     | Not restored on resume                                                                                                                      | End with the instance. Starting from a snapshot runs the entrypoint again.                                                                                                                                                     |
| How it resumes        | An SDK operation that requires a running VM, such as `runCommand()`, starts a new session from the latest snapshot                          | Your Durable Object calls `start()` with the image, or with a snapshot handle it stored                                                                                                                                        |
| Snapshots             | Automatic on stop, or manual with `snapshot()`. They expire 30 days after last use by default, and you can change or remove the expiration. | Public beta. Manual with `snapshotContainer()`, root filesystem only, up to 20 GB, kept 30 days from creation or the last restore.                                                                                             |
| Other persistence     | [Drives](https://vercel.com/docs/sandbox/concepts/drives) mounted as directories, up to four per sandbox                                    | [Directory backups to R2, or a mounted R2 bucket](https://developers.cloudflare.com/sandbox/files/)                                                                                                                            |
| Disposable mode       | `persistent: false` discards the filesystem when the session stops                                                                          | The default behavior                                                                                                                                                                                                           |

Work inside a Cloudflare instance does not count as Durable Object activity, so a build or agent task can be interrupted when the inactivity timeout ends. Use a [Durable Object alarm](https://developers.cloudflare.com/sandbox/concepts/lifetime/) to check ongoing work more often than the timeout. Platform events can still stop the instance.

On Vercel, each resume starts a new session timeout. The same persistent sandbox can span repeated sessions while its saved snapshot remains available. Requests to a stopped sandbox's public URL return [HTTP 410](https://vercel.com/docs/errors/SANDBOX_STOPPED). Resume it with an operation such as `runCommand()` before sending traffic.

Vercel and Cloudflare publish startup figures measured in different ways. To compare them, time each product from your application's region, from the start of creation through the [first command](https://vercel.com/docs/sandbox/sdk/javascript).

### Networking and security

Vercel Sandbox allows outbound internet access by default and uses a declarative firewall to restrict it. Cloudflare can disable general internet access while [outbound handlers](https://developers.cloudflare.com/containers/configuration/outbound-traffic/) forward selected HTTP and HTTPS requests through a Worker.

With `enableInternet: false`, handlers control outbound access. Setting it to `true` also lets unmatched connections reach the internet directly.

| **Concern**          | **Vercel Sandbox**                                                                                                                 | **Cloudflare Sandbox**                                                                                                                                                                                                                                 |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Default egress       | Allow all                                                                                                                          | No internet access. Only intercepted hostnames resolve in DNS.                                                                                                                                                                                         |
| Egress controls      | [Allow all, deny all, or domain/CIDR allow lists](https://vercel.com/docs/sandbox/concepts/firewall); denied CIDRs take precedence | [Outbound intercepts](https://developers.cloudflare.com/containers/configuration/outbound-traffic/) that send matching HTTP or HTTPS requests to a `WorkerEntrypoint`, with 128 intercept entries per container. Other protocols can't be intercepted. |
| Runtime updates      | Replace the policy without restarting the session                                                                                  | Register a handler again to replace it. An intercept can't be removed while the container runs.                                                                                                                                                        |
| Credential injection | Brokering rules on allowed domains that match path, method, query parameters, and headers                                          | Handler code adds the credential after the request leaves the container. Cloudflare says to add credentials only to HTTPS requests.                                                                                                                    |
| HTTPS inspection     | Per-sandbox CA for domains with request-transforming rules                                                                         | Ephemeral CA that the container must trust; see [certificate setup](https://developers.cloudflare.com/containers/configuration/outbound-traffic/)                                                                                                      |
| Inbound access       | Up to 15 ports, each with a public URL that anyone with the URL can reach                                                          | No public port. Your Worker forwards requests to the container with `getTcpPort(port).fetch(request)`.                                                                                                                                                 |
| Compliance           | SOC 2 Type II certified infrastructure; snapshots encrypted at rest                                                                | Confirm whether Containers and Sandbox are included in the applicable [audit scope](https://www.cloudflare.com/trust-hub/compliance-resources/)                                                                                                        |

Credentials stored in a sandbox's environment are visible to code running there. Both products can instead add secrets after requests leave the sandbox: Vercel uses brokering rules, while Cloudflare runs handler code with access to Workers bindings such as KV and R2.

Code inside the sandbox can still make requests that those controls authorize. Restrict destinations and permissions to the task on either platform.

### Regions and placement

Vercel Sandbox runs in [19 regions](https://vercel.com/docs/sandbox/concepts/regions), with selection per sandbox or as a project default. Its default is `iad1` in Washington, D.C., and Pro and Enterprise teams can set failover regions. Snapshots stay in the region of the sandbox they came from.

Cloudflare manages instance placement and provides [jurisdiction controls](https://developers.cloudflare.com/containers/concepts/placement/) that depend on the scheduling policy. Confirm the placement guarantee for your configuration when latency or data residency matters. Compute placement does not determine where container images or snapshots are stored.

### Core SDK calls

Install and authenticate before running either sample:

- For Vercel, [set up the project below](#get-started-with-vercel-sandbox) to install the SDK and load its OIDC token.
  
- For Cloudflare, [create a TypeScript Worker project](https://developers.cloudflare.com/sandbox/get-started/) with Wrangler 4.141.0+ and Docker running locally. Use the Worker and configuration files below.
  

Save the Vercel script as `sandbox.mjs`. It runs a command, writes and reads a file, then stops the session. Cloudflare's `src/index.ts` starts a container through a Durable Object and returns command output.

**Run the Cloudflare sample locally only.** It accepts unauthenticated commands in a shared sandbox. Before exposing it, add request validation and authentication, then assign each authorized user or session its own sandbox identity.

**Vercel Sandbox**

```javascript
import { Sandbox } from '@vercel/sandbox';

const sandbox = await Sandbox.create();

try {
  const result = await sandbox.runCommand('node', ['--version']);
  console.log(await result.stdout());

  await sandbox.writeFiles([
    { path: 'hello.txt', content: Buffer.from('hi') },
  ]);
  const file = await sandbox.readFileToBuffer({ path: 'hello.txt' });
  console.log(file?.toString());
} finally {
  await sandbox.stop();
}
```

**Cloudflare Sandbox**

```typescript
import { DurableObject } from "cloudflare:workers";

export class MyContainer extends DurableObject<Env> {
	async exec(argv: string[]) {
		const container = this.ctx.container;
		if (!container) {
			throw new Error("No container is configured");
		}

		if (!container.running) {
			container.start({
				// Debian Trixie with Node.js 24
				image: "cloudflare/debian-trixie",
				// Keep the instance running so it can accept commands
				entrypoint: ["sleep", "infinity"],
				// Block commands in the sandbox from reaching the Internet
				enableInternet: false,
			});
		}

		const process = await container.exec(argv);
		const output = await process.output();
		return {
			stdout: new TextDecoder().decode(output.stdout),
			exitCode: output.exitCode,
		};
	}
}

export default {
	async fetch(request: Request, env: Env): Promise<Response> {
		const { argv } = (await request.json()) as { argv: string[] };
		const sandbox = env.MY_CONTAINER.getByName("sandbox");
		return Response.json(await sandbox.exec(argv));
	},
};
```

The Worker also needs a `wrangler.jsonc` that declares the container with the `durable_object` scheduling policy, which is in public beta, and binds the Durable Object class. The file is JSONC, which allows comments and trailing commas:

```text
{
	"$schema": "node_modules/wrangler/config-schema.json",
	"name": "sandbox-linux",
	"main": "src/index.ts",
	// Set this to today's date
	"compatibility_date": "2026-11-22",
	"observability": {
		"enabled": true,
	},
	"upload_source_maps": true,
	"containers": [
		{
			"class_name": "MyContainer",
			"scheduling_policy": "durable_object",
		},
	],
	"durable_objects": {
		"bindings": [
			{
				"class_name": "MyContainer",
				"name": "MY_CONTAINER",
			},
		],
	},
	"exports": {
		"MyContainer": {
			"type": "durable-object",
			"storage": "sqlite",
		},
	},
}
```

Generate the Worker types, then start the local server:

**pnpm**

```bash
pnpm exec wrangler types
pnpm exec wrangler dev
```

**yarn**

```bash
yarn exec wrangler types
yarn exec wrangler dev
```

**npm**

```bash
npx wrangler types
npx wrangler dev
```

**bun**

```bash
bunx wrangler types
bunx wrangler dev
```

In a second terminal, send a command to the local Worker:

```bash
curl http://localhost:8787 \
  -H 'Content-Type: application/json' \
  -d '{"argv":["node","--version"]}'
```

The JSON response contains the Node.js version in `stdout` and `0` in `exitCode`.

By default, `sandbox.stop()` ends the Vercel session and snapshots its files. The next `runCommand()` resumes the same sandbox from that snapshot.

In the Cloudflare Worker, `getByName("sandbox")` sends every request to one Durable Object. Its [`exec()`](https://developers.cloudflare.com/sandbox/sdk/migrate/changes-in-1-0/) method takes an argument array and does not invoke a shell. Use `sh -c` only when the command needs shell features such as pipes.

This sample sets no inactivity timeout and takes no snapshot, so local files disappear when the instance stops. It uses the container API directly; the additional file helpers in `@cloudflare/sandbox` require the [sandbox-shim binary](https://developers.cloudflare.com/sandbox/reference/) in your image.

Vercel's [Python SDK](https://vercel.com/docs/sandbox/sdk/python), `vercel-sandbox`, supports Python 3.11+ with sync and async APIs. Cloudflare documents a TypeScript API for Workers.

## Where Vercel Sandbox goes deeper

### Access from any runtime

Call Vercel Sandbox from a Vercel Function, a CI job, a server on another host, or your own machine. On Vercel and in local development, the SDKs use the project's OIDC token. Elsewhere, [pass an access token with the team and project IDs](https://vercel.com/docs/sandbox/concepts/authentication). The [Sandbox CLI](https://vercel.com/docs/sandbox/sdk/cli) and the [Sandboxes endpoints in the Vercel REST API](https://vercel.com/docs/rest-api/sandboxes) create sandboxes and run commands from a terminal or an HTTP client.

Cloudflare containers are [reached only through their Durable Object](https://developers.cloudflare.com/containers/concepts/architecture/), so an application outside Workers calls Worker routes that you write and deploy.

### Persistent workspaces by default

Vercel sandboxes save their filesystem automatically unless you set `persistent: false`. Snapshot expiration can be set to `0` for indefinite retention, and one snapshot can [seed multiple sandboxes](https://vercel.com/docs/sandbox/concepts/snapshots), subject to your plan's quotas.

On Cloudflare, call `snapshotContainer()`, store the handle, and pass it to a later `start()`. Snapshots are in public beta, tied to their original image, and expire 30 days after creation or the latest restore. Use [R2 directory backups](https://developers.cloudflare.com/sandbox/files/) for files that must outlive an image or persist without refreshing a snapshot's expiry.

### Drives

[Vercel Drives](https://vercel.com/docs/sandbox/concepts/drives) keep working files separate from the sandbox's starting environment. Mount up to four drives for workspaces or dependency caches and reuse their files in later sandboxes. The sandbox and drive must share a region. Each drive allows one writable mount, plus read-only snapshots for concurrent readers.

Cloudflare can mount an R2 bucket through [`S3Mount`](https://developers.cloudflare.com/sandbox/files/mount-an-r2-bucket/) over FUSE. The mount has object-storage semantics: renames, locks, and permissions differ from a local filesystem. Keep dependencies and build output on local disk, then write shared artifacts to the mount.

### Declarative egress firewall and credentials brokering

The Vercel [firewall](https://vercel.com/docs/sandbox/concepts/firewall) controls outbound access through modes and allow lists. Brokering rules inject credentials into requests that match a path, method, query, or header. Add a direct-response rule to block other requests to an allowed domain.

Policies can change while code runs, so an agent can begin with egress denied and receive access to selected APIs as its task progresses.

For private dependencies, [managed npm credentials](https://vercel.com/docs/sandbox/concepts/credentials) reuse your team's registry configuration, including GitHub Packages and JFrog Artifactory. Set `credentials: { npm: true }` at creation to let the firewall authenticate package downloads without storing tokens in the sandbox's `.npmrc`.

This supports package installation only. Configure the registry credentials as team Shared Environment Variables in Development or Preview, and allow the registry hosts in the network policy.

### Public port URLs

List ports at creation, up to 15, and [`sandbox.domain(port)`](https://vercel.com/docs/sandbox/examples/expose-a-port) returns each one's public URL. You don't configure DNS or routing. Anyone with the URL can reach the server, so expose only services you intend to share.

Cloudflare previews use [Worker routes](https://developers.cloudflare.com/sandbox/previews/), including path-based previews on `workers.dev`. Use [separate preview hostnames](https://developers.cloudflare.com/sandbox/previews/serve-previews-on-their-own-hostnames/) on a dedicated domain for untrusted apps to isolate them from your main application's origin and parent-domain cookies.

Separate hostnames require a proxied wildcard DNS record. If they sit below a subdomain, configure Total TLS or an advanced certificate to cover that extra level.

### Private network access

Attach a sandbox to a [Secure Compute network](https://vercel.com/docs/sandbox/concepts/secure-compute) to reach private APIs or databases in your AWS VPC over VPC peering. Public internet traffic leaves through the network's static IPs, which you can allowlist at external services. Secure Compute is an [additional Enterprise purchase](https://vercel.com/docs/networking/secure-compute).

Cloudflare's [Claude Managed Agents integration](https://blog.cloudflare.com/claude-managed-agents/) reaches private services through outbound proxies backed by Workers VPC or Cloudflare Mesh. That integration routes selected requests to private services through Worker code.

### Custom images from Vercel Container Registry

Store dependencies and tools in a `linux/amd64` OCI image in [Vercel Container Registry](https://vercel.com/docs/sandbox/concepts/images). Sandboxes start from the image but don't run its `ENTRYPOINT` or `CMD`, so start processes with `runCommand()` after creation.

Cloudflare builds an image from your Dockerfile with `wrangler deploy` or pulls one by digest from its registry. Direct references to Docker Hub, Amazon ECR, or Google Artifact Registry aren't supported. The `start()` call runs your entrypoint.

### Separate users for collaborating agents

[Create a Linux user for each agent](https://vercel.com/docs/sandbox/concepts/multi-agent) to give agents separate home directories and file permissions within one sandbox. The JavaScript and Python SDKs support users, and the JavaScript SDK adds groups with shared directories. Your application keeps access to every agent's files. The users share one microVM, so run agents in separate sandboxes when each needs its own kernel.

In a deployed Cloudflare sandbox, every process has root's Linux capabilities, so a separate Linux user doesn't restrict file access. Cloudflare [treats the sandbox as the smallest unit of trust](https://developers.cloudflare.com/sandbox/concepts/security/).

### Agent frameworks and hosted agent APIs

eve's [`eve/sandbox/vercel`](https://vercel.com/docs/frameworks/agents/eve) provider supports Vercel Sandbox and Drive mounts. [Mastra](https://vercel.com/docs/sandbox/ecosystem/mastra) and [Flue](https://vercel.com/docs/sandbox/ecosystem/flue) also integrate with Vercel Sandbox. The [ecosystem](https://vercel.com/docs/sandbox/ecosystem) includes LangChain, TanStack AI, and the OpenAI and Anthropic SDKs.

For hosted agent APIs, Vercel Sandbox integrates with [Gemini API Managed Agents](https://vercel.com/docs/sandbox/ecosystem/gemini-api) and the [OpenAI Agents API](https://vercel.com/docs/sandbox/ecosystem/openai-agents-api). Cloudflare offers templates for Claude Managed Agents and the OpenAI Agents API, plus a [Sandbox tool](https://developers.cloudflare.com/agents/tools/sandbox/) in its Agents SDK.

### Coding agents in a coding sandbox

Coding agents can run inside Vercel Sandbox or offload work from your machine:

- **Run the agent inside a sandbox.** The [Sandbox CLI](https://vercel.com/docs/sandbox/sdk/cli) starts a supported agent, such as OpenCode, Claude Code, or Codex, in a sandbox, and you use its interface from your local terminal.
  
- **Keep the agent local and offload heavy work.** The agent edits on your machine and uses Vercel Sandbox as a remote coding sandbox. The [offload-to-sandbox](https://skills.sh/vercel/vercel-plugin/offload-to-sandbox) skill, included in the [Vercel plugin](https://vercel.com/docs/agent-resources/vercel-plugin), moves heavy builds, long test suites, and parallel tasks into their own sandboxes, then collects the results and cleans up.
  

Hosted coding agents can run in Vercel Sandbox too. The [Cursor integration](https://vercel.com/docs/sandbox/ecosystem/cursor) gives each Cursor Cloud Agents request its own microVM, and the [Devin integration](https://vercel.com/docs/sandbox/ecosystem/devin) runs Devin Outposts sessions in sandbox microVMs.

Cloudflare has [guides for running Claude Code, Codex, OpenCode, and Pi](https://developers.cloudflare.com/sandbox/coding-agents/) in a sandbox, plus templates for Devin and Cursor Cloud Agents.

## Where Cloudflare Sandbox goes deeper

### Sandboxes inside your Worker and Durable Object

When your application already runs on Workers, the sandbox is part of a Durable Object class you own. The same name always reaches the same Durable Object, which can store session details and snapshot handles in its own storage. The [Agents SDK Sandbox tool](https://developers.cloudflare.com/agents/tools/sandbox/) attaches a container to an agent's Durable Object, so each named agent gets its own sandbox and every turn reaches the same one.

### Lifetimes driven by request activity

Cloudflare can keep an instance available for up to six hours after its Durable Object becomes inactive. Requests arriving before that timeout reuse the instance while it remains running. There is no fixed maximum runtime, although process exits and platform events can stop it.

Deploying a new Worker version doesn't replace running sandboxes. Reapply the [inactivity timeout](https://developers.cloudflare.com/sandbox/concepts/lifetime/#the-timeout-does-not-survive-a-restart) after the Durable Object restarts, including in its constructor when a container is already running. Vercel instead limits each session to 45 minutes on Hobby or 24 hours on paid plans.

### Fractional-vCPU instances

Cloudflare's `lite` type has 1/16 vCPU, 256 MiB of memory, and 2 GB of disk, and `standard-1` has 1/2 vCPU and 4 GiB. You can also pass a [custom size](https://developers.cloudflare.com/containers/platform/limits/) with `vcpu`, `memoryMib`, and `diskMb`, down to the same minimums as `lite`. Your class picks the image and size each time it starts an instance.

### Egress handlers and preview routing in code

Outbound handlers are `WorkerEntrypoint` classes, so they can apply custom policy, reroute traffic, reach Workers bindings, and [scope credentials to one instance](https://developers.cloudflare.com/containers/configuration/outbound-traffic/) by passing the Durable Object ID in `props`. Registering a target again swaps its handler without dropping open connections.

Previews follow the routing and authentication you write. Cloudflare's example shares a preview through random, expiring tokens that the Durable Object stores.

## How pricing compares

[Vercel Sandbox](https://vercel.com/docs/sandbox/pricing) and [Cloudflare Containers](https://developers.cloudflare.com/containers/platform/pricing/) meter different resources. Cloudflare adds charges for the [Workers](https://developers.cloudflare.com/workers/platform/pricing/) and [Durable Objects](https://developers.cloudflare.com/durable-objects/platform/pricing/) that front each sandbox.

| **Product**                            | **Billing units**                                                                                                        |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| Vercel Sandbox                         | Active vCPU-hours, provisioned memory in GB-hours, sandbox creations, and snapshot storage in GB-months                  |
| Cloudflare Containers                  | Active vCPU-seconds, provisioned memory in GiB-seconds, and disk in GB-seconds, metered every 10ms; network egress in GB |
| Cloudflare Workers and Durable Objects | Worker requests and CPU time; Durable Object requests, duration, and storage. Requires the Workers Paid plan.            |

Check [Cloudflare snapshot pricing](https://developers.cloudflare.com/containers/platform/pricing/) for the current beta terms.

Vercel also meters data the sandbox sends to the internet and traffic in both directions through exposed ports, in GB, while downloads into the sandbox are free. Drive usage adds storage in GB-months and reads and writes in GB. Vercel's CPU, memory, data transfer, and Drive rates vary by region, and Cloudflare's egress rate depends on the region group.

Both products charge for memory while a sandbox waits. Vercel meters provisioned memory throughout the session; Cloudflare bills memory and disk while an instance runs, even when idle. An accepted WebSocket also keeps the Durable Object active, so it continues accruing duration charges while keeping the sandbox alive.

Estimate each bill from a representative task's CPU use, run time, storage, and transfer, using the rates and allowances for your plan and region.

## Choose by workload requirements

Compare these AI agent sandboxes against your workload requirements:

| **Requirement**                                            | **Product fit**    | **Reason**                                                                                    |
| ---------------------------------------------------------- | ------------------ | --------------------------------------------------------------------------------------------- |
| Call sandboxes from any runtime, CI job, or host           | Vercel Sandbox     | TypeScript and Python SDKs, a CLI, and a REST API with OIDC or access-token auth              |
| Automatic file persistence between sessions                | Vercel Sandbox     | Snapshot on stop; an operation such as `runCommand()` resumes the VM                          |
| Egress rules and credential injection as configuration     | Vercel Sandbox     | Firewall modes and brokering rules that match path, method, query, and headers                |
| Shareable preview URLs without DNS setup                   | Vercel Sandbox     | Public URL for each exposed port, up to 15                                                    |
| Choose a specific Vercel deployment region                 | Vercel Sandbox     | 19 regions, chosen per sandbox or project                                                     |
| Attach a sandbox to a Secure Compute network               | Vercel Sandbox     | Enterprise network with AWS VPC peering and static egress IPs                                 |
| More than 4 vCPUs without a custom limit request           | Vercel Sandbox     | Up to 8 vCPUs on Pro and 32 on Enterprise; Cloudflare can raise its default limits on request |
| Sandbox in the same Durable Object as your Worker or agent | Cloudflare Sandbox | `this.ctx.container` on your own class                                                        |
| Instance lifetime tied to request activity                 | Cloudflare Sandbox | Inactivity timeout of up to 6 hours, with no fixed maximum runtime                            |
| Fractional-vCPU instances                                  | Cloudflare Sandbox | `lite` at 1/16 vCPU and 256 MiB, or custom sizes                                              |
| Egress policy as code with access to Workers bindings      | Cloudflare Sandbox | Outbound handlers in the Workers runtime                                                      |
| Preview hostnames and authentication you define            | Cloudflare Sandbox | Worker routing on your own domain                                                             |

Both products put generated code behind a microVM boundary, so the choice usually comes down to where your application runs and how much of the lifecycle and network policy you want to write yourself.

## Get started with Vercel Sandbox

Before you begin, make sure you have a [Vercel account](https://vercel.com/signup), the [Vercel CLI](https://vercel.com/docs/cli), and Node.js 22 or later. Sandbox is available on Hobby within the included usage.

Link this directory to the Vercel project that will own your sandboxes:

```bash
vercel link
```

Pull the project's environment variables into `.env.local`, including its development OIDC token. The token expires after 12 hours; repeat this command to refresh it.

```bash
vercel env pull
```

Install the SDK:

**pnpm**

```bash
pnpm i @vercel/sandbox
```

**npm**

```bash
npm i @vercel/sandbox
```

**yarn**

```bash
yarn add @vercel/sandbox
```

**bun**

```bash
bun add @vercel/sandbox
```

Save the Vercel sample from [Core SDK calls](#core-sdk-calls) as `sandbox.mjs` in the linked directory.

Each run creates a persistent sandbox and uses your plan's allowances or billing. For a disposable run without snapshot storage, pass `persistent: false` to `Sandbox.create()`.

Run the script with the environment file loaded:

```bash
node --env-file=.env.local sandbox.mjs
```

The script prints the sandbox's Node.js version and `hi`, then stops the session. With default persistence, its files remain in a saved snapshot.

## Start from an eve template

The [eve with Vercel Drives template](https://vercel.com/templates/eve/eve-vercel-drives-starter) connects an agent in Slack or a terminal to shared team files. Each session reads a Drive snapshot mounted at `/drive`.

The `save_to_drive` tool opens a separate, short-lived sandbox with write access. This keeps ordinary sessions read-only and gives updates a dedicated write path.

## Next steps

- Configure [session timeouts and persistent files](https://vercel.com/docs/sandbox/concepts/persistent-sandboxes)
  
- Restrict egress and broker credentials with the [Sandbox firewall](https://vercel.com/docs/sandbox/concepts/firewall)
  
- Expose a dev server with [public ports](https://vercel.com/docs/sandbox/examples/expose-a-port)
  
- Authenticate from [outside Vercel with an access token](https://vercel.com/docs/sandbox/concepts/authentication)
  
- Estimate your bill with [Sandbox pricing and quotas](https://vercel.com/docs/sandbox/pricing)
  
- Compare Vercel Sandbox with [E2B](https://vercel.com/kb/guide/vercel-sandbox-vs-e2b) and [Upstash Box](https://vercel.com/kb/guide/vercel-sandbox-vs-upstash-box)
  

## Frequently asked questions

### Is Cloudflare Sandbox a microVM like Vercel Sandbox?

Yes. Cloudflare runs each Container instance in a Firecracker microVM with its own kernel and network, and the sandbox image runs as a Linux container inside that VM. Vercel Sandbox also gives every sandbox its own Firecracker microVM and kernel. The two differ in how you reach, size, and persist a sandbox.

### Can I use these sandboxes outside Vercel or Cloudflare?

Cloudflare containers are reachable only through their Durable Object, so code outside Workers has to call Worker routes you build. Vercel Sandbox works from any environment that can run its SDKs or call the Vercel REST API. Outside Vercel, authenticate with a Vercel access token plus your team and project IDs.

### What happens when a Vercel or Cloudflare sandbox stops?

Vercel saves a persistent sandbox's filesystem to a snapshot when the session ends, and the next SDK call that needs the VM restores it. Cloudflare instances lose their disk when they stop, so files survive only in a snapshot your code took, a directory backup in R2, or a mounted bucket. Running processes don't survive a stop on either product.

### Does Cloudflare Sandbox have internet access by default?

No. In Sandbox SDK 1.0, a container starts with `enableInternet: false`, and only requests that an outbound handler in your Worker intercepts can leave it. Vercel Sandbox starts with the `allow-all` firewall mode, and you can switch a sandbox to `deny-all` or a user-defined allow list while it runs.

### Can I run Docker in Vercel Sandbox and Cloudflare Sandbox?

Yes on both. Vercel Sandbox runs Docker and other system-level tools with `sudo` inside the microVM. Cloudflare supports Docker-in-Docker with the `docker:dind` image, with the daemon run as root and iptables and IP forwarding turned off.

Containers inside Vercel Sandbox must [trust its proxy CA certificate](https://vercel.com/docs/sandbox/concepts/security#trust-the-proxy-ca-in-containers) when calling domains with request-modifying firewall rules, such as credential injection.

### Can I run Python in Vercel Sandbox and Cloudflare Sandbox?

Vercel's default universal image includes Python 3.14. Its `vercel-sandbox` SDK lets Python 3.11+ apps create and control sandboxes. Cloudflare's managed `cloudflare/debian-trixie` image lacks Python, so add it to a custom image. Cloudflare's control API runs in a TypeScript Worker.

### Can I use either product as an AI code interpreter?

Yes. Both can sandbox AI-generated code for tasks such as data analysis. Use Vercel's [SDKs](https://vercel.com/docs/sandbox#using-vercel-sandbox) from your backend, or control Cloudflare's Linux environment through a [Worker and Durable Object](https://developers.cloudflare.com/sandbox/#containers). Restrict either agent sandbox's files, credentials, and network access to what the task requires.

## Related Resources

- [Vercel Sandbox vs E2B](/kb/guide/vercel-sandbox-vs-e2b): A detailed guide to Vercel Sandbox vs E2B: compute lifecycle, security controls, code execution, pricing, and when to choose each sandbox for your AI agent workloads.
- [Vercel Sandbox vs Upstash Box](/kb/guide/vercel-sandbox-vs-upstash-box): Compare Vercel Sandbox and Upstash Box as AI agent sandboxes, including isolation, persistence, network controls, SDKs, and deployment regions.
- [How Vercel Sandbox duration and persistence work](/kb/guide/vercel-sandbox-duration-and-persistence): Session duration and persistence are two separate controls in Vercel Sandbox. The timeout option keeps a single run alive for up to 24 hours, while snapshots and persistent sandboxes carry state across runs for long-running agents and pipelines.

## More Vercel Sandbox guides

- [Vercel Sandbox vs Upstash Box](/kb/guide/vercel-sandbox-vs-upstash-box): Compare Vercel Sandbox and Upstash Box as AI agent sandboxes, including isolation, persistence, network controls, SDKs, and deployment regions.
- [Add Python code execution to a TypeScript AI agent with Vercel Sandbox](/kb/guide/python-ai-sdk-vercel-sandbox): Add an \`executeCode\` tool to your TypeScript AI SDK agent with the \`ai-sdk-tool-code-execution\` package to run Python 3.13 inside an isolated Vercel Sandbox.
- [Build a v0-style app builder with OpenAI Agents API and Vercel Sandbox](/kb/guide/v0-clone-openai-agents-vercel-sandbox): Build a chat-to-app workspace with live Next.js previews, follow-up edits, and saved projects using the OpenAI Agents API preview, Vercel Sandbox, and Queues.

## Reference Architecture

Choose a stack and work through the decisions behind it, with curated documentation, guides, templates, and courses to help you build.

- [Agent stack](/kb/architecture/agents): Build and operate agents with models, tools, and durable workflows.
- [Web applications](/kb/architecture/web): Choose rendering, data, authentication, and caching approaches.
- [Backends](/kb/architecture/backends): Choose a runtime, connect services, and run background work.

[Browse all stacks](/kb/architecture)

## Build with prompts

Build an app, extend an agent, or improve your project with ready-to-use prompts for your coding agent.

[Browse the prompt library](/kb/prompts) · [Read the Markdown index](/kb/prompts.md)

## Search guides from your terminal

Search the Knowledge Base and read guides as Markdown with the Vercel CLI. No login required.

```bash
# Find guides by keyword
npx vercel@latest kb search "rewrites and redirects"
npx vercel@latest kb search "AI SDK streaming"

# Show the latest guides
npx vercel@latest kb

# Print a guide as Markdown, by slug or URL
npx vercel@latest kb inspect <guide>
```
