Skip to content
Dashboard

7 AI sandbox providers compared

Content Engineer

AI sandbox providers give agents an isolated environment for running generated code, testing changes, and working with files. Vercel Sandbox, E2B, Daytona, Modal, Cloudflare Sandboxes, Blaxel, and Fly.io Sprites support different execution and state requirements. Choose according to what your code needs to run and what must survive between sessions.

Vercel publishes this comparison and provides the first product listed. These seven providers offer programmable environments for executing untrusted code, with different approaches to agent workspaces and code-interpreter tasks. The order isn't a performance or security ranking, and the list isn't exhaustive.

Copy link to headingHow do you choose a sandbox for AI agents?

When choosing a provider for AI code execution, start with a representative task. Running a Python calculation once has different state requirements from returning to the same repository over several days. Notebook-style execution may also need to preserve variables and imported modules between code calls.

Evaluate the isolation boundary alongside the APIs your application will use. Agent sandboxes can expose shell commands, a stateful interpreter, or methods for interacting with a remote workspace. These interfaces change how you send code, handle errors, and retrieve files.

Filesystem persistence keeps files, while memory preservation can retain interpreter variables and process state. Neither guarantees that a remote database connection remains usable after a pause. Test the lifecycle your workload needs and confirm exactly what each snapshot restores.

Network access needs a separate decision. An isolated program can still send data to a destination it can reach. Check whether a provider can block outbound traffic, allow only selected destinations, and keep API credentials outside the sandbox. Apply the policy explicitly rather than relying on a default.

Provider

Isolation options

Retained state

Outbound network controls

Integration

Vercel Sandbox

Firecracker microVM

Persistent filesystem; filesystem snapshots

Deny-all or domain/IP rules; credential brokering

TypeScript and Python SDKs

E2B

Firecracker microVM

Interpreter state between calls; filesystem and memory on pause

Internet off switch; allow/deny lists

Sandbox SDKs; separate Code Interpreter SDK

Daytona

Container or VM classes

Filesystem snapshots; VM memory with selected snapshot modes

Tier-dependent policy; custom rules on Tiers 3 and 4

SDKs and lifecycle APIs

Modal

VM or gVisor; GPUs require gVisor

Filesystem snapshots; memory snapshots in alpha

Block-all or CIDR rules; TLS domain rules in beta

Sandbox APIs within Modal's compute platform

Cloudflare Sandboxes

Linux container in a microVM, or Dynamic Worker

Container filesystem snapshots in public beta

Worker-controlled outbound access and credential handling

Cloudflare Worker APIs

Blaxel

VM

Filesystem and process state through standby

Domain filtering in public preview; firewall enforcement requires configuration

SDKs, REST API, and MCP

Fly.io Sprites

Hardware-isolated Linux VM

Persistent files and filesystem checkpoints

Domain-based allow/deny policies

CLI and API

Workload recommendations are editorial judgments based on the linked product documentation; no comparative benchmark was run. Several providers can serve the same workload, so use the differences to decide which ones to test.

Copy link to heading1. Use Vercel Sandbox for isolated execution in your application

Vercel Sandbox runs code in Firecracker microVMs that you control through TypeScript or Python SDKs. Your application can create an environment, write files, execute a command, and retrieve its output. This fits an agent that generates a Python analysis script or edits a repository and runs its tests.

The Sandbox firewall enforces network policy outside the program. It can restrict destinations and add credentials to outgoing requests, allowing code to call an authenticated API without receiving the raw key. Public internet access is allowed by default, so configure deny-all or a destination policy when the task needs restricted access.

Notion uses this model for Notion Workers, which execute code written by third-party developers and agents. Each Worker gets its own microVM, with controls for network access and credentials.

Choose the lifecycle deliberately. Vercel's persistent sandboxes retain filesystem state between sessions, while non-persistent sandboxes support disposable execution. Restoring a filesystem snapshot doesn't restore a running Python interpreter's memory. If your product expects notebook variables to survive, it needs an interpreter design that supplies that behavior.

For implementation, start with the KB guide to running untrusted Python or the guide to executing AI-generated code from Next.js. Vercel is a natural candidate when your application already uses its project authentication and you want generated programs to execute separately from the application backend.

