Sub topic 2
From processes to VMs: what each boundary shares with the host
This chapter assumes you are comfortable with the Linux command line, know basic Docker usage, and understand Linux users and file permissions. Here you will compare four isolation boundaries by one question: what does the sandboxed code still share with the host?
The question to ask of any boundary
Every sandbox sits between untrusted code (here, commands your coding agent runs) and the host. The useful way to compare them is to list what crosses that boundary. The more the two sides share, the larger the attack surface. The most important shared thing is the kernel, because kernel bugs let code escape every other restriction.
Four boundaries
Plain process
A process run as your user shares almost everything with the host: the kernel, your filesystem, your network, your user ID, and your environment variables. An agent running this way can read ~/.ssh and every token in your shell environment. File permissions are the only barrier.
Container
A container is a process with a restricted view of the host. It gets its own filesystem view, process list, and network stack through namespaces, plus limits from cgroups. It still shares the host kernel. Every system call the container makes is handled by the same kernel that runs your host. A kernel vulnerability, or a misconfiguration such as a mounted Docker socket or the --privileged flag, can lead to escape.
User-space kernel (gVisor)
gVisor places a second kernel, written in a memory-safe language and running in user space, between the container and the host. The container's system calls go to that kernel first. Only a small, filtered set of calls reaches the host kernel. The shared surface shrinks a lot, at a cost in performance and some system call compatibility.
Virtual machine and microVM
A virtual machine runs its own guest kernel on virtualized hardware. The host and guest share only the hypervisor and the hardware virtualization interface. A microVM (such as Firecracker) is a VM stripped to a minimal device set, so it starts quickly and exposes less code to the guest.
Comparison
| Boundary | Kernel | Filesystem | Network | Relative strength |
|---|---|---|---|---|
| Process | Host | Host, by permissions | Host | Weakest |
| Container | Host | Image plus chosen mounts | Own or none | Moderate |
| gVisor | User-space kernel, filtered calls to host | Image plus chosen mounts | Own or none | Strong |
| VM / microVM | Separate guest kernel | Virtual disk | Virtual NIC | Strongest |
Seeing the shared kernel yourself
Compare the kernel version inside a container with the host's. They match because there is only one kernel.
uname -r
docker run --rm python:3.12-slim uname -rWith gVisor installed and registered with Docker, the second command reports a different version, because the container talks to gVisor's kernel.
docker run --rm --runtime=runsc python:3.12-slim uname -rTrade-offs
Stronger boundaries cost more. VMs add startup time and memory overhead. gVisor slows system-call-heavy work such as large builds and may not support every call. Containers are fast and familiar, but their isolation depends on correct configuration. The next chapters show how to harden a container, and a later chapter returns to choosing among these levels.
Exercise
An agent runs in a standard Docker container with no extra options. A vulnerability exists in the host's Linux kernel system call handling. Why is this container more exposed than a microVM on the same host, and which boundary reduces the exposure without a full VM?
Show answer
The container shares the host kernel, so a malicious system call from the agent reaches the vulnerable code directly. A microVM runs a separate guest kernel, so the same call hits the guest kernel instead, and the attacker must also escape the hypervisor. gVisor reduces the exposure without a full VM, because it handles most system calls in a user-space kernel and forwards only a small filtered set to the host kernel.
Exercise
Run uname -r on the host and inside a plain python:3.12-slim container. What do you expect to see, and what does the result tell you about the isolation?
Show answer
Both commands print the same kernel version. This shows the container uses the host kernel, so kernel-level vulnerabilities affect the container and the host alike.