Sub topic 14
Choosing the right isolation level
This chapter assumes you have read the earlier chapters on the isolation spectrum, container hardening, gVisor, and microVMs. You should know what a shared kernel means and how to run a hardened docker run command.
The decision in one sentence
Pick the weakest boundary that still contains the worst thing the agent could do, given who controls its input. Stronger boundaries cost more in startup time, memory, and setup effort. The aim is to match the boundary to the threat.
What each level shares with the host
| Level | Shares with host | Typical startup | Main weakness |
|---|---|---|---|
| Hardened container | Full host kernel | Under 1 second | A kernel bug or a misconfigured mount can allow escape |
| gVisor (`runsc`) | Host kernel, but only through a small set of calls made by a user-space kernel | 1 second or less | Some syscalls and features are unsupported, and I/O is slower |
| microVM | Only the hypervisor and CPU | About 1 to 3 seconds | Needs KVM, a guest image, and more tooling |
| Full VM | Only the hypervisor and CPU | 10 seconds or more | Heavy to run, and slow to create and discard |
The startup times are rough figures. Measure them on your own hardware.
Questions that drive the choice
Ask these questions in order.
- Who writes the input the agent reads? If only you do, and the repository is yours, the risk is mostly agent mistakes. If the agent reads issues, web pages, or third-party code, prompt injection is possible. An attacker can then steer the agent without touching your machine.
- Is the code trusted? Running your own test suite is different from running a dependency you have never audited.
- Is the host shared? On a laptop that holds only your own work, a container escape is bad. On a CI runner or a multi-tenant service, it exposes other people's data.
- What is reachable if the boundary fails? Credentials, other projects, and internal networks raise the stakes.
Typical matches
- Personal laptop, your own repository, you review changes: a hardened container with
--network noneor an internal network is usually enough. - Agent reads external content or installs unknown packages: use gVisor at minimum. Switching is one flag, so the cost is low.
docker run --rm -it --runtime=runsc --network none python:3.12-slim bash- CI runners, hosted agent services, or running code from strangers: use a microVM per task. A guest kernel gives a separate boundary, so a kernel exploit in the guest does not reach the host kernel.
Gotchas
Isolation level and configuration are separate things. A microVM that mounts your home directory and holds your cloud keys leaks them just as easily as a container does. Apply the filesystem, network, and secrets controls from earlier chapters at every level.
Strong isolation can also give false confidence. gVisor and microVMs reduce kernel attack surface, but they do not stop an agent from sending data out over an allowed network path.
Exercise
An agent service runs tasks submitted by many customers on shared servers. Each task installs arbitrary packages and executes them. Which isolation level fits best, and why is a hardened container alone not enough?
Show answer
Use a microVM per task. The input and code are untrusted and the host is shared, so a container escape through the shared kernel would expose other customers. A microVM puts a guest kernel between the task and the host. gVisor is an acceptable lighter option if startup time and density matter more.