Copy link to heading2. Evaluate E2B for code-interpreter applications

E2B provides cloud sandboxes with SDKs for commands and files. Its Code Interpreter SDK retains variables between calls and returns structured results such as charts. This supports follow-up analysis of data already in memory.

For example, an analyst might ask for revenue by region, then ask to exclude refunded orders. An interpreter can reuse its loaded data and imports as it evaluates the next code block. An application built around separate script processes must arrange equivalent reuse through files or another state mechanism.

E2B uses Firecracker microVM isolation. Its sandbox execution, Code Interpreter, and desktop products are separate entry points into the platform, so choose the SDK that matches the interaction you need. Installing the base sandbox SDK doesn't by itself provide the Code Interpreter's result model.

E2B's pause and resume preserves filesystem and memory state. Its internet-access controls can disable outbound access or apply allow/deny lists; internet access is enabled by default.

During evaluation, test a complete conversation rather than a single successful cell. Confirm how you associate interpreter state with a user and how a reset affects the next question. Keep the raw dataset available when a failed or interrupted session needs to reconstruct its analysis.

Copy link to heading3. Evaluate Daytona for development workspaces

Daytona provides programmable environments for agents to run commands and work with project files. Its lifecycle APIs cover operations such as creating, stopping, and deleting sandboxes. Development workflows can retain the working environment instead of rebuilding project setup for every interaction.

Reusable Daytona snapshots can define the environment a task starts from. You can prepare language dependencies and project tooling once, then create workspaces from that setup. This is useful when an agent needs a repository-specific test environment across repeated tasks.

Daytona offers container and VM sandbox classes. Container snapshots retain filesystem state; a VM hot snapshot can also include memory when that option is enabled. Select the isolation class and snapshot mode together, since restoring project files is different from resuming an in-progress process.

Network policy depends on the organization's tier. Tiers 1 and 2 use an organization policy that individual sandboxes can't override. Tiers 3 and 4 support custom per-sandbox block-all, domain-allowlist, or CIDR-allowlist policies. Confirm that the available policy can express your workload's required access.

Test a repository change across several commands, then return to the workspace. Check how your application resumes work after the environment stops. Confirm that the next task receives the intended revision without another user's changes.

Modal Sandboxes provide isolated execution within Modal's compute platform. You can define the environment's image and resources, then run programs through its sandbox API. This makes Modal relevant when generated code needs to work alongside an existing Python compute application or requires GPU resources.

Runtime selection affects the available capabilities. Modal supports VM and gVisor sandbox runtimes, and its GPU sandboxes require the gVisor runtime. Evaluate the isolation model with the resources your production workload requires.

Modal's network controls can block outbound access or restrict it to selected CIDR ranges. TLS domain allowlists are in beta and apply to port 443. A model-weight download during preparation and an offline computation afterward may need different access.

For retained state, Modal offers filesystem snapshots and alpha memory snapshots. If an interrupted computation must resume from memory, evaluate that feature's maturity alongside the runtime and GPU requirements.

For a trial, include the full input and output path. Running a GPU command successfully doesn't establish that the application can transfer its dataset, retain artifacts, and recover from an interrupted job. Test those steps before deciding whether the integration fits.

Copy link to heading5. Use Cloudflare Sandboxes from a Worker

Cloudflare Sandboxes gives Workers applications two execution options. Containers provide a Linux environment for commands and installed tools, with each instance running in a microVM with its own kernel. Dynamic Workers load untrusted code into a separate Worker and expose the application methods that code can call.

Choose Linux for a coding agent that needs a shell, native tools, or a repository's test runner. Transformations that only call methods supplied by your Worker may fit a Dynamic Worker. The choice determines which APIs are available and how much environment setup your application owns.

Cloudflare's sandbox security model treats the contents of each sandbox as shared by the code inside it. Assign separate environments to unrelated users or jobs, and derive their identities from authenticated application state. Don't let a caller-supplied sandbox name determine whose workspace the request receives.

The Worker can also control outbound requests and attach credentials without exposing tokens to sandboxed code. Container filesystem snapshots are in public beta and don't save memory or running processes.

