Home | Send Feedback | Share on Bluesky |

Sandboxing Docker containers with gVisor on Debian 13

Published: 6. December 2026  •  docker, debian

Docker makes it easy to package an application with its dependencies and run it in an isolated environment. But containers still share the host's Linux kernel. If an application gets compromised, a kernel vulnerability could allow an attacker to escape the container.

gVisor adds another isolation layer between the application and the host. It integrates with existing container tools, so you can keep using Docker images and Docker Compose.

In this blog post, we will look at how gVisor works, where it is useful, and how to set it up on Debian 13. We will also run a few examples and discuss its limitations.

What problem does gVisor solve?

A regular Linux container consists of processes isolated using features such as namespaces, capabilities, and seccomp. Namespaces restrict what processes can see, while seccomp restricts which system calls they can make. However, the allowed system calls still reach the host's kernel. Docker's security documentation explains these mechanisms in more detail.

Consider a service that converts uploaded documents to another format. An attacker uploads a specially crafted file that exploits a vulnerability in the conversion library. The attacker can now execute code inside the container.

Container isolation restricts access to the rest of the system, but the compromised process can still interact with the host kernel through the interfaces available to it. gVisor aims to reduce this exposure by putting its own implementation of those interfaces between the application and Linux. This is the main goal described in its security model.

How gVisor works

The central component of gVisor is the Sentry, an application kernel written in Go that runs in userspace. It implements Linux functionality such as system calls, process management, memory management, and signals.

When an application makes a system call, gVisor handles it. Some operations can be completed entirely inside the sandbox. Others require controlled interactions with the host.

For example, gVisor can answer a request for a process ID using its own process bookkeeping. Reading a file backed by host storage may ultimately require host filesystem operations.

The application's system calls are not simply forwarded to Linux. gVisor provides its own implementation and uses a restricted set of host operations to support it. The architecture introduction describes this separation.

Filesystem access also involves a component called the Gofer. Current configurations can use Directfs, which allows the Sentry to operate on filesystem trees exposed through file descriptors supplied by the Gofer. Access remains limited to the configured filesystem view. See the filesystem documentation.

For Docker users, the component we interact with is runsc, gVisor's OCI-compatible container runtime. Docker continues to manage images, containers, and networking, while runsc starts the sandbox. Existing compatible images can run without rebuilding them specifically for gVisor. See What is gVisor?.

When would I use it?

I would consider gVisor for workloads where an application compromise could give an attacker executable code on my infrastructure.

Some examples are:

Prerequisites

The following setup assumes a Debian 13 machine with sudo access and a standard Docker Engine installation running as a system service.

gVisor supports amd64 and arm64 and requires Linux 5.6 or newer. See the gVisor installation guide for more information.

You do not need /dev/kvm for this walkthrough. The default gVisor platform, systrap, works without hardware virtualization support. This makes it convenient for a Debian VPS.

There is also a KVM platform, which can be worth evaluating on bare metal. Inside a virtual machine, the documentation generally recommends systrap over nested KVM. We will use the default. See Changing Platforms.

Install Docker

If Docker Engine and the Compose plugin are already installed, you can skip this section.

Follow the official Docker Engine installation guide for Debian to install Docker Engine and the Compose plugin. The guide covers prerequisites, conflicting packages, and verification steps. Once Docker is running, continue with the gVisor installation below.

Install gVisor

For Debian 13, follow the APT repository instructions in the official gVisor installation guide. I use the release channel for this walkthrough.

For Docker integration details, see the official gVisor Docker quick start. Once runsc is installed and registered with Docker, continue with the examples below.

Run your first sandboxed container

Run the familiar Docker test image, this time selecting gVisor:

sudo docker run --rm --runtime=runsc hello-world

The relevant option is:

--runtime=runsc

Installing gVisor does not automatically move existing containers into sandboxes. For this setup, we select the runtime when creating each container.

This lets us introduce gVisor gradually and check compatibility for individual applications. The gVisor Docker guide includes additional examples.

Example: run a Python job

Let's create a small Python script that calculates a result and writes it to a temporary file.

Save the following as job.py:

import json
from pathlib import Path

values = [12, 7, 19, 3]

result = {
    "count": len(values),
    "total": sum(values),
    "maximum": max(values),
}

output = Path("/tmp/result.json")
output.write_text(json.dumps(result))

print(output.read_text())

We will use the official python:3.14-slim-trixie image. Pull it before running the job:

sudo docker pull python:3.14-slim-trixie
chmod 0644 job.py

Now run the script with gVisor:

sudo docker run --rm \
  --name gvisor-job \
  --runtime=runsc \
  --network=none \
  --read-only \
  --user=65534:65534 \
  --cap-drop=ALL \
  --security-opt=no-new-privileges=true \
  --memory=256m \
  --memory-swap=256m \
  --cpus=0.5 \
  --tmpfs /tmp:rw,nosuid,nodev,noexec,size=16m,mode=1777 \
  --mount "type=bind,src=$(pwd)/job.py,dst=/job.py,readonly" \
  python:3.14-slim-trixie \
  python -B /job.py

The expected output is:

{"count": 4, "total": 41, "maximum": 19}

There are several independent controls here:

Docker documents these options in the container run reference and the none network driver documentation.

