all posts

Best Secure Sandboxes for LLM Agents in 2026

Ajay Kumar··9 min read

For an LLM agent that runs the code and tool calls it generates, the sandbox is not a supporting detail — it is the security product. Everything else you build assumes the model can only do damage inside a box you control, and the strength of that box is what decides whether a prompt-injected 'helpfully clean up disk space' turns into a bad afternoon or a breach. So this roundup ranks options through one lens above all others: the strength of the security boundary. The isolation model — hardware VM versus shared-kernel container versus user-space kernel versus WASM — is the thing you're actually buying. Then comes the operational hygiene that keeps that boundary honest in production: per-run ephemerality, egress control, secret handling, and enough boot speed that security doesn't cost you the UX. As always here, real criteria over a leaderboard, and specific numbers only where I can stand behind them.

The field covered: the isolation tiers first (Firecracker microVMs, gVisor, Kata, plain containers, WASM), then a qualitative pass over platforms — PandaStack (our project, an open-source Firecracker-microVM platform, positioned honestly as the strong-isolation pick), plus E2B, Modal, Daytona, Vercel Sandbox, Fly, and Northflank named in general terms. The broader by-criteria roundups live at /blog/best-ai-agent-sandboxes-2026 and /blog/best-code-execution-sandboxes; here the organizing question is narrower and sharper: how strong is the wall, and does the operational story keep it strong.

Disclosure: I'm the founder of PandaStack, so read this as a vendor's roundup and weight it accordingly. I keep it honest the only way that works — I cite specific numbers (latency, fork times) only for PandaStack, and I describe every other tool in general, qualitative terms drawn from its own docs rather than asserting competitor internals as fact. Security posture is exactly the thing you must not take on a blog's word — isolation backends get swapped, egress defaults change, and 'secure' is a marketing word until you read the threat model. For anything load-bearing, verify against each vendor's own current security docs before you commit.

For agent code, the isolation model is the product

When an agent runs code it wrote itself, you are running untrusted code by definition — the model is not an authority you can trust with your host, and a prompt injection can turn a friendly assistant into an attacker's remote shell. So the first and largest question is what stands between the guest and your machine. There are four broad tiers, in increasing order of boundary strength, and the gap between them is the whole ballgame. The deeper walkthrough is /blog/code-isolation-hierarchy; here's the security-first version.

  • Plain containers (namespaces + cgroups + seccomp) — isolation: shared host kernel; a single kernel-level escape is a full host compromise. best for: trusted first-party code, not arbitrary agent output. A container is a polite suggestion to the kernel, and model-written code doesn't do polite (/blog/why-docker-is-not-a-sandbox).
  • WASM (WebAssembly runtime) — isolation: capability-scoped, in-process; the guest can only touch what you explicitly grant, and starts in milliseconds. best for: narrow, pure, compute-only tools (a math evaluator, a sanctioned transform) — a poor fit when the agent needs a full Linux userland.
  • gVisor (user-space kernel) — isolation: a second kernel in user space intercepts guest syscalls so most never reach the host kernel, shrinking attack surface without a full VM. best for: a meaningful middle rung above a container, with workload-dependent syscall compatibility.
  • Kata Containers — isolation: VM-grade, with a container/Kubernetes UX; runs atop Firecracker, Cloud Hypervisor, or QEMU. best for: teams who want microVM isolation but live in a Kubernetes/OCI workflow.
  • Firecracker microVMs — isolation: hardware-virtualized; each sandbox gets its own guest kernel, isolated by KVM, and guest code never touches the host kernel directly. best for: arbitrary untrusted agent code — the right default when you can't trust what the model emits (/blog/firecracker-vs-docker, /blog/what-is-a-microvm).

The honest spine: for arbitrary agent code, microVM-class isolation (Firecracker or Kata) clears the bar because the exposed surface is a small, better-audited VMM rather than the entire Linux syscall interface a container shares. gVisor is a genuine step up from a plain container and a reasonable middle bet. WASM is excellent but only for the narrow slice it covers. A shared-kernel container, on its own, is not a security boundary you should put arbitrary model output behind — it's a resource-partitioning tool that marketing sometimes dresses up as a sandbox.

Don't over-read 'microVM' as 'immune.' Hardware virtualization is a far stronger boundary than a shared kernel, and a minimal VMM's attack surface is much smaller and better-audited than the full Linux syscall interface — but it is not zero. VMMs have had bugs; KVM has had bugs. The honest claim is 'dramatically smaller, better-audited attack surface,' not 'unbreakable.' Defense in depth — a privilege-dropping jailer, seccomp, per-sandbox egress controls, per-run ephemerality — is what keeps the boundary strong in the real world. We cover that layering in /blog/secure-code-execution-for-ai-agents.

