4 min

What I learned today: Docker, sandboxes, gVisor, and things I thought I knew

From Docker and Kubernetes to gVisor and microVMs: the real isolation boundaries behind AI agent development, and why not everything needs rebuilding.

Also in: Tiếng Việt · 中文 · 한국어 · 日本語

Today I went down a surprisingly deep rabbit hole while researching secure execution environments for AI coding agents. It began with one question: Is Docker actually a sandbox?

That question led me from Kubernetes to gVisor, microVMs and Docker-in-Docker. Turns out, several things I thought I understood weren't quite that simple. Here are my notes from the journey.

What sits inside each sandbox?
Conceptual architecture, not a complete syscall or virtualization trace.
Chạy trong sandbox cô lập; mạng chỉ qua proxy được duyệt.

1/ Docker isn't necessarily a security sandbox

Docker isolates processes with Linux namespaces, cgroups, seccomp and other controls. But on Linux, ordinary containers still share the host kernel. A kernel vulnerability or container escape can cross that boundary.

Kubernetes doesn't magically fix this. It's a container orchestrator, not a stronger isolation boundary by itself. In simple terms: Docker builds rooms; Kubernetes manages the building. The rooms still share the same foundation.

2/ But Docker on macOS actually runs inside a VM

Docker Desktop on macOS runs Docker Engine inside a Linux virtual machine because macOS doesn't provide the Linux kernel needed to run Linux containers natively. Docker Desktop on Linux uses a KVM-backed VM too, whereas Docker Engine installed directly on Linux doesn't require one.

So Docker Desktop on macOS adds a VM boundary between Linux containers and the macOS host. Yet ordinary containers inside that VM still share its Linux kernel. A Docker container is not a virtual machine, and each container does not automatically get its own VM.

Compare isolation boundaries

Docker Engine

Standard Linux container

gVisor

Alternative to runc

MicroVM

VM per isolated workspace

FeatureDocker EnginegVisorMicroVM
Kernel interface seen by appHost Linux kernelSentry in userspaceGuest Linux kernel
Separate VM boundaryNoNoYes
Important caveatShared host kernelNot a full Linux VMVirtualization overhead

3/ gVisor takes a clever, different approach

Rather than booting a VM with a full Linux kernel, gVisor implements a Linux application kernel in userspace called Sentry. It intercepts and handles most application syscalls itself instead of simply forwarding them to the host kernel.

The app still sees a familiar Linux interface. Its regular instructions execute on the real CPU while Sentry implements the operating-system interfaces it needs. The trade-offs are compatibility and overhead, especially for I/O-heavy workloads.

mermaidflowchart LR
subgraph native["Docker Engine / Linux"]
A["Application"] --> B["syscall"] --> C["Host Linux kernel"]
end
subgraph visor["gVisor / runsc"]
D["Application"] --> E["Syscall trap"] --> F["Sentry / userspace"] --> G["Restricted host operations"]
end
Simplified syscall paths: gVisor does not merely forward every application syscall to the host.

4/ Yes, Docker can run inside gVisor

Docker-in-gVisor lets a Docker daemon operate within a gVisor sandbox. You can then docker build, docker run, or run PostgreSQL, Redis, Node.js and Python. That's enough for a fairly complete development environment.

But containers inside the same Docker daemon do not automatically have separate trust boundaries from one another. gVisor helps enforce the outer host boundary; it does not replace internal policies for filesystems, networking, access rights and secrets.

5/ What if every AI agent needs its own VM?

Docker Sandboxes provides the sbx CLI to run Claude Code, Codex and other coding agents in separate microVMs. Each sandbox gets its own Linux kernel, Docker Engine and filesystem. On Linux, Kata Containers is another approach that runs containers in lightweight VMs with separate kernels.

But if you mount a real host directory into the sandbox with write access, the agent can still alter or delete those files. Strong isolation cannot compensate for overly permissive access policies.

6/ Back to TOSE: three problems I should stop mixing together

While building Cloud Managed Agents and exploring Self-improvement Harness for TOSE, I realized we need to separate three responsibilities:

  • Orchestration: manage agents, sessions, queues, resources, lifecycle and costs.
  • Execution: provide an isolated runtime with filesystems, networking, Docker and development tools.
  • Improvement: let agents edit, test, evaluate and propose better harness versions.

Orchestration

Who runs, when, how long and at what cost?

Execution

Where can code execute and what can it access?

Improvement

What proves a new version is actually better?

TOSE already has pieces of this foundation: a gVisor-based Docker host for Cloud Harness, durable orchestration for Agent Runtime and a harness-versioning design. But several pieces remain incomplete, including the Pi runtime adapter, metering and real-world Hybrid Harness Platform tests.

An AI that can edit its own code hasn't necessarily improved itself.

An agent might change 20 files, add 50 tests and declare victory. But when it writes and grades its own tests, perhaps all it has accomplished is a fresh collection of tautological tests. :))))

Real self-improvement requires independent evaluation against a baseline: quality, task completion, cost, performance and security. If you can't measure the improvement, don't call it improvement.

Evidence-based improvement loop (proposed)

A target workflow, not a claim that autonomous self-improvement is live on TOSE.

  1. Step 1: Propose

    Agent edits code in a separate workspace.

  2. Step 2: Evaluate independently

    Run evaluator-owned tests in isolation.

  3. Step 3: Human review

    Compare quality, costs and risks to baseline.

  4. Step 4: Controlled release

    Publish an immutable version; no automatic deploy.


The biggest lesson I learned today

Before building something, understand which layer the problem belongs to. Docker doesn't replace Kubernetes. Kubernetes doesn't replace a sandbox. gVisor isn't a VM. And a fancy sandbox doesn't magically make an AI agent smarter.

If Docker already handles packaging, Kubernetes handles orchestration and gVisor addresses a substantial part of isolation, why rebuild them all? The part worth building is the value that existing tools still don't provide.

AI makes it possible to build almost anything. That doesn't mean we should build everything.

Sometimes spending a whole day understanding the problem, and then deciding NOT to build, is a much more productive day. :))))

References

P.S. These are notes from what I studied today, not a claim to be an expert. If you've deployed these technologies in production, I'd love to hear where my understanding needs correcting.