Coding agents write code and execute it, frequently with no human reading it first. An AI agent sandbox is the boundary that keeps a buggy script, a bad dependency or a prompt-injection attack from reaching the host. Three designs are common: ordinary containers, containers running under gVisor, and microVMs such as Firecracker. They differ in how much of the system the untrusted code can touch directly.
The slogan “VMs good, containers bad” flattens a more useful picture.
Start with the threat model
Assume the code is hostile even when the person launching it is not. Hostile code arrives through prompt injection in pages the agent reads, a compromised package, or a generated command that wipes something by accident. Firecracker’s design makes the same assumption and treats every guest vCPU thread as malicious from the first instruction.
The assets at stake are the host and its other tenants, the credentials the agent carries, internal services on your network, and your bill, since a runaway process can burn CPU, memory or disk.
gVisor sorts the attack surface into classes. The system API (calls, files, sockets) is where exploits are most common. The system ABI covers hardware and privileged behavior outside that API, and hypervisors have had flaws there too. Hardware side channels hit any code on a machine, and gVisor generally doesn’t defend against them. The Firecracker paper tells adopters to understand them and plan mitigations.
Containers share the host kernel
A container is a normal Linux process given a limited view of the machine. Namespaces isolate process IDs, mounts and networking. Cgroups cap resources. Docker removes most root capabilities by default, and a seccomp profile restricts system calls.
The host kernel enforces all of this. A kernel bug reachable through a permitted call gives container code the same path out as any other process.
For reviewed, in-house code, containers work well, with excellent compatibility and almost no overhead. Danger grows with distrust. A tight seccomp profile, reduced capabilities, read-only filesystems and user namespaces narrow the exposed surface, but gVisor’s documentation admits that writing a dependable policy for unknown applications is extremely difficult, if not impossible. A platform running strangers’ code is in exactly that position.
gVisor puts a kernel in user space
gVisor inserts its own kernel, a Go program called the Sentry, between the application and the host. The Sentry handles system calls, signals, memory and threads itself instead of forwarding them. It runs under a strict seccomp policy with a short list of host calls, and a separate process named the Gofer manages file access.
A platform catches the application’s calls. gVisor documents KVM, systrap and ptrace, and systrap took over from ptrace as the default in mid-2023. An attacker must therefore find a bug in the Sentry’s imitation of Linux and then break out of a Sentry that is itself confined.
The trade is compatibility and speed. gVisor implements a subset of the Linux syscall ABI, and io_uring is only partly supported. The project says most workloads run fine and cites Google Cloud Run and DigitalOcean App Platform. Agents are harder than web services, though, because they run package managers, compilers, test suites, headless browsers and sometimes Docker. Try your actual toolchain.
Firecracker gives each run a microVM
A microVM boots its own guest kernel on virtual hardware, and KVM with CPU virtualization extensions enforces the wall. Firecracker keeps the device model tiny: VirtIO network and block devices, a serial console and a few legacy pieces. Less emulation code means less to attack.
Each microVM is one process. In production a jailer launches it in a chroot, with separate PID and network namespaces, dropped privileges and a seccomp-bpf filter. Firecracker’s README adds that security still depends on a well configured host.
The 2020 paper reports under 5MB of memory overhead, boot to application code in under 125ms, and up to 150 microVMs created per second per host. Those figures use a minimal init and a single vCPU. The design document gives a slower number for a minimal kernel, one core and 128 MiB of RAM: 5 microVMs per host core per second.
The costs include a guest kernel to patch for each image, a VMM and host kernel with bugs of their own, and mandatory KVM on the host, which makes nested virtualization a performance problem. As of that paper, Firecracker skips legacy devices and PCI and can’t boot arbitrary kernels.
What no boundary solves
- Egress: Firecracker doesn’t filter network traffic, so filter at the host and decide what the box may call.
- Secrets: a key in the environment is readable by hostile code.
- Permissions: a valid token can do real harm within its scope, so add approvals and an audit trail.
- Resources: cap CPU, memory, disk and time for every run.
- State: reuse leaves residue, so destroy the box after each run.
Picking one
Choose containers for reviewed code, with a non-root user and a tight profile. Choose gVisor if you want more than a container offers but can’t count on hardware virtualization, and your tools fit its syscall support. Choose microVMs for varied, fully untrusted code when you can supply KVM. Many teams consider them the safer default for arbitrary agent-written code.
The layers also combine. Firecracker’s jailer wraps the VMM in container-style limits, and gVisor stacks seccomp beneath the Sentry. gVisor’s FAQ warns that using virtualization hardware doesn’t by itself make a system more or less secure.
What to do before you commit
Run your real toolchain through each option, then add egress rules, secret handling and approval steps around the one you pick.
Source: Sandscale