Sub topic 13
Hybrid approaches: microVMs and sandboxed runtimes
This chapter assumes you know what a kernel is, how namespaces and cgroups isolate a container, and why a container shares the host kernel while a VM does not. Earlier chapters covered both. Here we look at designs that sit between the two.
The problem hybrids solve
A container starts fast but exposes the host kernel to the workload. A system call from a container goes straight to the host kernel, so a kernel bug can become an escape. A traditional VM gives a much stronger boundary, but it boots a full guest operating system and emulates a lot of hardware.
Some workloads need both. A cloud provider that runs code from many customers wants VM-grade isolation with container-like startup and density. Hybrid approaches try to deliver that.
Two strategies
There are two common ways to close the gap.
- Make the VM lighter. Keep the hardware boundary, but remove everything a VM does not need. This is the microVM.
- Make the container sturdier. Keep the container workflow, but put a second layer between the workload and the host kernel. This is the sandboxed runtime.
MicroVMs
A microVM is a virtual machine with a stripped-down virtual machine monitor (VMM) and a minimal set of emulated devices. It usually has no graphics, no USB, and no legacy BIOS devices. It boots a small guest kernel directly, often in well under a second.
Firecracker is the best-known example. AWS built it for Lambda and Fargate. It uses the Linux KVM interface and exposes only a handful of virtual devices, such as a network card and a block device. Cloud Hypervisor and QEMU's microvm machine type follow similar ideas.
The workload gets its own kernel, so a guest kernel bug does not hand the attacker the host kernel. The attacker must also break out through the VMM, which has a far smaller attack surface than a full hypervisor with broad device emulation.
Kata Containers wraps this idea in the container workflow. It runs each pod or container inside a lightweight VM, but it speaks the standard OCI runtime interface, so Docker or Kubernetes can use it.
Sandboxed runtimes
gVisor takes the second route. It runs a kernel written in a memory-safe language (Go) in user space. When the app makes a system call, gVisor's kernel, called the Sentry, handles it. The Sentry itself makes only a small, filtered set of calls to the host kernel.
The host kernel's exposed surface shrinks, but there is no hardware virtualization boundary. Compatibility is the cost: gVisor implements a large share of Linux system calls but not all of them. Syscall-heavy workloads also run slower because each call takes a longer path.
Trade-offs
| Property | Container | Sandboxed runtime | MicroVM | Traditional VM |
|---|---|---|---|---|
| Kernel the app talks to | Host | User-space kernel | Own guest kernel | Own guest kernel |
| Startup | Milliseconds | Milliseconds to low seconds | Around a second or less | Seconds to minutes |
| Memory overhead | Very low | Low | Low to moderate | Moderate to high |
| Compatibility | Full Linux | Partial syscall coverage | Full Linux guest | Any guest OS |
| Isolation strength | Weakest | Medium | Strong | Strong |
Exact numbers depend on the implementation and configuration, so treat the table as relative.
Using a sandboxed runtime with Docker
Once a runtime is installed and registered, you choose it per container. This example assumes gVisor's runsc is registered with Docker.
docker run --rm --runtime=runsc alpine dmesgOutput differs from a normal container because the kernel the app sees is gVisor's, not the host's. The image and command are unchanged. Only the runtime differs, which is the point of the OCI standards.
When to reach for a hybrid
- You run untrusted or multi-tenant code, such as user-submitted functions or CI jobs from many users.
- You want container images and orchestration, but your threat model rejects a shared kernel.
- You need very high density and fast startup, which rules out full VMs.
If all workloads are your own and trusted, plain containers are usually enough.
Exercise
A platform runs customer-submitted code in short-lived jobs. Startup must be under a second, and a kernel exploit in one job must not expose the host kernel. Which would you pick, a plain container, a gVisor sandbox, or a Firecracker microVM, and what is the main trade-off versus the others?
Show answer
A Firecracker microVM (or Kata Containers using a microVM) fits best. Each job gets its own guest kernel behind a hardware virtualization boundary, and startup stays near a second or less. The trade-off is somewhat higher memory overhead and more operational setup than a plain container. A plain container fails the kernel-exposure requirement. gVisor reduces host kernel exposure but has no hardware boundary and may not support every syscall the jobs need.