AI agent sandboxes: how to choose one for the agents you ship
What an AI agent sandbox is, how containers, gVisor, microVMs and WebAssembly isolate agent code, and the questions to ask before you run one agent per user.
By Designing AI Agents Editors · Updated
An AI agent sandbox is the isolated machine an agent runs its work in: the shell commands it writes, the packages it installs, the files it creates, the browser it drives. None of that code was reviewed by the team that ships the product, so the sandbox has two jobs at once. It has to keep the agent away from the host and from every other customer, and it has to give the agent a real enough computer to finish the task.
This guide is for teams putting agents inside a product, often one agent per end user. It covers the isolation models sandboxes are built on, the difference between throwaway and persistent sandboxes, and a checklist to run against any provider or in-house design before you commit.
Ephemeral or persistent: decide what the sandbox has to remember
The first question is not which isolation technology to use but how long the sandbox lives. The answer changes almost every other requirement on this page.
| Ephemeral sandbox | Persistent sandbox | |
|---|---|---|
| Lives for | One task or one tool call, then deleted with its disk | As long as the user or agent exists; sleeps when idle and resumes |
| Keeps | Nothing between runs | Files, installed packages, browser sessions, running processes (with snapshots) |
| Typical uses | Code interpreters, eval and RL runs, untrusted snippets | Per-user assistants, coding agents with a workspace, long-running background agents |
| Main risk | Cold-start time on every task | State, credentials and cost that outlive the task |
| What drives cost | How many run at once | How many exist, and what an idle one costs |
A product that gives each user an agent usually needs both: a persistent sandbox that holds the user's workspace, and throwaway ones for anything risky it runs on their behalf. Stateful vs stateless agents covers the trade-off in depth, and agent state persistence across sleep and redeploys covers what has to survive a pause.
The isolation models agent sandboxes are built on
Every sandbox puts a boundary somewhere between the agent's code and the host. Where that boundary sits decides what an exploit inside the sandbox can reach.
| Model | Examples | Shares the host kernel? | Runs ordinary Linux software? | Fits |
|---|---|---|---|---|
| OS process sandbox | seccomp, bubblewrap, macOS Seatbelt | Yes | Yes, with restrictions | Trusted, developer-written tools on one machine |
| Container | Docker / runc | Yes; namespaces and cgroups only | Yes | Your own code; not on its own for untrusted, model-written code across tenants |
| User-space kernel | gVisor (runsc) | No direct syscalls; gVisor re-implements them | Mostly; some syscalls and features are unsupported | Stronger isolation while staying in a container workflow |
| MicroVM | Firecracker, Cloud Hypervisor, Kata Containers | No; each sandbox boots its own guest kernel on hardware virtualization | Yes, a full Linux guest | Untrusted code, one machine per tenant or per task |
| WebAssembly | Wasm runtimes, Pyodide | No; code runs inside the Wasm runtime | Only code compiled to Wasm | Small, self-contained computations; not general shell work |
For agents that write and run their own code for many customers, the boundary that matters is whether two tenants share a kernel. Why every AI agent needs its own kernel walks through why that leads most teams to microVMs, and tenant-scoped execution boundaries shows how to draw the boundary per user.
The word sandbox alone does not tell you which of these you are getting. Ask what the boundary is, in those terms, before comparing anything else.
What to check before you pick a sandbox
Run these questions against a hosted provider or your own design. Each one maps to a way agent products fail in production.
- Isolation boundary. Which model from the table above, and is it one boundary per tenant, per user or per task? Who else's code can run on the same host kernel?
- Persistence. Does the disk survive a stop? Can the full machine, memory included, be snapshotted and restored, and can a new sandbox be cloned from a snapshot?
- Idle behaviour and wake time. What happens to a sandbox nobody is using, and how long does it take to come back? Measure resume time yourself, at the median and the slow tail, from the region your users are in.
- Lifecycle API. Create, pause, resume, snapshot, fork and delete should all be API calls your product can make per user, with a stable ID you can map to your own tenant.
- Network egress. Can you allow-list where a sandbox may connect, per tenant? An agent that can reach any address can leak whatever it can read.
- Secrets. Can credentials be injected from outside the guest so the agent never holds the real key? See credential and secret isolation in per-user agent VMs.
- Resource limits. CPU, memory and disk quotas per sandbox, and what happens to neighbours when one agent loops.
- What the agent can install and run. Root inside the guest, arbitrary packages, background processes, a real browser. See package installation in agent VMs and browser session persistence.
- Operating system. Linux only, or also Windows desktops and phones for computer-use agents that have to drive GUI apps?
- Observability. Per-sandbox logs and metrics you can attribute to a tenant, and an audit trail of what the agent ran.
- Billing unit. Per second of running time, per sandbox that exists, or per seat, and what an idle or sleeping sandbox costs. Take prices from the provider's current pricing page on the day you compare; see billing and metering per-user agents and unit economics of one agent per user.
- Compliance. If you handle health or personal data, ask for the signed documents (a HIPAA BAA, a DPA, data-residency terms) rather than a line on a features page.
Matching the sandbox to the workload
- One-off code execution (a code interpreter, data analysis on an upload): ephemeral microVM or gVisor sandboxes, created per task and deleted with their disk, with fast creation from a snapshot.
- One persistent agent per user: a persistent microVM per user that sleeps when idle and resumes with its disk and, ideally, its memory. Idle cost and wake time decide whether this is affordable; choosing infrastructure for per-user stateful agents goes through the numbers to gather.
- Long-running background agents: a persistent sandbox with no request timeout, plus a record of completed steps outside it. See why serverless execution boundaries break multi-step agent workflows.
- Computer-use agents: a full desktop VM (Linux or Windows) or a device the agent can see and click, not a headless container.
- Evals and RL at high volume: ephemeral sandboxes cloned from one prepared snapshot, so every run starts from the same state.
- Small trusted tools in your own backend: a hardened container or OS sandbox is often enough when the code is yours, not the model's.
Build it or use a hosted sandbox
Firecracker, Cloud Hypervisor, Kata Containers and gVisor are all open source, so a team can build its own sandbox layer. The hard parts are not booting a VM but everything around it: snapshot storage, scheduling sleeping sandboxes onto hosts, per-tenant networking, image updates across thousands of machines, and on-call for all of it. Why per-customer agent isolation belongs on a tenant-aware platform and agent fleet management across thousands of tenants lay out that work.
Whichever way you go, verify claims yourself: read the isolation section of the provider's documentation, run your own cold-start and resume timings, and try your heaviest real task in a trial sandbox before signing anything.
Common questions
Is a Docker container an AI agent sandbox?
It isolates processes, but every container on a host shares that host's kernel. For your own code that is often fine; for code a model writes on behalf of many customers, most teams add a stronger boundary such as gVisor or a microVM.
Does the sandbox run the model?
Usually not. The model is called over an API or served elsewhere; the sandbox runs what the model decides to do: commands, code, browsers and files. That is why sandboxes rarely need GPUs.
Should each user get their own sandbox?
If the agent keeps files, credentials or sessions for that user, yes: one sandbox per user keeps one user's state out of another's reach. Per-user agent architecture in multi-tenant SaaS explains the pattern.
How fast should a sandbox start?
Fast enough that users do not wait on it, which depends on your product. Restoring from a snapshot is usually much quicker than a cold boot. Measure both on the provider you are evaluating instead of relying on published figures.