The CPU limit allows approximately half a CPU's worth of execution time. The memory settings allow 256 MiB of memory with no additional swap allowance. These limits apply to the sandbox, so leave room for gVisor's own overhead. See Docker resource constraints and the gVisor resource model.

This example runs a finite script. A service that accepts arbitrary jobs also needs a deadline enforced outside the sandbox, output limits, and cleanup. A CPU quota limits consumption rate, but it does not stop a job after a certain number of seconds. The job controller should explicitly stop and remove containers that exceed their deadline.

Also, noexec on /tmp does not prevent Python from reading and interpreting a script stored there. It restricts direct execution from that mount.

Example: use gVisor with Docker Compose

Docker Compose supports selecting a runtime for each service through the runtime property.

For a small demonstration, we will serve a static HTML file using Python's HTTP server.

Create the content:

mkdir -p site

cat > site/index.html <<'EOF'
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>gVisor example</title>
  </head>
  <body>
    <h1>Hello from a gVisor sandbox</h1>
  </body>
</html>
EOF

chmod 0755 site
chmod 0644 site/index.html

Create compose.yaml:

services:
  web:
    image: python:3.14-slim-trixie
    runtime: runsc
    user: "65534:65534"

    command:
      - python
      - -B
      - -m
      - http.server
      - "8080"
      - --bind
      - "0.0.0.0"
      - --directory
      - /site

    ports:
      - "127.0.0.1:8080:8080"

    volumes:
      - ./site:/site:ro

    read_only: true

    cap_drop:
      - ALL

    security_opt:
      - no-new-privileges:true

    mem_limit: 256m
    memswap_limit: 256m
    cpus: 0.5

Start the service and request the page:

sudo docker compose up -d

curl http://127.0.0.1:8080/

You can inspect the runtime selected for the running container:

sudo docker inspect \
  --format '{{.HostConfig.Runtime}}' \
  "$(sudo docker compose ps -q web)"

The output should be:

runsc

The published port is bound to the host's loopback address, so this example is intended for local access. The container still has outbound networking through the normal Compose network.

To remove the example:

sudo docker compose down

For an existing Compose application, you can add runtime: runsc to selected services and recreate them. For example, you could sandbox a document-conversion worker while evaluating the database separately.

Drawbacks

Performance overhead

gVisor adds work when an application interacts with operating-system interfaces. It also needs memory for the Sentry and its internal state.

The impact depends on the workload. Code that spends most of its time calculating in userspace may see relatively little overhead. Applications that perform many system calls, filesystem operations, or small network operations can be more affected.

Benchmark the actual application with representative traffic. Measure startup time, memory consumption, throughput, and latency.

The performance guide explains the sources of overhead.

Compatibility gaps

gVisor implements a substantial portion of Linux's application interface, but it does not implement every feature.

Applications that depend on specific kernel functionality or unusual device access may need changes or may not work. For example, the current compatibility documentation describes limited io_uring support and restrictions around mounting block devices inside the sandbox.

It would also be inaccurate to say that gVisor cannot use GPUs at all: there is dedicated support for certain accelerators. Hardware support needs to be checked for the particular workload.

Start with the application compatibility documentation and run your application's integration tests.

Different debugging and monitoring

Processes inside a gVisor sandbox do not appear as ordinary application processes on the host. Host tools therefore see a different picture than they do with native containers. See the resource model.

For troubleshooting, gVisor provides its own debugging and syscall logging facilities. These are useful when an application encounters a missing or differently implemented system call. The debugging guide explains how to enable them.

What gVisor does not do

gVisor protects an isolation boundary. It does not determine whether everything happening inside that boundary is legitimate.

It does not fix application vulnerabilities. An attacker who exploits an application can still act with that application's permissions. If the application can read customer records or access a secret, the attacker may be able to do the same. The security introduction explicitly distinguishes application compromise from escaping the sandbox.

It does not make exposed host resources harmless. A writable bind mount still grants write access to the mounted data. Giving a job access to the Docker socket can give it control over the daemon and a route around the intended isolation. Docker explains the implications of daemon access in its security documentation.

It does not automatically define an outbound network policy. gVisor has its own network stack, but that does not mean every container is disconnected from your network. A compromised worker may still reach internal services or send data to external destinations if its network configuration allows it. Use networking restrictions appropriate to the workload. See the networking guide.

It does not automatically solve resource exhaustion. You still need CPU and memory limits, storage controls, job deadlines, and limits on concurrent jobs. A sandbox that cannot escape can still consume the resources you allow it to use. Docker's resource constraints documentation covers the basic controls.

It does not eliminate hardware side channels or every possible escape. Host and runtime vulnerabilities still matter, and gVisor itself needs security updates. Its security model describes the threats it addresses and the limits of that protection.

Wrapping up

gVisor adds another isolation layer between a containerized application and the host kernel. Its integration with Docker and Docker Compose makes it straightforward to try with existing workloads: select the runsc runtime, then check compatibility and performance with your application.

For services that execute user-provided code, process uploaded documents, or run AI-generated scripts, this additional containment can be useful. The trade-offs are runtime overhead, some compatibility gaps, and differences in debugging and monitoring.

The sandbox still needs carefully chosen permissions. Restrict access to files, credentials, and networks, set resource limits, and keep the host and runtime updated. Combined with these controls, gVisor can help limit the damage when an application is compromised.