What Is gVisor? How It Works and gVisor vs Firecracker
Eli Mernit10 min read
gVisor is an open-source application kernel from Google that sits between a container and the host's Linux kernel. It is written in Go, runs in user space, and answers the container's system calls itself, so untrusted code never talks to the host kernel directly. It is not a virtual machine and not a syscall filter. Its runtime, runsc, plugs into Docker and Kubernetes in place of the default runtime.
How gVisor works
gVisor puts a second kernel, written in a memory-safe language, in front of the real one. When a process in the container makes a system call, gVisor catches it and handles it inside its own process. The project's architecture guide puts it plainly: gVisor never passes a system call through to the host.
Three parts do the work:
- The Sentry. This is the kernel-like component, a from-scratch Go implementation of the Linux system call interface, with its own memory management, file system layer and network stack. Your code runs against the Sentry, not against the host.
- The Gofer. A companion process that handles the file operations the Sentry isn't allowed to do on its own. When the container opens a file from the host, the request goes through the Gofer.
- runsc. The OCI-compliant runtime binary that starts and manages sandboxes. Docker, containerd and Kubernetes call
runscthe same way they callrunc.
The Sentry still needs the host for a few things, so it makes a small set of host system calls of its own. Those don't map one-to-one to what the sandboxed process asked for, and the Sentry runs under a seccomp filter that blocks calls such as exec and connect. An attacker has to break the Sentry first and then get past that filter to reach the host.
gVisor catches system calls through a platform, and you pick one per host:
| Platform | How it intercepts | Where it fits |
|---|---|---|
| systrap | seccomp-bpf traps on the host | The default. Best inside a cloud VM or on a host without virtualization support |
| KVM | Hardware virtualization extensions | Bare-metal hosts. It works under nested virtualization, but systrap usually performs better there |
| ptrace | The ptrace debugging interface | No longer supported and expected to be removed |
The KVM platform is a common source of confusion. It uses the CPU's virtualization extensions to switch between the application and the Sentry, but there is still no guest Linux kernel. gVisor on KVM is not a microVM.
gVisor vs Docker's default runtime (runc)
Docker's default runtime, runc, starts your process directly on the host kernel and limits what it can see with namespaces, cgroups and a seccomp profile. gVisor starts the same container image, but the process talks to the Sentry instead. The image, the Dockerfile and the orchestration stay the same. What changes is which kernel receives the system calls.
That difference matters when the code is untrusted. With runc, every container on a machine calls into one shared kernel, and a single kernel bug can let code reach the host and its neighbors. A seccomp profile narrows the list of allowed calls, but each allowed call still runs in the host kernel. gVisor reimplements the calls, so a bug in the host's implementation of one of them is not directly reachable from the container.
For code you wrote and reviewed, runc is fine. For code written by a model or submitted by a user, most teams want gVisor or a microVM. Our guide to what an AI sandbox is covers the rest of the controls that go around the runtime, such as network rules and time limits.
gVisor vs Firecracker
Firecracker and gVisor solve the same problem from opposite sides. Firecracker is a virtual machine monitor that boots a real guest Linux kernel behind hardware virtualization. gVisor reimplements the kernel's interface in a user-space process and boots no guest kernel. With Firecracker, the boundary is the CPU's virtualization hardware. With gVisor, the boundary is software.
| gVisor | Firecracker | |
|---|---|---|
| What it is | Application kernel in user space | Virtual machine monitor on KVM |
| Written in | Go | Rust |
| Built by | Amazon Web Services | |
| Kernel your code sees | The Sentry's Linux-like interface | A real guest Linux kernel |
| Isolation boundary | Software: the Sentry, plus seccomp around it | Hardware virtualization, plus the jailer process |
| Needs KVM on the host | No, on the default systrap platform | Yes |
| Linux compatibility | Most system calls, not all | Full, because it is Linux |
| Per-system-call cost | Higher than native | Native inside the guest |
| Start time and overhead | Starts in milliseconds; a small, mostly fixed memory overhead | Documents boot in 125 ms or less and about 5 MiB of VMM memory overhead per microVM |
| GPUs | NVIDIA GPUs through its nvproxy driver proxy | No GPU in its device list |
| Tooling | Drop-in OCI runtime for Docker and Kubernetes | Needs a VM orchestrator, or an integration such as Kata Containers or firecracker-containerd |
The Firecracker figures come from its specification. The boot time runs from the InstanceStart API call to the start of the guest's /sbin/init. The 5 MiB is the memory used by the VMM threads, measured on a microVM with 1 vCPU and 128 MiB of RAM, and the guest's own memory comes on top of it.
Neither one wins on every workload. gVisor is the easier fit when you already run containers and can't get KVM, which is the normal situation inside most cloud VMs. Firecracker gives code a real kernel, so anything that runs on Linux runs in the guest, and a kernel exploit inside the guest stays inside the guest. Our explainer on what a microVM is goes deeper on Firecracker, Cloud Hypervisor and Kata Containers.
What gVisor costs: compatibility and performance
gVisor's own documentation names the price: reduced application compatibility and higher overhead per system call. Both follow from the design. Reimplementing Linux means some of Linux is missing, and handling every call in a second kernel takes longer than handing it to the first.
- Compatibility. gVisor's compatibility table for x86-64 currently lists 352 Linux system calls. 292 have a full or partial implementation and 60 are unsupported. Common language runtimes, package managers and web servers work. Software that depends on unusual kernel interfaces, some
/procand/sysentries, or kernel modules can fail. - System-call-heavy work. The overhead is per call, so programs that make many small calls pay the most. gVisor's performance guide lists Redis and small-file web serving among the workloads most affected.
- CPU-bound work. gVisor doesn't emulate CPU instructions, so compute-heavy code runs at close to native speed. Model inference and numeric work fall here.
- File and network I/O. File operations that leave the sandbox go through the Gofer, which adds cost on workloads that open many files. The network stack is gVisor's own, and the project describes it as less CPU-efficient than Linux's.
- Side channels. gVisor does not protect against hardware side channels. It relies on the host and the platform for that.
The practical test is to run your real workload under runsc before you commit. A build that installs thousands of small files will show the overhead. A Python script that calls a model will not.
GPUs and checkpoint/restore in gVisor
gVisor supports NVIDIA GPUs through a component called nvproxy, enabled with the --nvproxy flag. It proxies the application's calls to the NVIDIA driver on the host, and it covers CUDA workloads such as PyTorch and LLM inference. This is one reason GPU sandbox platforms use gVisor: a microVM needs device passthrough to see a GPU, and Firecracker's device list has none.
Two limits come with it. nvproxy has to match the host's driver version exactly, so a driver that gVisor doesn't know will not start. And the gVisor docs say it is much less effective at containing vulnerabilities in the NVIDIA driver itself, so driver updates still matter.
gVisor can also checkpoint a running container to a set of files and restore it into a new container later, memory included. The commands are runsc checkpoint and runsc restore. Platforms use this to save an idle sandbox and bring it back with its processes intact. The restoring host must have every CPU feature of the host that took the checkpoint.
How to run a container with gVisor
On a Linux host with Docker, you install runsc, register it as a Docker runtime and pass --runtime=runsc when you start a container:
sudo runsc install
sudo systemctl restart docker
docker run --runtime=runsc --rm hello-worldTo confirm a container is running under gVisor, read the kernel log from inside it. gVisor prints its own boot messages, starting with Starting gVisor...:
docker run --runtime=runsc -it ubuntu dmesgDon't use that output as a security check. Any program can print the same lines.
On Kubernetes with containerd, you define a RuntimeClass whose handler is runsc and name it in the pod spec. These two manifests are the ones in gVisor's containerd quick start:
apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
handler: runsc
apiVersion: v1
kind: Pod
metadata:
name: nginx-gvisor
spec:
runtimeClassName: gvisor
containers:
- name: nginx
image: nginxEach node also needs runsc installed and containerd configured with the io.containerd.runsc.v1 runtime type. If you'd like to run this stack yourself for agent workloads, the guide to self-hosting a code execution sandbox walks through the options.
Who uses gVisor
gVisor runs in production at several large platforms, mostly where a provider has to run code it didn't write. The project's own user list includes:
- Google. GKE Sandbox, Cloud Run and App Engine use it.
- Anthropic. It contains code execution in claude.ai.
- OpenAI. It is used for some higher-risk tasks such as code execution.
- Modal. Its compute jobs are containerized with gVisor.
- Cloudflare, DigitalOcean and Snowflake. Pages builds, App Platform and the Snowpark execution sandbox.
- Beam. Sandboxes run as containers by default, and beta9, the open-source engine underneath, runs them under gVisor by default.
Cloud Run is a useful worked example because Google offers both models side by side. Its first-generation execution environment is based on gVisor, and Google describes it as having fast cold starts with emulation of most, but not all, operating system calls. The second generation is a microVM with full Linux compatibility and better CPU and network performance under sustained load, at the price of longer cold starts for some services. That is the gVisor trade-off in one product page.
If you're comparing hosted sandboxes built on these runtimes, see the Modal Sandbox alternatives and Docker Sandbox alternatives guides.
When to use gVisor and when to use a microVM
Use gVisor when you want more isolation than a plain container and want to keep container tooling, density and start times. Use a microVM when the code needs a real kernel or you want a hardware boundary between tenants.
gVisor fits when:
- The host can't expose KVM, as inside most cloud VMs.
- The workload needs a GPU.
- Tasks are short, start often and mostly compute: running generated code, tests, data analysis.
- You already run Kubernetes or Docker and want to change one runtime setting.
A microVM fits when:
- The code needs Docker, systemd, kernel modules or other parts of Linux that gVisor doesn't implement.
- The workload makes heavy use of system calls or the file system.
- Your threat model calls for a hardware-enforced boundary and a separate kernel per tenant.
- An agent needs a long-lived machine with a durable disk.
Many platforms run both and route each workload to the runtime that suits it.
Running agent code on gVisor or a microVM without operating either
Operating gVisor yourself means keeping runsc, the platform choice and the NVIDIA driver versions in step across a fleet. A hosted sandbox hides that. On Beam, a sandbox runs on a container runtime by default, and beta9, the open-source engine underneath, sets gVisor with the systrap platform as the default runtime for its worker pool. Passing use_vm=True moves a CPU sandbox into a microVM with at least 1 vCPU and 1 GiB of memory.
The same code runs on either runtime. This example starts one sandbox of each kind and prints the kernel release each one reports:
from beam import Sandbox
for use_vm in (False, True):
sb = Sandbox(cpu=1, memory="1Gi", use_vm=use_vm, keep_warm_seconds=300).create()
try:
result = sb.process.run_code("import platform; print(platform.release())")
print("use_vm =", use_vm, "->", result.stdout)
finally:
sb.terminate()Sandboxes that need a GPU stay on the container runtime, and use_vm=True is for CPU work. For an agent that needs a persistent machine with systemd and Docker, a Beam VM is a CPU microVM with its own kernel and a durable root disk. The post on sandboxing AI-generated code shows the network and timeout controls that go around either runtime.
FAQ
Is gVisor a virtual machine?
No. gVisor is an application kernel that runs as a user-space process on the host. It boots no guest kernel and emulates no hardware. Its optional KVM platform uses virtualization extensions to intercept system calls, but that still doesn't make it a VM.
What is the difference between gVisor and Firecracker?
gVisor reimplements the Linux system call interface in a user-space process, so the boundary is software and no KVM is needed. Firecracker boots a real guest Linux kernel in a microVM, so the boundary is hardware virtualization and the host must expose KVM. gVisor keeps container tooling and supports NVIDIA GPUs; Firecracker gives full Linux compatibility.
Is gVisor secure enough for untrusted code?
It is built for that job, and Google, Anthropic and OpenAI all run untrusted code in it. An attacker has to compromise the Sentry and then escape its seccomp filter to reach the host. It does not defend against hardware side channels, and a microVM adds a hardware boundary if your threat model needs one.
Is gVisor slower than Docker?
For system-call-heavy and file-heavy workloads, yes, because every call is handled by the Sentry before any host work happens. CPU-bound code runs at close to native speed because gVisor doesn't emulate instructions. Measure your own workload under runsc to see which case you're in.
Does gVisor work with Kubernetes?
Yes. You install runsc on the nodes, register it with containerd, and create a RuntimeClass whose handler is runsc. Pods that set runtimeClassName to that class run inside gVisor. GKE Sandbox is Google's managed option, and gVisor is one of the sandbox technologies it supports.
Does gVisor support GPUs?
Yes, for NVIDIA GPUs. The nvproxy component forwards the application's driver calls to the host's NVIDIA driver and supports CUDA workloads such as PyTorch. The host driver version has to be one gVisor knows, and gVisor does less to contain bugs in the driver itself.
Who created gVisor, and is it open source?
Google created gVisor and open-sourced it in 2018 under the Apache 2.0 license. Google uses it in GKE Sandbox, Cloud Run and App Engine, and the code lives in the google/gvisor repository on GitHub.
Run untrusted code without operating the runtime
Beam sandboxes run as containers by default, and beta9, the open-source engine underneath, runs them under gVisor by default. One argument moves a CPU sandbox into a microVM, so you can match the runtime to the workload without running a fleet. Create a Beam account and start a sandbox from the Python or TypeScript SDK.
