Skip to content
Français
Account: not signed in, sync available My learning
Select theme
Français

Runtime Sandboxes: gVisor, Kata Containers and RuntimeClass

By updated

Improve this page

Containers share the Linux kernel of the host. A kernel flaw or a poorly filtered system call can let a malicious container escape to the host. Sandboxed runtimes (gVisor, Kata Containers) add an extra layer of isolation between the container and the host kernel, which reduces the attack surface. The Kubernetes RuntimeClass resource lets you send chosen Pods to these alternative runtimes. This guide covers the configuration, the usage and the selection criteria for the CKS exam.

Sandboxed runtimes belong to the Minimize Microservice Vulnerabilities domain of the official CKS curriculum published by the CNCF, which gives it a weight of 20% in the exam. This domain lists "sandboxed containers" among its isolation techniques. This guide has you practice the two gestures that belong to it: creating a RuntimeClass, and assigning a Pod to the runtime you want.

What you will learn

  • Explain why standard containers are not enough for some workloads
  • Compare how gVisor and Kata Containers isolate containers
  • Declare an alternative runtime in containerd
  • Create a RuntimeClass resource and assign it to a Pod
  • Choose the runtime that fits your constraints
  • Confine a Pod and detect abnormal activity without help, with the module challenge

Prerequisites

  • A Kubernetes cluster with administrator access
  • Familiarity with Pods and Security Contexts
  • SSH access to the cluster nodes (to configure containerd)

Why isolate containers further?

A standard Linux container (runc) runs as an isolated process thanks to namespaces and cgroups, but it shares the host kernel. Every system call of the container is handled directly by the host kernel.

This shared kernel raises two security problems:

  • Wide attack surface: the Linux kernel exposes several hundred system calls. A vulnerability in any of them can allow a container escape.
  • Incomplete isolation: some kernel resources (such as /proc and /sys) are not fully partitioned by namespaces.

Sandboxed runtimes solve this problem by placing an extra layer between the container and the host kernel.

ApproachIsolationPerformanceCompatibility
runc (standard)Namespaces + cgroupsNativeFull
gVisor (runsc)Application kernel in userspaceSyscall overheadHigh for common workloads
Kata ContainersLightweight VM per PodStartup overheadNear-complete

The diagram follows the same system call in the three cases. On the left, with runc, the process reaches the host kernel directly, shared with every container. In the middle, with gVisor, the call stops first in the Sentry (outlined in red), which only calls the host kernel for a restricted set of operations. On the right, with Kata Containers, the call is served by the micro-VM's guest kernel (outlined in red): the host is reached only through the hypervisor.

Three system call paths. runc container: the process calls the shared host kernel directly. gVisor: the process calls the Sentry, an application kernel in userspace, which calls the host kernel only for restricted operations. Kata Containers: the process calls the guest kernel of a micro-VM, then the hypervisor, then the host kernel.Container (runc)system callContainerprocessSharedhost kernelgVisor (runsc)system callrestricted operationsContainerprocessSentryuserspace application kernelHost kernelKata Containerssystem callContainerprocessGuest kernelin the micro-VMHypervisorHost kernel
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

gVisor: an application kernel in userspace

gVisor is an open source Google project that intercepts the system calls of containers and handles them in an application kernel written in Go, called the Sentry. This kernel runs in userspace, that is, as an ordinary program and not inside the host kernel. The container's processes do not call the host kernel directly: their system calls are intercepted and served by the Sentry, which relies on the host kernel only in a controlled way.

How is gVisor built?

gVisor is made of two main processes:

  • Sentry: the application kernel. It implements the Linux system calls (memory management, threading, signals, networking) and relies on the host kernel only for a restricted set of operations. It runs in userspace with a very restrictive seccomp profile.
  • Gofer: a mediator process that manages file system access through the 9P protocol. The Sentry has no direct access to the host's files.

gVisor's OCI executable is called runsc (run sandboxed container). It integrates with containerd and CRI-O like any OCI runtime.

What are the strengths and limits of gVisor?

The trade-off of gVisor fits in one sentence: it intercepts system calls in user space instead of letting them reach the host kernel. Everything below follows from it, the benefits and the costs alike, and that is what makes the choice predictable rather than a matter of taste.

