Containers or microVMs for AI agent sandboxes

Containers share a kernel, microVMs don't, and coding agents need more than either gives by default. Isolation, Docker inside, state and network for agent sandboxes.

SandboxesSecurityExplainer

An agent that writes and runs code needs somewhere to run it. The choice of "somewhere" decides how much damage a bad command can do, whether the agent can use Docker, and whether its work survives a pause. Here is how the options compare.

What a coding agent actually needs

A coding agent is not a function call. It behaves like a junior engineer with a terminal:

  • Root, or close to it. It installs packages, edits system config and starts services.
  • Docker. Half of real repositories need docker compose up before the tests will run.
  • Long sessions. A task can run for hours, then wait for a review, then carry on.
  • State. Installed dependencies, a warm build cache and a running database are expensive to rebuild.
  • A wall around it. It runs code from the internet that nobody has read.

Each sandbox type gets some of these cheaply and others not at all.

Containers

A container is a set of Linux namespaces and cgroups around a process. It is fast to start and cheap to pack densely, which is why it is everyone's first choice.

The catch is the shared kernel. Every container on a host talks to the same kernel, so a kernel bug is a path from one tenant to the next. That is acceptable for code you wrote. It is a harder call for code an agent pulled from a package registry a minute ago. Running Docker inside a container also needs either a privileged container or extra tooling, and a privileged container gives away much of the isolation you wanted.

Hardened containers

User-space kernels such as gVisor intercept system calls and answer many of them without touching the host kernel. That shrinks the shared surface a lot. The cost is compatibility and speed on syscall-heavy work: some programs behave differently, and nested Docker is awkward.

MicroVMs

A microVM is a small virtual machine with its own kernel, run by a lean virtual machine monitor on KVM. Firecracker and Cloud Hypervisor are the best-known. The guest's kernel is its own, so a kernel bug inside the guest stays inside the guest. Docker runs inside as it would on any Linux machine, with no privileged tricks.

The old objection to VMs was start time and memory overhead. Lean monitors cut most of that, and the trade now favours VMs for untrusted code.

A side-by-side view

ContainerHardened containerMicroVM
KernelShared with hostShared, filteredIts own
Docker insideNeeds privilegesAwkwardWorks as normal
Root insideRoot in a namespaceRoot in a namespaceRoot in that VM only
Start timeFastestFastSeconds
Pause with memoryRareRareNative (snapshot and restore)

Where isolation stops being enough

Picking a VM solves "can a bad command escape the box". It does not solve "what can a bad command do from inside the box". Two things matter here as much as the boundary:

  • Network. Can the sandbox reach your cloud metadata server, your private network or an SMTP port? It shouldn't.
  • Secrets. Any key the agent can read, it can send. Isolation does nothing about that.

We covered the second in detail in Keep API keys out of your AI agent's sandbox.

What Zode chose

Each Zode sandbox is a microVM run by Cloud Hypervisor on KVM, with its own Linux kernel, disk and memory. Sandboxes don't share a kernel with each other or with the host. Every sandbox boots Ubuntu 24.04 with Docker and common toolchains already there.

Around that boundary:

  • The host drops SMTP ports, private address ranges, link-local addresses and the cloud metadata server for every sandbox.
  • Web traffic goes through a host proxy that records each connection's host and outcome, never bodies.
  • Secrets reach the VM as placeholders, swapped for real values only on the way to hosts you allow.
  • Stopping a sandbox hibernates it with memory and disk, so a long agent task can pause for free compute and resume mid-process.
  • A running sandbox can be forked, memory included, to try two approaches from one state.

The full isolation and network model is on the security page.

A rule of thumb

If you wrote the code, a container is fine. If an agent is about to run code it found, give it its own kernel, keep your keys out of its reach, and make sure it can't talk to anything you wouldn't let a stranger talk to.

Try it: install the CLI, or start free in the console.

$curl -fsSL https://zode.dev/install | sh