Skip to main content

Guide · Agent infrastructure

Best Sandboxes for Running AI Agent Code

Last reviewed

Once an agent can write and run code, you are executing untrusted input. The model can be wrong, and a prompt injection can make it hostile, so the code needs a box where it cannot read your secrets, reach your network or touch your host. The real decision is how strong that box needs to be (container, gVisor or a microVM), whether you rent it as an API or run it yourself, and how close it sits to the rest of your stack.

Quick pick

Drop-in code execution API for an agent
E2B
Long-running dev environments an agent can work inside
Daytona
Python workloads that may need GPUs
Modal Sandboxes
Your app already runs on Cloudflare Workers
Cloudflare Sandbox SDK
Your app already deploys on Vercel
Vercel Sandbox
Full control on your own hardware
Firecracker or gVisor

The options, and when to use each

Docker (local)

localcontainers

Use it for: Prototyping on your own machine, or running an agent you trust over code you mostly trust.

Tradeoff: Containers share the host kernel, so a plain container is a weak wall for hostile code. Drop capabilities, block the network and never mount the Docker socket.

E2B

open sourceAPIisolated machines

Use it for: You want an SDK call that gives the agent its own isolated machine to run code, then throws it away.

Tradeoff: Another vendor in the request path, and long-lived or heavy workloads need more planning than quick snippets.

Daytona

APIisolated runtimes

Use it for: Agents need a full workspace with a file system, processes and real-time output, not just one-off snippets.

Tradeoff: More environment than you need if the agent only runs short calculations.

Modal Sandboxes

gVisor or VM runtimePythonGPUs

Use it for: You already use Modal or the generated code needs heavy compute, with a choice between gVisor and VM runtimes.

Tradeoff: Best fit for Python stacks; adopting Modal just for sandboxes adds a platform to learn.

Cloudflare Sandbox SDK

Workerscontainers

Use it for: Your agent lives in a Worker and you want to run generated code from there without another provider.

Tradeoff: The docs note it needs the Workers Paid plan, and it ties your sandboxes to the Cloudflare platform.

Vercel Sandbox

microVMsVercel

Use it for: Your app is on Vercel and you want agent output run in isolated Linux microVMs next to it.

Tradeoff: Most convenient inside the Vercel ecosystem; less so if the rest of your stack lives elsewhere.

Fly Machines

fast-launching VMsREST API

Use it for: You want to start and stop your own virtual machines per task through an API and control the image yourself.

Tradeoff: A general compute primitive, not a sandbox product: you build the lifecycle, timeouts and cleanup.

Firecracker or gVisor (DIY)

open sourceself-hostedmicroVM or user-space kernel

Use it for: You need sandboxes on your own servers: Firecracker gives microVMs, and gVisor (gvisor.dev) adds a user-space kernel in front of containers.

Tradeoff: You own the hard parts: images, networking, scheduling, cleanup and keeping the isolation layer patched.

Skills that use these tools