kosa8 / Guides / MicroVM vs container
Isolation explained · Updated 2026-11-29
MicroVM vs container isolation for LLM code execution
For LLM-generated code that nobody has reviewed, a microVM is the stronger default. A container's processes make system calls straight into the host's kernel, so one kernel or container-runtime bug can be enough to reach the host. A microVM gives the code its own guest kernel behind hardware virtualization, so an escape needs a guest-kernel bug and then a hypervisor or device bug. Containers stay a sound choice for reviewed code on a patched host, gVisor sits between the two, and the start-up gap has narrowed: a small microVM boots in a fraction of a second and restores from a snapshot in tens of milliseconds.
01How each one isolates code
A container is a group of ordinary host processes with a restricted view. Namespaces give it its own process tree, mounts, network and user IDs. Cgroups cap its CPU, memory and process count. Dropped capabilities and a seccomp filter remove privileged operations and some system calls. Everything the code does is still handled by the host's own kernel.
A microVM is a virtual machine cut down to the minimum: a small virtual machine monitor (VMM) such as Firecracker or Cloud Hypervisor on Linux's KVM, a handful of virtio devices and a guest Linux kernel. The code makes its system calls to the guest kernel. The guest reaches the host only through the CPU's virtualization boundary and the VMM's small device model. Kata Containers puts the same idea behind container interfaces, so each container or pod gets a lightweight VM of its own.
gVisor is neither. It is an application kernel written in Go that runs in user space, intercepts a container's system calls and serves most of them itself, making a narrower set of calls to the host kernel.
02Side by side
| Property | Container (runc) | Container under gVisor | MicroVM | Full VM |
|---|---|---|---|---|
| What handles the code's system calls | The host kernel, shared | gVisor's user-space kernel | Its own guest kernel | Its own guest kernel |
| Boundary to the host | Namespaces, cgroups, capabilities, seccomp | gVisor, plus a narrow interface to the host kernel | Hardware virtualization and a minimal device model | Hardware virtualization and a full device model |
| Bugs an escape needs | One, in the host kernel or the runtime | One in gVisor, then one in the host calls it can make | One in the guest kernel, then one in the VMM or a device | One in the guest kernel, then one in the hypervisor or a device |
| Linux compatibility | Full | Most system calls, not all | Full | Full |
| Start-up | Milliseconds | Milliseconds | A fraction of a second to boot; tens of milliseconds from a snapshot | Seconds or more |
| Memory per instance | Smallest | Small | A guest kernel plus the RAM you give it | Largest |
| Running a container engine inside | Needs extra privileges (Docker-in-Docker) | Possible, with limits | Yes, on the guest kernel | Yes |
| Snapshot of a running instance | Limited (CRIU) | Checkpoint and restore supported | Memory and device state, fast | Supported, usually slower |
| What the host needs | Any Linux kernel | Linux | KVM on Linux, or a hypervisor framework such as Apple's on a Mac | A hypervisor |
Run uname -r in a container on a Linux host and you get the host's kernel release, because it is the host's kernel. Run it in a microVM and you get the guest's.
03What escapes have actually happened
Two classes of container escape recur in the CVE record. Container runtime flaws: CVE-2019-5736 let a root process in a container overwrite the host's runc binary, and CVE-2024-21626 leaked a file descriptor that gave a container process a working directory on the host filesystem. Kernel bugs reachable from inside a container: CVE-2022-0185, CVE-2022-0492 and CVE-2022-0847 (Dirty Pipe). All are patched. The point is the pattern: on a shared kernel, one bug is enough.
VMs are not immune. CVE-2015-3456 (VENOM) was a flaw in QEMU's virtual floppy controller that could let a guest crash the VM or possibly run code on the host. MicroVM designs answer by shrinking that surface: Firecracker exposes a minimal device model and runs behind a jailer as a second line of defence. The difference is the number of independent bugs an attacker has to chain.
For LLM-generated code this matters more than for a typical service. The code's whole job is to run things it just wrote or downloaded, and a prompt injection in a README or a package can steer what that is.
04Start-up, density and I/O
The old reason to avoid VMs for short tasks was boot time, and it has mostly gone. Firecracker documents boot in under 125 ms and under 5 MiB of memory overhead per VM. Snapshots go further: a prepared VM restores instead of booting, and a pool of paused VMs turns a create into a resume.
In kosa8's own benchmark (3 Nov 2026, one AMD Ryzen 7 7700 server, sandboxes of 1 vCPU and 256 MiB on Cloud Hypervisor), a cold boot took 287 ms at the median, a restore from snapshot 74 ms and a create from the warm pool 1.9 ms. A hundred forks of one running sandbox used 26 GB of host RAM, about 260 MB each, and memory rather than CPU set how many fit on the host. The benchmark study has the full method and dataset. These are one machine, not a guarantee.
I/O is where VMs still cost something. On a Mac, kosa8's baseline measured a shared folder mounted over virtiofs at 30% of host-native write throughput, and the VM's own block device at 52%. Heavy builds and data work run faster on the VM's own disk than through a shared folder. CPU-bound code runs at close to native speed in both containers and VMs.
05How to decide
- Choose a container when the code is yours or reviewed, the host kernel and runtime are patched, and the container holds no secrets worth stealing.
- Choose gVisor when you want a smaller host-kernel surface while keeping container tooling, and your workloads do not depend on system calls gVisor lacks.
- Choose a microVM when the code is generated and unreviewed, installs packages on its own, runs unattended, or runs next to other tenants or next to things you care about, such as your home directory, SSH keys or cloud credentials.
- Choose a full VM for long-lived environments you rarely recreate, or when you need devices a microVM does not offer.
The boundary is only one layer. Whichever you choose, the network, secrets, quota and audit controls in How to safely run untrusted code generated by LLMs still apply, and a folder you mount in is writable from inside unless you mount it read-only.
06If you stay with containers
Harden every one: drop all capabilities, block privilege gain, run as a non-root user, make the root filesystem read-only, mount only the project and cut the network.
- Keep the default seccomp profile on. Never use
--privilegedorseccomp=unconfined. - Never mount the container runtime's socket.
- Patch the host kernel and the runtime promptly; container isolation is only as good as both.
- Use rootless mode or user namespaces where your workloads allow it.
07If you run microVMs yourself
- Expose the fewest devices you can, and run the VMM itself with least privilege (Firecracker's jailer applies chroot, namespaces, cgroups and a privilege drop).
- Patch the host kernel, KVM and the VMM; they are the second layer an attacker must break.
- Enforce network rules on the host, outside the guest. Rules inside the guest belong to whoever is root there.
- When you restore one snapshot into many VMs, give each clone fresh random state, identifiers and network identity.
- Do not share writable host folders, and never reuse a VM across tenants.
08One way to do it: kosa8
kosa8 is Zero Trust cybersecurity infrastructure for AI agents. It gives each sandbox its own microVM and kernel: Apple's Virtualization framework on an Apple silicon Mac and Cloud Hypervisor on KVM on x86-64 Linux, so the same model works on a laptop and on a server. Around the VM it adds the layers this page says you would otherwise build: an egress allow-list enforced on the host, keys kept outside the sandbox, approvals for risky steps, a hash-chained audit log, and checkpoint, rewind and fork of a running machine.
kosa8 sandbox create agent --egress deny kosa8 sandbox pull agent alpine:3.20 kosa8 sandbox run agent alpine:3.20 sh -c "uname -r" kosa8 sandbox rm agent
One distinction matters. kosa8 also serves a Docker-compatible API, and containers started through it run in one shared engine VM: a VM boundary from your machine, but ordinary container isolation from each other. For a microVM per workload, use kosa8 sandbox as above.
kosa8 limits what code can reach; it does not detect prompt injection. SOC 2 Type II is in progress; there is no SOC 2 report and no external penetration test yet.
Try a microVM free Benchmark study
Try free with no account at kosa8.com/try. Starter is free with no card; plans from $29 a month.
09Questions
Is a microVM more secure than a container?
For untrusted code, yes, in the way that matters: escaping a microVM needs a bug in the guest kernel and then one in the hypervisor or its device model, while escaping a container needs one bug in the shared host kernel or the container runtime. Neither is unbreakable, so keep hosts patched and keep the network and secrets controls either way.
Is gVisor a microVM?
No. gVisor is an application kernel that runs in user space and handles a container's system calls itself. It shrinks the host-kernel surface without running a virtual machine, at the cost of slower system-call-heavy work and incomplete system-call coverage.
How much slower is a microVM to start than a container?
Less than it used to be. Firecracker documents boot in under 125 ms. Restoring a prepared microVM from a memory snapshot takes tens of milliseconds on current hardware (74 ms at the median in kosa8's own benchmark), and a pool of paused microVMs turns a create into a resume.
Can I run Docker inside a microVM?
Yes. A microVM has its own kernel, so a container engine runs inside it normally, without the extra privileges that running Docker inside a container needs.
When is a container enough for LLM-generated code?
When the code is yours or reviewed, the host kernel and runtime are patched, the container runs as a non-root user with capabilities dropped and no new privileges, its network is closed or allow-listed, and it holds no secrets worth stealing.
10Sources and further reading
Updated 2026-11-29