The operational security that keeps the boundary honest

A strong isolation tier is necessary but not sufficient. Most real-world incidents with agent sandboxes aren't hypervisor escapes — they're boring operational failures: a sandbox that outlived its run and got reused with someone else's data still in it, an unrestricted network egress that let injected code POST your environment variables to an attacker's server, or a long-lived API key baked into the image where the model could read it. Four operational properties matter as much as the wall itself.

  • Per-run ephemerality — a fresh, clean sandbox per run (or per turn) that is destroyed after, so nothing bleeds between tasks or tenants. Ephemerality is a security control, not just tidiness: a sandbox you never reuse can't leak the last run's state into this one.
  • Egress control — untrusted agent code should not have unfettered internet. The ability to allowlist or block network egress per sandbox is the single biggest lever against data exfiltration — it turns a contained tool into a contained tool that also can't phone home.
  • Secret hygiene — secrets should be injected narrowly and short-lived, never baked into a template the guest can read at leisure. If the model can cat a long-lived cloud credential, isolation bought you less than you think.
  • Boot latency — this is a security property in disguise. If a clean per-run sandbox is slow to create, teams quietly start reusing sandboxes to save latency, which erodes ephemerality. Fast create is what lets you stay disposable without paying a UX tax.

PandaStack (the strong-isolation pick)

PandaStack (our project) is an open-source, Apache-2.0 platform where every sandbox is a Firecracker microVM with its own guest kernel (5.10, Ubuntu 24.04 guest), isolated by KVM, running under a jailer that drops privileges and exposes only a minimal virtio device model (net, block, vsock). On the isolation axis it sits at the strong end — hardware-virtualized, guest code never touches the host kernel. On the operational axis it's built for per-run ephemerality specifically: boot is snapshot-restore on every create with no warm pool of idle VMs, so spinning up a fresh, clean microVM per turn is cheap rather than something you avoid. Where I'm allowed to be specific, because these are our own numbers: create lands at 179ms p50, roughly 203ms p99, with the restore step itself around 49ms; the only slow path is the first-ever spawn of a brand-new template, which cold-boots in about 3s to bake the snapshot. Networking is per-sandbox — its own Linux netns, veth pair, and tap from 16,384 pre-allocated /30 subnets per agent — which is where egress controls hang. Forking is first-class via copy-on-write (same-host 400–750ms, cross-host 1.2–3.5s), and a managed Postgres create runs 30–90s on the same substrate. It's self-hostable end-to-end on any Linux box with /dev/kvm, which matters when the reason you want strong isolation is that the data can't leave your infrastructure.

from pandastack import Sandbox

# A fresh microVM per run, destroyed after the TTL, so a crashed
# loop can't leak a sandbox and no run reuses another's state.
# Create is ~179ms p50 -- cheap enough to stay disposable.
sbx = Sandbox.create(template="agent", ttl_seconds=900)

# The model wrote this. Run it inside the KVM-isolated guest,
# where a `rm -rf /` scribbles on a disposable rootfs -- not
# on your host's shared kernel.
result = sbx.exec("python untrusted_from_model.py")
print(result.stdout, result.exit_code)

# When the run ends the microVM is gone. No warm pool means no
# stale sandbox waiting around with the last task's secrets in it.

The security argument in one snippet: hardware-isolated execution of code you didn't write, a disposable box per run so nothing carries over, and create cheap enough that staying disposable doesn't cost you latency. The SDK reads PANDASTACK_API_KEY (keys prefixed pds_) with a configurable base URL, so identical code targets the hosted offering or your self-hosted control plane — the same @pandastack/sdk exists for TypeScript, and a pandastack CLI over the same API. It's the right pick when strong isolation you can own end-to-end is the requirement; it's the wrong pick if you have no infra appetite and a hosted-only service with equivalent isolation would do.

  • Isolation model: hardware-virtualized Firecracker microVM, own guest kernel per sandbox, KVM-isolated, minimal VMM surface under a privilege-dropping jailer.
  • Best fit: teams for whom the reason to want strong isolation is that the code is untrusted and the data can't leave their infrastructure — an open-source Firecracker platform they self-host, with cheap per-run ephemerality and per-sandbox networking for egress control.

The rest of the field, through the security lens