Cloudflare is worth evaluating when a Worker already coordinates the application. Test which credentials remain in the Worker and how your application validates output from the execution environment.

Copy link to heading6. Evaluate Blaxel for sessions that resume after inactivity

Blaxel sandboxes run in VMs and can move into standby when they have no active connection. Standby preserves filesystem and process state, then restores the sandbox when a client reconnects. An agent that works intermittently in the same environment can use this lifecycle to retain its working context between interactions.

Restoring process memory doesn't restore external connections. The database or API may have closed its side while the environment was paused. Resumed code must reconnect and check whether any interrupted operation already completed.

That makes a pause-and-return workflow a better evaluation than a continuous execution. Leave a workspace idle, reconnect, and check both local state and remote-service behavior. If the agent writes to an external system, include a way to identify repeated operations so a reconnect doesn't create duplicates.

Blaxel's domain filtering is in public preview and isn't recommended for production. Its proxy settings alone can be bypassed by tools that ignore them; network-level enforcement requires enabling the proxy firewall ruleset on supported infrastructure. If restricted outbound access is a requirement, verify that enforcement is available for the environment you select.

Standby and deletion also have different consequences. Use a retention policy that matches how long a user's workspace should remain available, and provide a deliberate reset path for tasks that need a clean environment.

Copy link to heading7. Evaluate Fly.io Sprites for persistent Linux workspaces

Fly.io Sprites are hardware-isolated Linux VMs intended for persistent environments, including AI agents and untrusted code. Files remain available between runs, which suits work that accumulates a repository, installed tools, or intermediate artifacts over time.

The workspace model can fit an agent that returns to an unfinished project. Instead of recreating every file from conversation history, the agent can inspect the existing environment and continue. Your application still needs to establish which user owns that environment and what a subsequent task is allowed to reuse.

Sprites also provides filesystem checkpoints for returning to an earlier state. Restoring an earlier filesystem can discard later edits, and it doesn't undo changes already sent to an external API.

Sprites exposes workspace operations through its CLI and API, including domain-based network allow/deny policies. Configure outbound access alongside the workspace's retention rules.

Evaluate persistence with a task that makes changes, stops, and returns later. Then test recovery from an unwanted edit, including which files the checkpoint restores and which later changes it removes.

Copy link to headingHow do you use a sandbox with your AI agent?

Your agent framework controls the model loop and tool calls. Code sandboxes give agents an isolated place to run commands and work with files. You can connect them by exposing sandbox operations as tools, or by starting a coding agent inside the sandbox. The choice depends on whether you are building the agent's tool loop yourself or using an existing agent such as Claude Code.

These integrations use Vercel Sandbox and a server-side Node.js 24+ project. Configure authentication, workspace ownership, and cleanup for your application before using them with real users.

Copy link to headingGive an eve agent a session workspace

eve's sandbox integration connects the built-in bash, read_file, write_file, and edit_file tools to a session workspace.

Add the configuration to agent/sandbox.ts in your eve project:

agent/sandbox.ts
import { defineSandbox } from 'eve/sandbox';
import { VercelSandbox } from 'eve/sandbox/vercel';
export const environment = VercelSandbox.environment();
export default defineSandbox(() => environment.open());

Use agent/sandbox/sandbox.ts if the project already has that directory.

Each session gets its own sandbox and keeps files across turns, so an assistant can revise a report after a follow-up request. Authored tools use ctx.getSandbox() to access the same workspace.

Run eve link to connect local development to a Vercel project. Configure deployment credentials, reusable setup, and network policies for that environment. Vercel Drives can retain files independently of the session.

Copy link to headingConnect an AI SDK tool to a sandbox

With AI SDK, the model loop stays in your application while commands run remotely. Its experimental sandbox interface makes that environment available to tools. Tool execute functions still run in your application and must call the sandbox explicitly to execute a command there.

Install the dependencies for the server-side TypeScript example:

pnpm add ai @ai-sdk/sandbox-vercel zod

Configure Sandbox authentication and set AI_GATEWAY_API_KEY in the host environment. Set AI_GATEWAY_MODEL to a tool-capable model ID from AI Gateway.

