November 13, 2025

gVisor: The Application Kernel

Understanding gVisor: The Application Kernel

1. Introduction and General Idea

gVisor is an open source application kernel for containers. It was developed by Google to provide a secure environment for running untrusted code.

gVisor is neither a standard container nor a traditional virtual machine. It exists in a unique category often called a sandboxed container runtime. It acts as a distinct layer between the application and the host operating system.

The primary goal of gVisor is to provide strong isolation. In a standard container environment, the application talks directly to the kernel of the host machine. If the application contains malicious code, it could exploit vulnerabilities in the host kernel to escape the container. gVisor solves this by inserting a boundary that intercepts application requests before they reach the sensitive host kernel.

2. The Core Problem: Native Containers vs Virtual Machines

To understand gVisor, one must understand the two ends of the spectrum.

Native Containers (runc)

Standard containers, such as Docker using the default runc runtime, are efficient. They are simply processes running on the host Linux kernel with some restrictions applied using cgroups and namespaces.

  • Pros: High performance, low memory footprint, fast startup.
    Cons: Weak isolation. The kernel is a large attack surface. A single bug in the kernel can compromise the entire server.

Virtual Machines (VMs)

Virtual Machines run a full operating system on top of a hypervisor.

  • Pros: Excellent isolation. Each VM has its own kernel.
    Cons: Heavy resource usage. They consume more memory and take longer to start.

The gVisor Solution

gVisor offers the best of both worlds. It provides the isolation of a virtual machine but maintains the flexibility and resource efficiency of a container. It creates a virtualized kernel interface in user space.

3. Architecture and Mechanics


gVisor operates by emulating the Linux kernel. It is written in the Go programming language. When a program inside a gVisor sandbox tries to make a system call (like opening a file or sending a network packet), gVisor intercepts it.

The architecture consists of two main components.

The Sentry ---- The Sentry is the core of gVisor. It acts as a kernel for the container. It implements the majority of the Linux system calls. When the application makes a request, the Sentry handles it. The Sentry runs in user space, meaning it does not have the high privileges of the actual host kernel. If an attacker compromises the Sentry, they are still trapped in a user space process and cannot easily harm the host.

The Gofer ---- The Gofer acts as a file system proxy. To maintain strict isolation, the Sentry is not allowed to access files on the host directly. Instead, the Sentry communicates with the Gofer. The Gofer then accesses the actual files on the disk. This separation ensures that even if the Sentry is compromised, it cannot read or write arbitrary files on the host system.

4. Comparison of Alternatives

Here is how gVisor compares to other runtime options available in the Kubernetes and Docker ecosystems.

FeatureNative (runc)gVisor (runsc)Kata Containers
Isolation MechanismNamespaces and CgroupsKernel Emulation (Software)Hardware Virtualization (VM)
Security LevelLow (Shared Kernel)High (Attack surface reduction)High (Hardware isolation)
PerformanceNative SpeedModerate OverheadModerate to High Overhead
Startup TimeInstantFastSlow to Moderate
CompatibilityFull Linux CompatibilityHigh (Most apps work)Full Linux Compatibility

Kata Containers

Kata is the primary alternative to gVisor for secure containers. Kata uses lightweight virtual machines (like Firecracker or QEMU) to run containers.

  • Difference: Kata relies on hardware virtualization features. gVisor relies on software emulation.

  • Use Case: Kata is often better for workloads that need raw kernel performance or features gVisor has not yet implemented. gVisor is often better for high density environments where memory usage is a concern.

5. Why and When to Use gVisor

You should consider using gVisor in specific scenarios where security is more critical than raw performance.

Multi Tenant Environments

If you run a platform where multiple distinct users run workloads on the same cluster, gVisor prevents one user from spying on or attacking another.

Running Untrusted Code

If your application executes code submitted by external users (such as a coding interview platform or a script runner), gVisor is essential. It contains the code within the sandbox effectively.

Defense in Depth

Even for internal applications, gVisor adds a layer of defense. If a web server is hacked, the attacker finds themselves in a restricted kernel emulation rather than on the actual host server.

6. Summary

gVisor is an Application Kernel. It runs containers by emulating the system call interface in user space. It is heavier than a standard container but lighter than a virtual machine. It is the ideal choice when you need to run containers with strict security boundaries without the complexity of managing full virtual machines.

7. Ref

https://gvisor.dev/docs/architecture_guide/

No comments:

Post a Comment