The practical consequence for deciding: gVisor suits an application better the more it talks little to the kernel. A service that computes barely pays; a service that multiplies I/O operations pays on every operation.

What you gain:

  • Small footprint: no VM, no full guest kernel. A gVisor sandbox uses little extra memory.
  • Fast startup: comparable to runc, because there is no VM to launch.
  • Written in Go: the fact that gVisor is mostly written in Go reduces some classic classes of memory vulnerabilities (use-after-free, buffer overflow) compared with kernel code in C/C++.

What you lose:

  • Per-syscall overhead: every system call goes through the Sentry, which adds latency. I/O-heavy and syscall-heavy workloads are the most affected.
  • Compatibility: gVisor does not implement every Linux system call. Some very specific applications may not work.
  • No kernel modules: applications that need specific kernel modules (advanced iptables, eBPF) are not compatible.

Kata Containers: a lightweight VM per Pod

Kata Containers takes the opposite approach to gVisor: each Pod runs in its own dedicated lightweight virtual machine. The container has its own guest Linux kernel, isolated from the host kernel by a hypervisor (QEMU/KVM, Cloud Hypervisor or Firecracker).

What are the strengths and limits of Kata Containers?

Rather than reimplementing system calls, Kata gives a real Linux kernel to each Pod, inside a lightweight virtual machine. Compatibility gains everything gVisor concedes, and the cost moves from run time to memory and startup.

The criterion for choosing between the two is therefore less the threat covered, which is the same on both sides, than the nature of the workload: Kata for a demanding or exotic application that gVisor refuses to run, gVisor for many lightweight containers on a node with limited resources.

What you gain:

  • Hardware isolation: the separation is provided by the hypervisor and the CPU virtualization mechanisms (VT-x/AMD-V). The isolation is comparable to that of a classic VM.
  • Near-complete compatibility: the container runs on a real Linux kernel, with no system call restriction.

What you lose:

  • Startup overhead: launching a micro-VM takes a few seconds, against a few milliseconds for runc.
  • Memory consumption: each Pod needs its own guest kernel in memory.
  • Nested virtualization: if your Kubernetes nodes themselves run in VMs, Kata may require nested virtualization, which depends on the cloud provider and the instance type.

gVisor vs Kata Containers

Two rows of this table settle the choice in practice; the others only add nuance. Nested virtualization first: if your Kubernetes nodes are themselves virtual machines at a cloud provider that does not expose it, Kata is ruled out outright, and the question no longer arises. Compatibility next: gVisor reimplements system calls, so an application that touches eBPF, kernel modules or rare system calls may fail, where Kata runs a real Linux kernel and accepts everything. Keep in mind that these two runtimes are not ranked from weaker to stronger: they protect against the same threat, escape to the host kernel, through two different mechanisms.

CriteriongVisorKata Containers
MechanismUserspace kernel (Go)Lightweight VM (hypervisor)
IsolationStrong (system call interception)Strong (kernel separated by a hypervisor)
PerformancePer-syscall overheadStartup + memory overhead
CompatibilityHigh for common workloadsNear-complete
Nested virt.Not requiredRequired if nodes are virtualized
Use casesMulti-tenant, CI/CD, serverlessRegulated workloads, defense in depth

RuntimeClass: sending Pods to a runtime

The Kubernetes RuntimeClass resource lets you assign a Pod to a specific CRI runtime. It is a non-namespaced (cluster-scope) resource, stable since Kubernetes v1.20, which maps a readable name to a CRI handler configured on the nodes.

How do you create a RuntimeClass?

apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
# The handler must match the configuration name exposed by the CRI
handler: runsc

The handler field must exactly match the configuration name exposed by the node's CRI implementation, for example containerd or CRI-O.

How do you use a RuntimeClass in a Pod?

To run a Pod with a sandboxed runtime, add the runtimeClassName field to the Pod spec:

apiVersion: v1
kind: Pod
metadata:
name: sandbox-test
spec:
runtimeClassName: gvisor
containers:
- name: app
image: nginx:1.27@sha256:6784fb0834aa7dbbe12e3d7471e69c290df3e6ba810dc38b34ae33d3c1c05f7d

