Skip to content

gVisor — user-space kernel for container sandboxing

Deploy gVisor (runsc) as the OCI runtime for containers that need an extra isolation layer between the workload and the host kernel.

gVisor (binary name runsc) is a user-space implementation of a Linux kernel that intercepts every syscall a container makes, services it in user space, and only forwards a heavily filtered subset to the host kernel. Where Docker’s default runc lets the container talk directly to the host kernel’s syscall table, gVisor inserts itself in between. For multi-tenant hosts running untrusted code — CI runners, code execution sandboxes, SaaS isolation boundaries — this is the runtime to standardise on.

How to verify

A working gVisor install responds to these probes:

runsc --version
docker info | grep -i runtime
runsc --strace --debug --debug-log=/tmp/runsc.log run -bundle . sandbox
docker run --rm --runtime=runsc alpine dmesg | head -5
docker run --rm --runtime=runsc alpine uname -a

Inside a runsc container, uname -a reports kernel 4.4.0 regardless of the host’s actual kernel — that is gVisor’s synthetic kernel identity. The container is talking to a fake kernel.

What’s happening

runsc runs the container in its own address space, watching every syscall through ptrace (the slow but compatible default) or KVM-assisted virtualisation (the faster --platform=kvm mode). When the container calls read(), gVisor catches it, interprets the arguments, looks up its own file-descriptor table, decides whether the operation is allowed, and either services it from user-space data structures or makes a much smaller, narrower syscall on the host’s behalf.

The result is that the container never directly issues a syscall to the host kernel. Most CVEs in the Linux kernel — privilege escalations via clever syscall sequences, buffer overflows in obscure subsystems, race conditions in namespace cleanup — are simply unreachable from the container because the syscall flow goes through gVisor’s own kernel re-implementation first.

The trade-off is performance and compatibility. gVisor’s syscall handling is slower than direct host syscalls; for syscall-heavy workloads (databases, network proxies) it can be 10-30% slower. And gVisor implements only the syscalls real workloads use — exotic syscalls return ENOSYS. Most production apps work; some niche tools (containerised debuggers, kernel-feature probes) do not.

The mental model

Picture the syscall path under standard runc:

container app → host kernel (full syscall API)

Under gVisor:

container app → ptrace catch → runsc (user-space kernel) → narrow host syscalls

runsc is itself a Linux kernel-style implementation: process table, file-descriptor table, network stack, VFS layer. It even has its own implementations of procfs, sysfs, and tmpfs. The host kernel sees only the small subset of syscalls runsc itself makes to do its job.

This is the same architectural pattern as a microVM — a strong isolation boundary between the workload and the host — but achieved through user-space interpretation rather than hypervisor virtualisation.

Operational notes

  • Platform choice matters. The default ptrace platform is portable but slow because every syscall causes two context switches. The kvm platform is much faster but requires /dev/kvm access — pick kvm on bare metal or nested-virt-capable VMs, ptrace on shared cloud instances where /dev/kvm is unavailable.
  • Networking is two flavours. netstack is gVisor’s user-space network stack — gives the strongest isolation but worst performance. host reuses the host’s network stack via passthrough — faster but reduces the isolation gain. Default to netstack unless you have measured a network bottleneck.
  • Filesystem performance. gVisor uses 9P (or directfs in newer versions) for the container’s rootfs and mounts. Heavy filesystem workloads (e.g., compilations writing many small files) are noticeably slower than native overlayfs. Mount cached volumes via tmpfs where possible.
  • Compatibility gates. Some syscalls are not implemented (e.g., prctl(PR_SET_NAME) works, prctl(PR_MCE_KILL) does not). The gVisor project ships a compatibility report — check it before adopting gVisor for a stack you do not own.
  • Memory accounting. gVisor’s user-space kernel itself uses memory — figure 50-100 MiB per sandbox just for the runtime. On hosts running thousands of small containers, this adds up.
  • Logging and debugging. runsc debug --stacks <sandbox-id> dumps the sandbox’s internal goroutine state — invaluable when a workload hangs. The Sentry log lives at /var/run/containerd/io.containerd.runtime.v2.task/k8s.io/<container>/log.json.

Common pitfalls

  • Running workloads that depend on syscalls gVisor does not implement and being surprised they fail silently. Always test under --strace first to see which syscalls are issued.
  • Mixing gVisor and Docker on the same host with overlapping cgroup setups. Docker’s cgroup manager and gVisor’s both want to manage cgroups; the result is process accounting confusion.
  • Trusting runsc to protect against side-channel attacks (Spectre, Meltdown). It does not — those attacks are on CPU microarchitecture, not syscall semantics. For those threats, a microVM runtime like Firecracker is the right tool.
  • Deploying gVisor on a host kernel too old to support its KVM platform requirements (needs kernel ≥ 4.14 and modern KVM). On older kernels, only ptrace mode works.
  • Forgetting that --runtime=runsc does not work in rootless Docker without significant additional setup; gVisor expects to run as a privileged sub-process of the runtime.

Stack Harbor uses gVisor as the runtime for CI workloads, code-execution sandboxes, and any workload where a container escape would cross a trust boundary — see managed operations for the deployment pattern, the syscall compatibility audits we run, and the per-tenant runsc policy enforcement we layer onto Kubernetes.