ai-sdk-agent.mts
import {
createVercelNetworkSandboxSession,
} from '@ai-sdk/sandbox-vercel';
import { isStepCount, tool, ToolLoopAgent } from 'ai';
import { z } from 'zod';
const model = process.env.AI_GATEWAY_MODEL;
if (!model) throw new Error('Set AI_GATEWAY_MODEL');
const session = await createVercelNetworkSandboxSession({
runtime: 'node24',
persistent: false,
timeout: 60_000,
networkPolicy: 'deny-all',
});
try {
const agent = new ToolLoopAgent({
model,
stopWhen: isStepCount(5),
tools: {
shell: tool({
description: 'Run a shell command in the isolated workspace.',
inputSchema: z.object({ command: z.string() }),
execute: async (
{ command },
{ experimental_sandbox, abortSignal },
) => {
if (!experimental_sandbox) {
throw new Error('Sandbox is unavailable');
}
const result = await experimental_sandbox.run({
command,
abortSignal,
});
return {
exitCode: result.exitCode,
stdout: result.stdout.slice(0, 12_000),
stderr: result.stderr.slice(0, 12_000),
};
},
}),
},
});
const result = await agent.generate({
experimental_sandbox: session.restricted(),
prompt:
'Use Node.js to calculate the sum of integers from 1 through 100.',
});
console.log(result.text);
} finally {
await session.destroy();
}

The model request leaves from your application, so the sandbox can deny outbound access during the calculation. The example allows up to five model steps and requests workspace cleanup in a finally block. The expected answer is 5,050; the model's wording can vary.

Each tool result returns up to 12,000 characters from each output stream. Truncation happens after collection, so it doesn't bound output buffered in the host. For public submissions, consume and limit streamed output. Pin compatible versions of the experimental interface and adapter.

Copy link to headingRun a coding agent through TanStack AI

TanStack AI's sandbox middleware can start a coding agent inside the selected environment and stream its work through chat(). It separates the provider, workspace setup, and agent adapter. Its provider integrations include Vercel, E2B, Daytona, Blaxel, and Sprites.

This Claude Code agent inspects a public repository. Install its dependencies:

pnpm add @tanstack/ai @tanstack/ai-claude-code \
@tanstack/ai-sandbox @tanstack/ai-sandbox-vercel

Set ANTHROPIC_API_KEY in the host environment, along with the Vercel credentials VERCEL_TOKEN, VERCEL_TEAM_ID, and VERCEL_PROJECT_ID.

tanstack-agent.mts
import { randomUUID } from 'node:crypto';
import { chat } from '@tanstack/ai';
import { claudeCodeText } from '@tanstack/ai-claude-code';
import {
createSecrets,
defineSandbox,
defineWorkspace,
githubRepo,
withSandbox,
} from '@tanstack/ai-sandbox';
import { vercelSandbox } from '@tanstack/ai-sandbox-vercel';
const apiKey = process.env.ANTHROPIC_API_KEY;
if (!apiKey) throw new Error('Set ANTHROPIC_API_KEY');
const workspace = defineSandbox({
id: 'repository-reader',
provider: vercelSandbox({ persistent: false, timeout: 300_000 }),
workspace: defineWorkspace({
source: githubRepo({ repo: 'TanStack/ai' }),
setup: ['npm install -g @anthropic-ai/claude-code --include=optional'],
secrets: createSecrets({ ANTHROPIC_API_KEY: apiKey }),
}),
lifecycle: { reuse: 'none', snapshot: 'none', destroyOnComplete: true },
});
const stream = chat({
threadId: randomUUID(),
adapter: claudeCodeText('claude-opus-4-8'),
messages: [
{
role: 'user',
content: 'Read the README and explain this repository.',
},
],
middleware: [withSandbox(workspace)],
});
for await (const chunk of stream) {
if (chunk.type === 'TEXT_MESSAGE_CONTENT') {
process.stdout.write(chunk.delta);
}
if (chunk.type === 'RUN_ERROR') throw new Error(chunk.message);
}