If the referenced RuntimeClass does not exist, the Pod creation is rejected at admission (Forbidden: RuntimeClass not found). If the RuntimeClass exists but the handler is not configured on the node, the Pod stays stuck in ContainerCreating with a FailedCreatePodSandBox event.

The next diagram shows the whole chain. Follow the solid arrows: the Pod names a RuntimeClass, whose handler designates the runtime declared in containerd, here runsc. The dashed arrows show a Pod without runtimeClassName, which containerd hands to its default runtime.

A Pod with runtimeClassName gvisor references the gvisor RuntimeClass, whose runsc handler is declared in containerd, which starts runsc. A Pod without runtimeClassName goes through containerd and gets the default runtime, runc.handler runscdefault runtimePodruntimeClassName: gvisorRuntimeClass gvisorhandler: runsccontainerdon the nodePod withoutruntimeClassNamerunsc (gVisor)runc
Source · SVG
Esc to close, + and − to zoom, scroll to move around. 100 %

Scheduling and nodeSelector

By default, RuntimeClass assumes a homogeneous cluster where every node supports the runtime. In practice, only some nodes have gVisor or Kata installed.

RuntimeClass supports a scheduling field that injects a nodeSelector and tolerations into Pods at admission. These constraints combine with those already present in the Pod; they do not replace them:

apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: gvisor
handler: runsc
scheduling:
nodeSelector:
runtime: gvisor
tolerations:
- key: runtime
value: gvisor
effect: NoSchedule

With this configuration, Pods that use runtimeClassName: gvisor are automatically directed to the nodes labeled runtime=gvisor.

Pod Overhead

Sandboxed runtimes consume extra resources (memory for the gVisor Sentry, or for the Kata guest kernel). The overhead field lets you declare that consumption so the scheduler accounts for it:

apiVersion: node.k8s.io/v1
kind: RuntimeClass
metadata:
name: kata
handler: kata
overhead:
podFixed:
memory: "120Mi"
cpu: "250m"

This cost is injected into the Pod at admission, from the RuntimeClass, then taken into account everywhere afterwards: in scheduling, in resource quotas, in the Pod's cgroup and in eviction decisions.

The Pod Overhead mechanism is stable since Kubernetes 1.24, so there is no feature gate to enable. What you do need to check, however, is that it took effect: the values declared in the RuntimeClass's overhead.podFixed appear in the Pod's .spec.overhead field after admission. If that field is empty, the Pod was not attached to the RuntimeClass you thought it was.

How do you configure containerd for an alternative runtime?

The two runtimes are not installed the same way. gVisor is installed on each node, outside Kubernetes: a binary, then a declaration in containerd. Kata Containers is installed, according to its documentation, with its kata-deploy Helm chart, which drops binaries and artifacts on the nodes from the cluster itself.

  1. Install runsc on each target node

    gVisor publishes one archive per dated release, which contains runsc and the containerd shim. Pin the release rather than following latest, and check the SHA-512 digest before installing (extraction needs bzip2):

    Terminal window
    ARCH=$(uname -m) # x86_64 or aarch64
    GVISOR=20260928.0
    URL=https://storage.googleapis.com/gvisor/releases/release/${GVISOR}/${ARCH}
    curl -sSfLO "${URL}/gvisor.tar.bz2"
    curl -sSfLO "${URL}/gvisor.tar.bz2.sha512"
    sha512sum -c gvisor.tar.bz2.sha512
    tar xjf gvisor.tar.bz2 runsc containerd-shim-runsc-v1
    sudo install -m 0755 runsc containerd-shim-runsc-v1 /usr/local/bin/
    runsc --version

    The check must answer gvisor.tar.bz2: OK, and the last command must report the pinned release:

    runsc version release-20260928.0
    spec: 1.2.1
  2. Configure containerd to declare the runsc handler

    Add to /etc/containerd/config.toml (containerd 2.x syntax / config v3):

    [plugins."io.containerd.cri.v1.runtime".containerd.runtimes.runsc]
    runtime_type = "io.containerd.runsc.v1"
  3. Restart containerd

    Terminal window
    sudo systemctl restart containerd
  4. Check that the runtime is available

    Terminal window
    sudo crictl info | grep -A 5 runsc