The qualitative pass, ranked by isolation model with the same discipline throughout: specific numbers only for PandaStack, every other platform in general terms with a 'verify against their docs' caveat, and no invented internals. Isolation backends and egress defaults are exactly the details that move, so treat each line as a pointer to that vendor's current security docs, not a settled fact.

  • E2B — isolation: Firecracker microVMs per its own infra docs (hardware-virtualized, own guest kernel). best for: a mature, focused, hosted-first sandbox that clears the isolation bar with little to operate; Apache-2.0 core, also self-hostable. Verify current isolation and egress behavior in its docs. See /blog/pandastack-vs-e2b.
  • Vercel Sandbox — isolation: Firecracker microVMs (Vercel states this plainly and links the project). best for: teams on the Vercel AI SDK wanting strong isolation with near-zero integration tax; client SDK open source, runtime not, hosted-only. See /blog/pandastack-vs-vercel-sandbox.
  • Fly — isolation: Firecracker-based microVMs per Fly's own platform docs; persistent volumes and scale-to-zero. best for: durable, long-lived stateful agent environments rather than disposable per-run creates — weigh persistence against ephemerality for your threat model. See /blog/pandastack-vs-fly-sprites.
  • Northflank — isolation: a per-workload choice of Kata (via Cloud Hypervisor), Firecracker, or gVisor per its docs; BYOC available. best for: a unified managed platform where you pick the isolation tier per workload and may want it in your own cloud. See /blog/pandastack-vs-northflank.
  • Modal — isolation: gVisor user-space kernel per its own security docs — syscall interception, a meaningful middle rung, not a hardware-virtualized VM. best for: scale-out AI/ML compute where the sandbox is one primitive among many and the gVisor trade is acceptable; hosted-only. See /blog/pandastack-vs-modal.
  • Daytona — isolation: a dedicated-kernel, VM-like model per its docs, without (in what I've read) naming a hypervisor — so I won't name one. best for: a development-environment-flavored workspace model; AGPL-3.0, managed/self-host/hybrid. Verify isolation details in its docs. See /blog/pandastack-vs-daytona.

How to choose

Start from your threat model, not a feature matrix. The single most important question is what the sandbox is running: if it's arbitrary, model-generated code with any path to prompt injection, you want microVM-class isolation (Firecracker or Kata) and you should treat a plain shared-kernel container as disqualified for that job. If it's narrow, pure, compute-only tool calls, a WASM runtime may be both safer to reason about and dramatically faster. gVisor is the reasonable answer when you want more than a container but a full VM is more than the workload warrants and you've checked the syscall compatibility. Once the isolation tier is settled, the serious options largely agree there — so decide the rest on the operational security properties: can you get a fresh sandbox per run cheaply enough to actually stay ephemeral, can you control egress per sandbox, can you keep secrets short-lived, and — if the data can't leave your walls — can you self-host it. Shortlist two, and prove the boundary before you commit.

A security checklist for agent sandboxes

Before you put an LLM agent in front of real users or real data, walk this list against your chosen sandbox. Most of it is operational, because most incidents are.

  1. Isolation tier matches the threat — arbitrary agent code sits behind a hardware VM (or at least gVisor), never a bare shared-kernel container. Read the vendor's actual threat model, not the tagline.
  2. Per-run ephemerality — a clean sandbox per run, destroyed after, with no silent reuse. Confirm nothing (files, processes, env) survives across runs or tenants.
  3. Egress is default-deny or allowlisted — untrusted code can't open arbitrary outbound connections. This is your primary defense against data exfiltration; verify it's enforced, not just documented.
  4. Secrets are narrow and short-lived — injected per run, scoped to what the task needs, never a long-lived credential baked into the template where the model can read it.
  5. Resource limits — CPU, memory, disk, and process caps so model-generated code can't wedge the host or run up a bill via a fork bomb or a crypto miner.
  6. Auditability — you can see what a sandbox executed and reached, so an incident is investigable after the fact.
  7. Defense in depth — the isolation boundary is backed by a privilege-dropping jailer and seccomp, so a single bug isn't a single point of failure.
  8. Boot latency you can live with — fast enough that staying ephemeral is the easy path, because the moment clean creates feel slow, teams start reusing sandboxes and quietly break the model.
Don't pick from this post — or any roundup, including the ones written by the vendors themselves — on the strength of a description. Isolation backends get swapped, egress defaults change, licenses shift, and 'secure' covers a wide range of real behavior. Pull every security claim (isolation tier, egress model, secret handling, per-run teardown) live from each vendor's own current docs and date it. Then build a one-hour spike against your top two: run genuinely hostile code, confirm it can't reach the host or the open internet, verify the sandbox is actually gone afterward, and check that a leaked secret would have been short-lived. An afternoon of adversarial testing settles more than a week of reading security pages.

The bottom line

There is no single most secure sandbox for every LLM agent — there's a best one for your threat model. But the ranking principle is clear: for arbitrary model-generated code, isolation strength is the product, and hardware-virtualized microVMs (Firecracker, Kata) are the correct foundation, with gVisor a reasonable middle and WASM excellent for the narrow slice it fits. A shared-kernel container, on its own, is not the answer for untrusted agent output. Then the operational security — per-run ephemerality, egress control, secret hygiene, and boot latency fast enough that you actually stay disposable — is what keeps that boundary honest in production. PandaStack's bet, for the record, is an Apache-2.0 Firecracker core where every create is a fresh KVM-isolated microVM (179ms p50, no warm pool), with per-sandbox networking for egress control, that you run end-to-end on your own hardware. If strong, ownable isolation matches your threat model, put it up against the field and keep us honest — adversarially.

Frequently asked questions

What's the most secure sandbox for AI agents?

For arbitrary, model-generated code there's no universal winner, but the ranking principle is clear: isolation strength is the product, and hardware-virtualized microVMs are the strongest practical boundary. E2B, Vercel Sandbox, and PandaStack run Firecracker microVMs (own guest kernel, KVM isolation) per their own docs; Fly is Firecracker-based per Fly's docs; Northflank lets you pick Kata, Firecracker, or gVisor per workload; and Modal uses gVisor per its security docs — a meaningful middle rung, not a full VM. A plain shared-kernel container is not a security boundary for untrusted agent output. But isolation is necessary, not sufficient: also weigh per-run ephemerality, egress control, secret hygiene, and boot latency, because most real incidents are operational, not hypervisor escapes. Verify each vendor's isolation and egress model in its own current docs, then test adversarially before you commit.

Is a Docker container enough to run LLM-generated code?

Generally no, not for arbitrary agent output. Every container shares the one host kernel, so a single kernel-level escape is a full host compromise — a container is a polite suggestion to the kernel, and model-written code (especially prompt-injected code) doesn't do polite. Namespaces, cgroups, and seccomp are real hardening for trusted first-party workloads, but they don't give you a separate kernel, which is the property you want when running code you can't trust. For untrusted agent code, use hardware-virtualized microVMs (Firecracker or Kata), where each run gets its own guest kernel isolated by KVM, or at least gVisor's user-space kernel as a middle rung. If you must use containers, treat them as one layer in defense-in-depth (seccomp, dropped capabilities, egress control, per-run teardown), never as the whole boundary.

How do I stop data exfiltration from an agent sandbox?

Control network egress per sandbox — this is the single biggest lever. Untrusted agent code should not be able to open arbitrary outbound connections, because that's exactly the path a prompt-injected instruction uses to POST your secrets to an attacker's server. Default-deny egress and allowlist only the hosts the task genuinely needs; verify it's enforced, not just documented. Layer that with secret hygiene (inject short-lived, narrowly scoped credentials per run rather than baking long-lived keys into a template the model can read), per-run ephemerality (a fresh sandbox destroyed after each run, so nothing lingers to be exfiltrated later), and auditability (so you can see what a sandbox reached). Strong isolation contains the blast radius, but egress control is what stops contained code from phoning home.

Does a microVM sandbox mean my agent is fully secure?

No — a microVM is a dramatically stronger boundary than a shared kernel, but it isn't a guarantee. Hardware virtualization gives each sandbox its own guest kernel isolated by KVM, and a minimal VMM exposes a much smaller, better-audited attack surface than the full Linux syscall interface a container shares. But VMMs have had bugs and KVM has had bugs, so the honest claim is 'much smaller, better-audited attack surface,' not 'unbreakable.' Real security comes from defense in depth on top of the VM: a privilege-dropping jailer, seccomp, per-sandbox egress control, short-lived secrets, resource limits, and per-run ephemerality. The microVM is the foundation; the operational hygiene around it is what keeps the whole system secure in production.

Can I self-host a secure sandbox for LLM agents?

Yes — and self-hosting is often the point when the reason you want strong isolation is that the code is untrusted and the data can't leave your infrastructure. PandaStack's core is Apache-2.0 and runs end-to-end on your own Linux KVM hosts (control-plane API plus a per-host agent; sandboxes execute on your infrastructure; the same binaries power a hosted offering via a configurable base URL). E2B (Apache-2.0) and Daytona (AGPL-3.0; managed/self-host/hybrid) are also self-hostable, as are the building blocks Firecracker, Kata, and gVisor. By contrast, Modal and Vercel Sandbox are hosted-only, and Northflank's self-host is BYOC (a proprietary control plane in your cloud). The trade-off is operational weight — KVM hosts, an agent fleet, networking, egress policy, and storage you now own — so verify each candidate's current license and isolation model in its own repo first.

Run code in a microVM in one API call.

49ms p50 cold start. Fork, snapshot, and scale to zero.

Start free
Written by Ajay Kumar, Founder, PandaStack.