Here the sandbox needs network access to clone the repository, install the CLI, and contact the model provider. The model API key enters the sandbox as a workspace secret, so use a credential scoped for that workload. The explicit lifecycle creates a disposable environment for this run. For follow-up work on the same repository, configure thread reuse and persistence together.

TanStack AI can also make your application's server tools callable by the sandboxed agent. Those bridged tools execute on the host, with the host's permissions, so authorization belongs in each tool. For this integration, the bridge endpoint must be reachable from the remote sandbox.

Copy link to headingHow should you test a shortlist?

Use a fixed task with an expected result before introducing model variability. For a repository agent, pin a commit and dependency lockfile, apply the same patch, and run the same test command on each provider. For a data-analysis assistant, use one CSV and a fixed script that produces a known total and an output file. Once the execution path works, repeat the task with your agent generating the code.

Record the runtime, resource allocation, network policy, and saved-state mode with each result. Include dependency installation and data transfer in the trial so a successful command doesn't hide work the application still needs to perform.

Trial

What to do

What to verify

Complete the task

Run the fixed program with production-sized inputs

Expected result, exit status, retrievable artifacts, and useful error output

Interrupt and return

Write a marker file, set an interpreter variable if relevant, then pause or stop the environment

Which files and variables survive, whether processes restart, and whether remote connections recover

Restrict the network

Allow one test destination and block another; call both with the tools the agent will use

The allowed request succeeds and the blocked request fails, including when a tool ignores proxy settings

Bound execution

Run a process that exceeds the configured deadline and emits more output than the application retains

Cancellation stops work, output stays within application limits, and the failure reaches the caller

Check ownership

Create workspaces for two test users and try to resume the first through the second user's session

The application rejects access before returning files, logs, or a running environment

Recover a workspace

Save a checkpoint, modify a file, and restore it

The intended file revision returns and the application handles any external writes separately

Define acceptable outcomes before comparing results. A task that only needs files to survive doesn't require a memory snapshot. A notebook assistant that promises to preserve loaded variables does need a way to meet that promise after inactivity. Record any recovery or storage code you had to add, since that work becomes part of operating the integration.

For the final trial, use the concurrency your application expects and collect task completion rates and end-to-end timings. Keep cold starts, resumed workspaces, and already-running sessions separate in the results. This produces a comparison of the configurations you tested without treating different lifecycles as equivalent.

Copy link to headingWhat does choosing a provider leave unresolved?

The provider supplies the execution environment. Your application decides who can use it and what each task can do. Credential brokering keeps keys out of the sandbox, but API permissions must still limit what those keys authorize.

Reusing a workspace saves setup work and retains prior changes, including changes made by untrusted code. Use disposable environments for independent submissions and verify ownership before resuming a workspace.

Vercel Drives can retain files independently of sandbox compute when an application needs a separate storage lifecycle.

Copy link to headingFrequently asked questions

Copy link to headingIs one AI sandbox provider best for every agent?

No. Data-analysis assistants may need a stateful interpreter, while a repository agent needs command execution and a retained working directory. Choose based on the execution model and lifecycle your application requires, then test those requirements with a representative task.

Copy link to headingWhich providers should I evaluate for notebook-style code execution?

E2B is a relevant starting point because its Code Interpreter SDK preserves variables across code calls and returns structured results. Shell-oriented sandboxes can also host interpreters, but your application must provide and manage that integration. Check the distinction before treating a successful Python command as a complete notebook experience.

Copy link to headingDo all sandbox providers preserve the same state?

No. Files, interpreter memory, processes, and external connections have different lifecycles. Check the exact environment and snapshot mode, then test what remains after a pause or restart.

Copy link to headingCan I switch providers by changing the SDK import?

Usually the integration requires more work because providers differ in command handling, file APIs, authentication, and state retention. Keep your application's execution interface explicit and test those behaviors during a migration. Even a shared interface leaves differences in isolation and lifecycle behavior.

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: Build and operate agents with models, tools, and durable workflows.
  • Web applications: Choose rendering, data, authentication, and caching approaches.
  • Backends: Choose a runtime, connect services, and run background work.

Browse all stacks

Build with prompts

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

More Sandbox articles

Ready to deploy?