Complete workflow: from the node to the Pod

Here is the complete procedure to deploy a sandboxed Pod with gVisor. With Kata, kata-deploy takes care of the first two steps and creates its own RuntimeClasses:

  1. Install the runtime on the target nodes (gVisor or Kata)

  2. Configure containerd with the matching handler

  3. Label the nodes that support the runtime

    Terminal window
    kubectl label nodes <node-name> runtime=gvisor
  4. Create the RuntimeClass in the cluster

    Terminal window
    kubectl apply -f - <<EOF
    apiVersion: node.k8s.io/v1
    kind: RuntimeClass
    metadata:
    name: gvisor
    handler: runsc
    scheduling:
    nodeSelector:
    runtime: gvisor
    EOF
  5. Deploy a Pod with the RuntimeClass

    Terminal window
    kubectl apply -f - <<EOF
    apiVersion: v1
    kind: Pod
    metadata:
    name: sandbox-test
    spec:
    runtimeClassName: gvisor
    containers:
    - name: test
    image: nginx:1.27@sha256:6784fb0834aa7dbbe12e3d7471e69c290df3e6ba810dc38b34ae33d3c1c05f7d
    command: ["sh", "-c", "uname -a && sleep 3600"]
    EOF
  6. Check that the Pod uses the right runtime

    Terminal window
    # Confirm the runtimeClassName in the spec
    kubectl get pod sandbox-test -o jsonpath='{.spec.runtimeClassName}'
    # gvisor
    # Compare the kernel seen by the container with the node's
    kubectl exec sandbox-test -- cat /proc/version
    # Linux version 4.19.0-gvisor ... (the node itself runs 6.8.x)
    # dmesg shows the messages of the gVisor Sentry
    kubectl exec sandbox-test -- dmesg | head -3
    # [0.000000] Starting gVisor...
    # For a Kata Pod, the kernel shown is the one of the guest VM,
    # and dmesg shows a complete Linux boot

Best practices

Two questions arise once the sandboxed runtime is in place, and they do not call for the same answers. The first is to guarantee that it is really used, because nothing in Kubernetes forces a manifest to ask for a RuntimeClass. The second is to measure its cost on your workload, which varies too much from one application to another to be deduced from an advertised figure.

Security

The blind spot of the setup is that a RuntimeClass is not enforced: the author of the manifest chooses their own runtimeClassName, and forgetting it silently falls back to runc. The security of the sandbox therefore rests entirely on two external safeguards: RBAC that prevents creating a RuntimeClass pointing to a lax handler, and an admission policy that rejects Pods without a sandboxed runtime in sensitive namespaces.

  • Restrict the creation of RuntimeClasses to cluster administrators (RBAC). A user should not be able to create or modify RuntimeClasses.
  • Enforce the RuntimeClass on sensitive namespaces with an admission controller (Kyverno, Gatekeeper) to guarantee that multi-tenant workloads always use a sandboxed runtime.
  • Combine with other mechanisms: RuntimeClass does not replace the Pod Security Standards, AppArmor/Seccomp or Network Policies. It is an additional layer of defense in depth.

Performance

The overhead of a sandboxed runtime cannot be summed up as a global percentage: it depends on your application's system call profile. A service that computes a lot and talks little to the kernel loses little; a service that multiplies disk accesses or network connections pays on every operation. So measure on your real workload, not on a generic benchmark, and keep an eye on the node's memory: it is what saturates first when several sandboxes coexist, each carrying its own Sentry or its own guest kernel.

  • Test before deploying: measure the impact on your real workloads. gVisor adds an overhead that varies with the number of system calls.
  • Separate the nodes: dedicate some nodes to sandboxed workloads so the overhead does not affect standard applications.
  • Declare the Pod Overhead: set the overhead field in the RuntimeClass so the scheduler plans Pods correctly.

Troubleshooting

The moment the Pod fails already tells you where to look, before you even read the message. An immediate refusal at creation comes from the API server: the RuntimeClass does not exist in the cluster. A Pod that stays Pending found no node matching the scheduling constraints. A Pod that reaches ContainerCreating and then hangs was scheduled: the problem is then on the node itself, in the containerd configuration or in the runtime binary. So start with kubectl describe pod, whose Events section tells these three cases apart unambiguously.

SymptomLikely causeSolution
Rejected at creation: Forbidden: RuntimeClass "xxx" not foundRuntimeClass missing from the clusterCheck kubectl get runtimeclass
Pod stuck in ContainerCreating with a FailedCreatePodSandBox eventHandler not configured in containerd / CRI-OCheck /etc/containerd/config.toml (path depends on the version), restart containerd
Pod Pending indefinitelyNo node with the required labelCheck the labels (kubectl get nodes --show-labels) and the RuntimeClass's scheduling.nodeSelector
not supported error with KataHardware virtualization not availableCheck that /dev/kvm exists on the node; enable nested virtualization if the nodes are virtualized
Application crashes under gVisorSystem call not implementedCheck the gVisor logs (runsc debug); check compatibility on gvisor.dev

Resources

Three sources, depending on what you are looking for. The Kubernetes documentation describes RuntimeClass itself, that is, the exposure mechanism, and it is the reference if your question is about the handler or about scheduling. The other two each document an implementation, and that is where the compatibility lists and the tuning options live, which change at the pace of those projects and not of Kubernetes.

Hands-on practice

A sandbox is proven by looking at the kernel the container sees. This lab places a Pod on a second runtime installed on the node, which runs its own application kernel, and the validation reads from the inside a kernel version that is no longer the node's.

Challenge: confine a Pod and detect abnormal activity

The challenge is the module's unaided proof: it is graded on the cluster state you leave behind, not on the commands you typed. On the k8s-cp.lab node, no procedure is given. You confine Pods against the kernel with AppArmor and seccomp, you require mutual TLS in a meshed namespace, you close another namespace by default while keeping its application flow and its DNS, and you isolate a Pod in a sandbox. Finally, you get Falco to raise an alert when a shell is opened in the protected namespace, and only there. The lab preparation installs Falco 0.45.2, gVisor and Istio, but it defines no profile and no rule: writing the Falco rule is your job, like the profiles.

The validation reads sixteen states, with no solution and no value to copy. The tests really write and run chmod in the Pods, make real connections between Pods and compare the sandbox's kernel with the machine's. They open a shell themselves in the protected Pod, then in a Pod of another namespace, before reading the alerts written by Falco, and they check that the rules shipped with Falco have not changed. Passing requires 70 points out of 100, and there are no hints.

Three states are blocking and must pass whatever the total: the write to /tmp refused by the AppArmor profile, the client without a sidecar blocked while the meshed client gets through, and the Falco alert for a shell opened in the protected namespace. While you work, dsoxlab check shows what is missing, without saying how to fix it, and the lesson to go back to is the one that teaches that state. Another state grades the default network lockdown of a namespace, which the lesson on NetworkPolicies teaches. The challenge builds on AppArmor (in French), on seccomp (in French), on pod-to-pod mutual TLS, on Falco and on Falco or Tetragon (in French), as well as on the sections of this lesson devoted to the sandbox.

Key takeaways

  1. Standard containers share the host kernel, which exposes a wide attack surface through system calls
  2. gVisor intercepts system calls in an application kernel written in Go, suited to multi-tenant and CI/CD workloads
  3. Kata Containers runs each Pod in a lightweight VM with its own kernel: near-complete compatibility, but costlier startup and memory
  4. RuntimeClass is the Kubernetes resource that maps a name to a CRI handler configured on the nodes
  5. The runtimeClassName field in the Pod spec activates the alternative runtime
  6. The RuntimeClass scheduling field automatically targets the compatible nodes
  7. The overhead field declares the runtime's extra resources for the scheduler
  8. Sandboxed runtimes do not replace the other Kubernetes security mechanisms, they complete them

Knowledge check

Five questions on kernel isolation: what gVisor and Kata Containers do differently, and how RuntimeClass exposes them to Pods.

Knowledge check

Check what you have learned with this interactive quiz

5 questions
5 min
70% to pass

How it works

  • The timer starts when you click Start
  • Multiple choice, true/false and short answer questions
  • You can move between questions
  • Detailed results are shown at the end

Starts the quiz and the timer