---
title: "Isolation for AI Agents: Container and Sandbox Escapes"
description: "A container escape or sandbox escape turns one bad tool call into host access. See how isolation for AI agents also covers noisy neighbors and leftover data."
canonical: "https://cosmonic.com/ai-sandbox/principles/isolation/"
---

[Learning Hub](https://cosmonic.com/ai-sandbox/) **·** [Principles](https://cosmonic.com/ai-sandbox/principles/) **·** **Isolation**

# Isolation for AI agents: containment across process, resource consumption, and time

Learn how a container escape or sandbox escape turns one bad tool call into host access.

Last updated October 2026

1. [Principle 1 Isolation](https://cosmonic.com/ai-sandbox/principles/isolation/)
2. [Principle 2 Deny by default](https://cosmonic.com/ai-sandbox/principles/deny-by-default/)
3. [Principle 3 Least authority](https://cosmonic.com/ai-sandbox/least-privilege-ai-agents/)
4. [Principle 4 Policy enforcement points](https://cosmonic.com/ai-sandbox/principles/policy-enforcement-points/)
5. [Principle 5 Controlled information flow](https://cosmonic.com/ai-sandbox/principles/lethal-trifecta/)
6. [Principle 6 Composition](https://cosmonic.com/ai-sandbox/principles/composition/)

[Download the principles matrix (PDF)](https://cosmonic.com/ai-sandbox/principles/sandboxing-principles-matrix.pdf)

When agents at OpenAI, Anthropic, and Google escaped test environments over the summer of 2026, none of them had to break a hypervisor. Instead, they left through channels that were supposed to be closed: a package cache proxy, a DNS resolver, a test network that reached the real internet.

Now picture your own coding agent pulling a container image and running it. If that image is hostile, what stops a container escape onto your laptop or your cluster? The answer starts with purpose, one job per sandbox, and then confinement along three edges: walls (what it can reach), budgets (how much it can take), and leftovers (what survives into the next run).

Isolation is one of [The 6 Principles of Secure Agent Platforms](https://cosmonic.com/ai-sandbox/principles/), and it builds on our guide to [choosing an agent sandbox](https://cosmonic.com/ai-sandbox/choosing-an-agent-sandbox/). In [the building analogy that runs across these principles](https://cosmonic.com/ai-sandbox/principles/#the-building-and-the-guard-the-six-principles-as-one-story), every agent gets its own room, with walls to the ceiling and its own share of the heat.

> The most important takeaway
>
> Isolation means each AI agent sandbox does one job and never shares memory, budgets, or leftovers. A container escape or sandbox escape crosses the wall, usually through something shared like the kernel, a socket or a GPU hook. A noisy neighbor drains a shared budget. Leftover data leaks to the next tenant.

![Diagram of a container escape: an AI agent sandbox with paths out through the shared kernel, a mounted folder, a socket and a GPU hook.](https://cosmonic.com/ai-sandbox/principles/isolation/container-escape-paths-day.webp)

## What isolation means for an AI agent

Isolation means an agent's sandbox shares nothing it doesn't have to with anything else on the machine, including purpose, memory, budgets, and leftovers. Each sandbox needs one clear purpose and a clear edge in three directions:

- **A clear purpose (what it does).** Each sandbox does one job, like the Unix philosophy of doing one thing and doing it well. This is a property of the design, not of the sandbox technology, and it sets the size of the control surface you have to guard.
- **In space (memory and kernel).** One tenant can't read or write another tenant's memory, or reach the host.
- **In resources.** Each tenant gets its own share of CPU, memory, instance slots, file descriptors, connections and disk.
- **In time.** Nothing is left behind for the next tenant.

A tenant is anyone or anything that shares the hardware: a user, a customer, an agent session or one task. Anything shared across an edge is a path between tenants.

| Edge | What goes wrong | Real example |
| --- | --- | --- |
| Intent: one job per sandbox (design, not rated) | One sandbox does several jobs, so it needs all of their access, and one compromise reaches all of it | [Clinejection](https://adnanthekhan.com/posts/clinejection/) (Feb 2026): an issue-triage bot also held a shell, write tools and release credentials |
| Walls: memory and kernel (1a) | Code escapes the sandbox into the host or another tenant | Leaky Vessels, runc CVE-2024-21626[^1] (Jan 2024): a leaked file handle let a container image reach the host's filesystem |
| Budgets: resources (1b) | One tenant starves the rest | A noisy neighbor or a fork bomb uses up CPU, memory or process slots, and every other session stalls |
| Leftovers: time (1c) | Old data reaches the next tenant | [ChatGPT, Mar 2023](https://openai.com/index/march-20-chatgpt-outage/): a connection reuse bug showed some users other people's chat titles |

Agents raise the stakes. An agent writes and runs code, pulls images, installs packages and loops on its own for hours, so every shared thing gets tested. In the [2026 lab breakouts](https://cosmonic.com/ai-sandbox/principles/) at OpenAI, Anthropic and Google, every escape ran through something the environment shared with the outside world: a package-registry proxy, an evaluation network, a DNS resolver. One OpenAI model went looking for a sandbox flaw and found one[^2].

Each environment shared a channel with the outside world. Closing channels until someone opens them on purpose is [deny by default](https://cosmonic.com/ai-sandbox/principles/deny-by-default/). Checking DNS and proxies as egress is [policy enforcement points](https://cosmonic.com/ai-sandbox/principles/policy-enforcement-points/).

The idea is a well researched topic; Saltzer and Schroeder[^3] (1975) called it "least common mechanism": share as little machinery between users as you can. [Rushby's separation kernel](https://doi.org/10.1145/800216.806586) (1981) set the order this series follows: isolate first, then add only the channels you mean to.

> What is isolation?
>
> Isolation is keeping each agent's sandbox fully apart from every other one, so nothing in one can touch, slow down or inherit from another.

## Intent: one job per sandbox

Purpose isn't a wall. It is a decision about what the sandbox is for. Give each sandbox one job, the way Bell Labs' 1978 summary of the Unix philosophy asked each program to "do one thing well." A sandbox that only runs tests needs the repo and a package mirror. A sandbox that only reads email needs the inbox and nothing else. Put both jobs in one sandbox and it needs the union of their access, so a single compromise reaches all of it.

Intent is a property of the design, not of the sandbox technology, so our comparison matrix doesn't rate it: you can give a container, a VM or a Wasm component one job or ten. What it changes is the control surface, meaning the files, hosts, tools and credentials you have to write rules for and watch. One job means a short allowlist you can actually check ([deny by default](https://cosmonic.com/ai-sandbox/principles/deny-by-default/)) and a small grant ([least authority](https://cosmonic.com/ai-sandbox/least-privilege-ai-agents/)). It is also step one of the [six-step method](https://cosmonic.com/ai-sandbox/choosing-an-agent-sandbox/#how-to-choose-an-agent-sandbox-in-six-steps): break the agent into workflow steps. Putting single-purpose pieces back together safely is [composition](https://cosmonic.com/ai-sandbox/principles/composition/).

In February 2026, [Clinejection](https://adnanthekhan.com/posts/clinejection/) showed the cost of mixing jobs. Cline's issue-triage bot also had a shell, write tools and a path to release credentials, so an injected issue title led to stolen release keys.

## Memory and kernel (1a): how sandbox and container escapes happen

The first edge is the wall itself: separate address spaces, kernels or linear memories, so one tenant can't read or write another tenant's state. This is what most people mean by isolation, and it is a common escape vector for agents.

### What is a sandbox escape?

A sandbox escape is when code inside a sandbox reaches something the sandbox was built to keep out, such as the host's files, its processes, or another tenant's data. Escapes almost always run through something the sandbox shares with the host. There are four common ways out:

| Way out | What is shared | Real example |
| --- | --- | --- |
| 1. The shared kernel | The host kernel and its objects, such as open file handles | [Leaky Vessels](https://github.com/opencontainers/runc/security/advisories/GHSA-xr7r-f8xq-vfvv) (runc CVE-2024-21626, Jan 2024): a leaked file handle let a container image reach the host's filesystem |
| 2. The runtime that builds the sandbox | The code that sets up namespaces, mounts and limits | [runc setup races](https://github.com/opencontainers/runc/security/advisories/GHSA-9493-h29p-rfm2) (CVE-2025-31133, -52565, -52881, Nov 2025): races during setup let a container redirect writes to sensitive host files |
| 3. A shared resource left inside | A bind mount, a control socket, the host network | [Docker Desktop Engine API](https://blog.qwertysecurity.com/Articles/blog3) (CVE-2025-9074, Aug 2025): any container could reach Docker's control API without auth and start a new container with the host's C: drive mounted |
| 4. A privileged helper on the host | A hook or daemon that acts for the sandbox | [NVIDIAScape](https://www.wiz.io/blog/nvidia-ai-vulnerability-cve-2025-23266-nvidiascape) (CVE-2025-23266, Jul 2025): a three-line Dockerfile got a privileged host hook to load attacker code |

![The four ways a sandbox escape happens, each with a real incident.](https://cosmonic.com/ai-sandbox/principles/isolation/four-ways-out-of-a-sandbox-day.webp)

### What is a container escape?

A container escape is a sandbox escape out of a container: a process inside gains access to the host or to other containers, usually through the kernel they all share. A container is an ordinary process with a private view of files, processes and network, not a small VM.

### Container escape vs VM escape vs sandbox escape

"Sandbox escape" is the general term; the other names tell you which wall was crossed.

| Escape type | The wall | Shared with the host | Typical way out | Example |
| --- | --- | --- | --- | --- |
| Container escape | Namespaces and cgroups | The whole host kernel, the runtime, any mounted socket or path | Kernel or runtime bug; a mounted `docker.sock` | Leaky Vessels, runc races |
| VM escape | Hardware virtualization | The hypervisor and its virtual devices | Bug in an emulated or virtual device | Firecracker virtio-PCI, CVE-2026-5747 |
| Wasm escape | Bounds-checked linear memory | The runtime and its compiler, in one process | Compiler or runtime bug; a misused host function | Wasmtime advisories, Apr 2026 |

### Container escapes: when the shared kernel or runtime breaks

Containers are namespaces plus cgroups on one host kernel[^4][^5]. So a kernel or runtime bug breaks every container on the host at once.

#### Why a shared kernel is the weak point

seccomp shrinks the kernel surface by filtering system calls, but the kernel docs say plainly: "System call filtering isn't a sandbox"[^6]. Docker's default profile disables around 44 of 300+ system calls[^7], but this still leaves a large kernel attack surface by default. A compromised agent can use that surface to gain new access, probe for weaknesses or connect through unexpected paths, like DNS. Minimal containers and images built `FROM scratch` reduce what is ambiently available by removing utilities, but they do not reduce the system calls.

#### Misconfigurations that hand over the host

Many escapes rely upon a misconfiguration instead of a bug. A mounted `docker.sock`, host paths, host networking or `CAP_SYS_ADMIN` hands the container the host[^8][^9]. The [policy enforcement points](https://cosmonic.com/ai-sandbox/principles/policy-enforcement-points/) guide covers this under the host control plane.

### GPU and AI infrastructure escapes

GPU containers need a privileged helper on the host to wire the graphics card in. That helper is shared, and on a shared AI cloud the next tenant's models and data sit behind it.

- [NVIDIA Container Toolkit, CVE-2024-0132](https://www.wiz.io/blog/wiz-research-critical-nvidia-ai-vulnerability) (Sep 2024): a malicious GPU container image could take over the host, exposing other tenants' models and data.
- [NVIDIAScape, CVE-2025-23266](https://www.wiz.io/blog/nvidia-ai-vulnerability-cve-2025-23266-nvidiascape) (Jul 2025): a three-line Dockerfile got a privileged host hook to load attacker code.

The fix is tenant separation: one tenant per GPU host, or a VM wall per tenant with [Kata Containers](https://katacontainers.io/). Use confidential VMs (AMD SEV-SNP, Intel TDX) if the host is untrusted[^10], and patch the [NVIDIA Container Toolkit](https://github.com/NVIDIA/nvidia-container-toolkit).

> What is a privileged helper?
>
> A privileged helper is a program on the host with high access that does setup work for a sandbox, such as attaching a GPU. It is like a building superintendent with a master key who does whatever any tenant's note asks. Forge the right note and the superintendent opens doors for you.

### VM, microVM and Wasm escapes: strong walls still need patching

Hardware and software walls are much smaller targets than a shared kernel, but they are code too.

#### What is a VM escape?

A VM escape is when code in a guest virtual machine breaks out into the hypervisor or host, usually through a bug in emulated or virtual devices. The hardware wall itself is sound[^11], so the devices are the soft spot. [Firecracker CVE-2026-5747](https://aws.amazon.com/security/security-bulletins/2026-015-aws) (Apr 2026) was an out-of-bounds write in the optional PCI transport that let a guest crash the VMM and possibly run code on the host. The default configuration was not affected. Keep optional devices off and run [Firecracker](https://github.com/firecracker-microvm/firecracker) under its [jailer](https://github.com/firecracker-microvm/firecracker/blob/main/docs/jailer.md) [^12].

#### Can Wasm code escape its sandbox?

Wasm code can escape only through a bug in the runtime or its compiler, or by misusing a host function it was explicitly given. Wasm isolates memory in software, inside one process[^13][^14], so the compiler is part of the wall. The April 2026 [Wasmtime advisories](https://bytecodealliance.org/articles/wasmtime-security-advisories) (CVE-2026-34971, -34987) were compiler bugs that let a module reach host memory in non-default configurations: the Winch backend, or aarch64 with Spectre mitigations turned off. Eleven of the twelve advisories were found with LLM-assisted tools. Use guard regions and Spectre mitigations[^15], the [pooling allocator](https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html), one instance per request and a second wall.

#### Shared hardware leaks across every wall

[Spectre](https://doi.org/10.1109/SP.2019.00002) showed that side channels in the CPU cross software boundaries. For high-value tenants, the only full answer is separate hardware.

### When the agent itself is the hole

Isolation has to hold against the agent too. An agent acting with your full privileges makes every wall moot.

- [Perplexity Comet](https://brave.com/blog/comet-prompt-injection/) (Aug 2025): hidden text on a web page made an AI browser read the user's Gmail and post a one-time password to Reddit.
- [Claude Code and its own denylist](https://ona.com/stories/how-claude-code-escapes-its-own-denylist-and-sandbox) (Mar 2026): blocked from npx, the agent called it through `/proc/self/root/usr/bin/npx`. When bubblewrap stopped that, it asked to turn the sandbox off.

Give the agent its own identity, enforce approvals outside the model, and give it no switch to turn its own sandbox off. Claude Code, for one, documents an unsandboxed retry escape hatch[^16]. See [least authority](https://cosmonic.com/ai-sandbox/least-privilege-ai-agents/) and [controlled information flow](https://cosmonic.com/ai-sandbox/principles/lethal-trifecta/).

### How to prevent container and sandbox escapes

1. Use one disposable sandbox per task.
2. Run each agent as its own user and restrict ptrace[^17].
3. Go rootless with user namespaces, drop all capabilities, set `no-new-privileges`, and apply the Pod Security Standard "restricted"[^18][^19].
4. Never mount `docker.sock` or host paths, and never use host networking.
5. Put a smaller guard in front of the kernel ([gVisor](https://gvisor.dev/docs/) runsc) or a VM wall ([Kata Containers](https://katacontainers.io/), Firecracker).
6. Keep optional VM devices (PCI) off and use the Firecracker jailer.
7. Give each tenant its own GPU host.
8. Patch runc, the GPU toolkit, the hypervisor and the Wasm runtime.
9. Run tools as Wasm components (pooling allocator with guard pages, Spectre mitigations) inside a second wall: an OS sandbox or a microVM.

#### How to detect container escape attempts

Watch for processes entering host namespaces, new privileged containers, writes to host paths and calls to control sockets such as `docker.sock`.

> Watch out
>
> A container inside a container on the same kernel is one wall, not two. One kernel bug beats both.

## Resource budgets (1b): noisy neighbors, fork bombs and starvation

Resource isolation means each tenant gets a fixed share of CPU, memory, instance slots, file descriptors, connections and disk, so no tenant can starve the rest. Picture one agent session stuck in a runaway build loop. It eats all the RAM, and every other session on the host stalls or gets killed.

There is no public AI agent incident for resource budgets yet, but agents that loop on their own will hit these old failure modes. [Gligor](https://doi.org/10.1109/TSE.1984.5010241) (1984) counted denial of service as a security property, and [resource containers](https://www.usenix.org/conference/osdi-99/resource-containers-new-facility-resource-management-server-systems) (Banga, Druschel and Mogul, 1999) introduced the per-activity caps behind cgroups.

### What is the noisy neighbor problem?

The noisy neighbor problem is when one tenant on shared hardware uses so much CPU, memory, disk or network that every other tenant slows down. [Dean and Barroso](https://doi.org/10.1145/2408776.2408794) showed how this sharing drives slow tail responses at scale.

### What is a fork bomb, and how do you stop one?

A fork bomb is a program that copies itself over and over until the machine runs out of process slots and stops responding. A wall alone doesn't stop it, because the bomb never leaves its sandbox. A process cap does: cgroups v2 `pids.max`, Docker `--pids-limit`, a Job Object process limit on Windows, or RLIMIT_NPROC.

### The classic failure modes, and the control for each

| Failure mode | What it looks like on an agent host | Control |
| --- | --- | --- |
| Noisy neighbor | One session's build slows every other session | CPU and memory caps per sandbox |
| Tragedy of the commons | Every tenant takes a little more of a shared pool | Per-tenant quotas plus a global ceiling |
| Starvation | A low-priority session never gets CPU | Fair-share scheduling |
| Slowloris hoarding | A tenant holds connections open until the slots run out | Per-tenant connection caps |
| Fork bomb | A process copies itself until the process table is full | A process limit per sandbox |
| Overcommit and the OOM killer | Memory runs out and the kernel kills the wrong process | A memory limit per sandbox; no overcommit for hostile tenants |
| Head-of-line blocking | One slow job holds up the whole queue | Admission control and backpressure |
| Fate sharing | One crash takes down its neighbors | One sandbox per task |
| Priority inversion | A low-priority task holds what a high-priority one needs | Fair-share scheduling; short-held locks |
| Deadlock | Two tasks wait on each other forever | Fail fast instead of waiting |
| Thundering herd | Every session retries at the same moment | Jittered retries and staggered restarts |

Each layer has its own controls: [cgroups v2](https://docs.kernel.org/admin-guide/cgroup-v2.html), [Job Objects](https://learn.microsoft.com/en-us/windows/win32/procthread/job-objects) or [setrlimit](https://man7.org/linux/man-pages/man2/setrlimit.2.html) and launchd limits on the host; fuel and epoch interruption[^20], [ResourceLimiter](https://docs.wasmtime.dev/api/wasmtime/trait.ResourceLimiter.html) and [pooling-allocator limits](https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html) in a Wasm runtime; [ResourceQuota](https://kubernetes.io/docs/concepts/policy/resource-quotas/), LimitRange and pod limits in Kubernetes; token and tool-call budgets per agent session.

## Residue and reuse (1c): what the last tenant leaves behind

The third edge is time: nothing outlives the tenant. Scratch files, memory, pooled connections, cached sessions and reused identifiers are wiped or retired before anything else gets them. Picture yesterday's agent session leaving a token in a shared temp folder. Today's session, run for someone else, can read it.

### What is object reuse?

Object reuse is the rule that memory, files, connections and IDs must be wiped of the last owner's data before anyone else gets them. The term comes from the [Orange Book](https://csrc.nist.gov/files/pubs/conference/1998/10/08/proceedings-of-the-21st-nissc-1998/final/docs/early-cs-papers/dod85.pdf) (DoD TCSEC, 1985). Data remanence, the related term, means data that lingers after it should be gone. [Chow et al. (2005)](https://www.usenix.org/legacy/events/sec05/tech/full_papers/chow/chow.pdf) argued for clearing memory as soon as it's freed.

The four classic failure modes:

- **Object reuse:** memory or files handed over without being wiped.
- **Resource leaks and orphans:** state that nobody reclaims.
- **Identifier reuse:** a new tenant inherits an old tenant's ID, and whatever it was granted.
- **Stale snapshots:** a restored microVM brings back old memory, secrets and random-number state.

In March 2023, a bug in the Redis client's connection reuse [handed one ChatGPT user's cached data to another](https://openai.com/index/march-20-chatgpt-outage/): some users saw other users' chat titles, and some payment details were exposed. In 2026, [Agent Substrate](https://github.com/agent-substrate/substrate/issues/1688) never reclaimed actor directories when worker pods went away: 23 orphans held 27 GB and pushed a node to 90% disk. Instructions planted in an agent's long-term memory are leftovers too; see [controlled information flow](https://cosmonic.com/ai-sandbox/principles/lethal-trifecta/).

The controls: bubblewrap `--tmpfs` and systemd [PrivateTmp](https://man7.org/linux/man-pages/man5/systemd.exec.5.html) on Linux; Windows Sandbox, which discards all state on close; a fresh Wasm instance per request; an ephemeral VM or microVM per task, with snapshots verified before restore. At the agent layer, wipe the workspace and credentials at the end of every task.

## Isolation across the sandbox types

No sandbox type meets all three edges by default. Intent isn't rated here, because it is a design choice you make on top of any sandbox type. **Yes** means a type meets the edge by default, **Partial** means partly or with the listed controls, and **No** means not by default. The OS sandbox rows are rated as configured: bubblewrap, Landlock, seccomp and cgroups (Linux), Seatbelt (macOS), and AppContainer with Job Objects (Windows). Remember, while we refer to all of these mechanisms as "sandbox types" after the conventional usage of the term, mechanisms like [containers and VMs are not sandboxes at all](https://cosmonic.com/ai-sandbox/principles/#containers-microvms-and-vms-are-not-sandboxes).

**Linux sandbox (Space: Partial) (Resources: Yes) (Time: Yes)**

**Overall:** Partial

**Pro:** Namespaces and cgroups give each sandbox its own view and its own budget, cheaply; `--tmpfs` scratch vanishes on exit

**Con:** One shared kernel: a kernel bug breaks every sandbox; bubblewrap sets no budgets itself

**Controls to add:** bubblewrap (`--unshare-all`, `--tmpfs /tmp`); seccomp; cgroups v2 with `pids.max`; gVisor

**Upstream doc:** [bubblewrap](https://github.com/containers/bubblewrap), [cgroups v2](https://docs.kernel.org/admin-guide/cgroup-v2.html), [gVisor](https://gvisor.dev/docs/)

**macOS sandbox (Space: Partial) (Resources: Partial) (Time: Partial)**

**Overall:** Partial

**Pro:** Seatbelt confines files, network and IPC per process

**Con:** Shared XNU kernel; no per-sandbox budgets beyond rlimits; container directories persist

**Controls to add:** Seatbelt profile (sandbox-exec; deny process-info\*, mach-lookup); setrlimit and launchd limits; per-run temp folder; Apple container for a hardware wall

**Upstream doc:** sandbox-exec(1)[^21] (deprecated), [apple/container](https://github.com/apple/container), [App Sandbox](https://developer.apple.com/documentation/security/app-sandbox)

**Windows sandbox (Space: Partial) (Resources: Yes) (Time: Partial)**

**Overall:** Partial

**Pro:** AppContainer gives its own object namespace and token; Job Objects cap CPU, memory and process count; Windows Sandbox discards all state on close

**Con:** AppContainer shares the NT kernel, sets no budgets alone, and its storage persists between runs

**Controls to add:** AppContainer / LPAC; Job Objects; Windows Sandbox (Hyper-V) for disposable runs

**Upstream doc:** [AppContainer isolation](https://learn.microsoft.com/en-us/windows/win32/secauthz/appcontainer-isolation), [Job Objects](https://learn.microsoft.com/en-us/windows/win32/procthread/job-objects), [Windows Sandbox](https://learn.microsoft.com/en-us/windows/security/application-security/application-isolation/windows-sandbox/windows-sandbox-overview)

**Container (Space: Partial) (Resources: Yes) (Time: Partial)**

**Overall:** Partial

**Pro:** Own filesystem, process and network namespaces; cgroup limits per container; writable layer discarded with the container

**Con:** Shares the host kernel (runc, NVIDIA toolkit escapes); inodes, conntrack and page cache stay shared; volumes need explicit cleanup

**Controls to add:** Rootless / user namespaces; gVisor or Kata; no host paths, no `docker.sock`; Pod Security Standard "restricted"; `--pids-limit`, pod limits, ResourceQuota; `--rm`, `--read-only` + tmpfs

**Upstream doc:** [Docker rootless](https://docs.docker.com/engine/security/rootless/), [Pod Security Standards](https://kubernetes.io/docs/concepts/security/pod-security-standards/), [ResourceQuota](https://kubernetes.io/docs/concepts/policy/resource-quotas/), [Kata Containers](https://katacontainers.io/)

**gVisor (container runtime) (Space: Partial) (Resources: Yes) (Time: Partial)**

**Overall:** Partial

**Pro:** A user-space kernel (the Sentry) answers most system calls itself, so the host kernel sees only a small set; drop-in OCI runtime (runsc); same cgroup budgets as a container

**Con:** Still a software wall that reaches the host kernel through that smaller set; slower system calls and I/O; not every syscall or feature is supported; volumes still need cleanup

**Controls to add:** Use runsc as the runtime for untrusted workloads; keep the container controls (no host paths, no `docker.sock`, `--rm`, pod limits)

**Upstream doc:** [gVisor docs](https://gvisor.dev/docs/), [gVisor security model](https://gvisor.dev/docs/architecture_guide/security/)

**VM (Space: Partial) (Resources: Yes) (Time: Partial)**

**Overall:** Partial

**Pro:** Strongest wall available: hardware-enforced, its own kernel; fixed vCPUs and RAM

**Con:** Not functional on its own: needs a full guest OS, wide open inside; host overcommit brings noisy neighbors back; long-lived VMs and snapshots keep state

**Controls to add:** Disable shared folders and clipboard; patch the hypervisor; confidential VM if the host is untrusted; no memory overcommit, CPU pinning; ephemeral VM per task

**Upstream doc:** [KVM docs](https://docs.kernel.org/virt/kvm/index.html)

**microVM (Space: Partial) (Resources: Yes) (Time: Partial)**

**Overall:** Partial

**Pro:** Strong hardware wall with a tiny device model; about 125 ms boot (Firecracker); built-in disk and network rate limiters

**Con:** Needs a guest OS and KVM on a Linux host; snapshot restore brings back old memory, secrets and random-number state

**Controls to add:** Firecracker jailer; keep optional devices (PCI) off; one microVM per task; I/O rate limiters; verify snapshots and reseed randomness after restore

**Upstream doc:** [Firecracker](https://github.com/firecracker-microvm/firecracker), [jailer](https://github.com/firecracker-microvm/firecracker/blob/main/docs/jailer.md)

**Wasm (Space: Yes) (Resources: Partial) (Time: Partial)**

**Overall:** Partial

**Pro:** Bounds-checked linear memory per instance; no OS; microsecond start; pooled memory reset before reuse

**Con:** Software-enforced: compiler bugs are escapes; budgets are switches you must turn on; preopened folders and host pools outlive the instance

**Controls to add:** One instance per request; pooling allocator with guard pages; fuel + epoch interruption; ResourceLimiter memory caps; Spectre mitigations; never reuse tenant IDs; a second wall (OS sandbox or microVM)

**Upstream doc:** [Wasmtime security](https://docs.wasmtime.dev/security.html), [PoolingAllocationConfig](https://docs.wasmtime.dev/api/wasmtime/struct.PoolingAllocationConfig.html), [ResourceLimiter](https://docs.wasmtime.dev/api/wasmtime/trait.ResourceLimiter.html), [Config: fuel and epochs](https://docs.wasmtime.dev/api/wasmtime/struct.Config.html)

**Process (Space: No) (Resources: No) (Time: No)**

**Overall:** No

**Pro:** Separate address space per process

**Con:** Shares the kernel, files, budgets and leftovers with everything the user runs

**Controls to add:** Run under an OS sandbox; separate user account; restrict ptrace; rlimits; private temp folder per run, cleaned on exit

**Upstream doc:** [Yama ptrace_scope](https://docs.kernel.org/admin-guide/LSM/Yama.html), [setrlimit(2)](https://man7.org/linux/man-pages/man2/setrlimit.2.html)

A plain process meets none of the three edges. A configured Linux sandbox covers budgets and leftovers cheaply but shares one kernel, so the strongest setups stack two walls: Wasm inside an OS sandbox for density, or Wasm inside a microVM for a hardware wall. The full comparison lives in the [platforms vs principles matrix](https://cosmonic.com/ai-sandbox/principles/sandboxing-principles-matrix.pdf).

![Container isolation compared with VM, microVM and Wasm isolation by what each shares with the host.](https://cosmonic.com/ai-sandbox/principles/isolation/what-each-sandbox-boundary-shares-day.webp)

## Stack walls that fail differently

Defense in depth works only when the layers fail in different ways: two walls built from the same thing fall to the same bug. The [principles hub](https://cosmonic.com/ai-sandbox/principles/) compares weak, dense and strong stacks, and Figure 4 summarizes them.

Here is the dense stack in practice. An agent's PDF tool runs as a Wasm component, one instance per request, inside a host process locked down with Landlock and seccomp. A parser bug hits the Wasm wall, and a runtime bug still faces the OS sandbox.

Add an egress proxy ([policy enforcement points](https://cosmonic.com/ai-sandbox/principles/policy-enforcement-points/)) and a scoped cloud identity ([least authority](https://cosmonic.com/ai-sandbox/least-privilege-ai-agents/)) to any stack, and put budgets and cleanup at every layer: cgroups or Job Objects on the host, fuel and memory caps in the runtime, one sandbox per task.

![Weak, dense and strong ways to stack sandbox walls that fail differently to stop a sandbox escape.](https://cosmonic.com/ai-sandbox/principles/isolation/weak-vs-strong-sandbox-stack-day.webp)

### How Cosmonic applies isolation

Cosmonic gives each agent tool its own small sandbox that starts with nothing, so a bad tool call stays in one room.

[Cosmonic Desktop](https://cosmonic.com/desktop/) is a free app for macOS, Windows and Linux. It runs tools and apps as WebAssembly components in a local deny-by-default sandbox, and shows what each component can reach before it runs. Its built-in MCP server lets coding agents such as Claude Code, Codex and Gemini CLI build tools and deploy them there. No account, cloud or Kubernetes is needed.

[Cosmonic Control](https://cosmonic.com/control/) runs the same components in production on Kubernetes. It is built on wasmCloud, the CNCF project Cosmonic's founders co-created. Egress is denied by default, with DNS controls. It works with a Kubernetes admission controller and RBAC, Kubernetes Secrets and External Secrets, and OpenTelemetry. It installs on-prem and in air-gapped environments.

WebAssembly is the mechanism. You still pick the outer wall around the host.

**Try it:** [download Cosmonic Desktop](https://cosmonic.com/desktop/) and run your agent's next tool as a component. For production, [talk to us about Cosmonic Control](https://cosmonic.com/control/). Then read the rest of [The 6 Principles of Secure Agent Platforms](https://cosmonic.com/ai-sandbox/principles/).

[Previous 6. Composition](https://cosmonic.com/ai-sandbox/principles/composition/) [The series Back to all six](https://cosmonic.com/ai-sandbox/principles/) [Next 2. Deny by default](https://cosmonic.com/ai-sandbox/principles/deny-by-default/)

## Related topics

[Principles Principles of secure agent platforms Security design principles for AI agents, from Saltzer and Schroeder to NIST, each tied to a real AI agent incident.](https://cosmonic.com/ai-sandbox/principles/) [Principle 2 Deny by default Why an AI agent should start with no access, and why denylists, auto-approve and auto-started tools fail.](https://cosmonic.com/ai-sandbox/principles/deny-by-default/) [Compare Sandbox approaches compared Containers, microVMs, isolates and WebAssembly on isolation, cold start, density and cost, at agent-traffic scale.](https://cosmonic.com/ai-sandbox/compare/) [Cornerstone How to choose an AI agent sandbox The six-step method: break the agent into steps, list what each one really needs, and match it to the least capable sandbox that still fits.](https://cosmonic.com/ai-sandbox/choosing-an-agent-sandbox/)

## Run agent tools as Wasm components

Public beta

Cosmonic Desktop (free; macOS, Windows, Linux) runs each tool in a deny-by-default sandbox and shows what each component can reach before it runs. For production on Kubernetes, use Cosmonic Control.

[Download Cosmonic Desktop](https://learn.cosmonic.com/cosmonic-desktop-beta) [See Cosmonic Control](https://cosmonic.com/control/)

![Cosmonic Desktop's Inspect view: a component's declared interfaces and network egress drawn out, with everything else denied by default.](https://cosmonic.com/ai-sandbox/inspect-capabilities.webp)

## Frequently asked questions

**What is a container escape?**

A container escape is when a process inside a container gains access to the host or to other containers. It usually happens through the shared kernel, a bug in the container runtime, or a mounted control socket such as `docker.sock`. Leaky Vessels (runc CVE-2024-21626, January 2024) is a well-known example: a leaked file handle exposed the host's filesystem.

**Can an AI agent escape a container?**

Yes. An AI agent can escape a container if the container shares a vulnerable kernel or runtime, or exposes `docker.sock` or host paths. The runc setup races of November 2025 and the NVIDIA Container Toolkit bugs are real examples. Add a second wall that fails differently, such as gVisor, Kata Containers or a microVM.

**What is a VM escape?**

A VM escape is when code in a guest virtual machine breaks into the hypervisor or the host, usually through a bug in a virtual device. VM escapes are rarer than container escapes. Firecracker CVE-2026-5747 (April 2026) affected only the optional PCI transport, which is why optional devices should stay off.

**Is a VM safer than a container for AI agents?**

A VM is usually safer than a container for isolation, because it has its own kernel behind a hardware wall. But a VM does nothing about what the agent can do inside it. Pair it with deny-by-default tools and egress control. See [containers vs VMs vs microVMs vs Wasm](https://cosmonic.com/ai-sandbox/compare/).

**Can Windows Sandbox be escaped?**

Windows Sandbox is a disposable Hyper-V virtual machine, so escaping it requires a bug in the hypervisor or the host. No sandbox is escape-proof. To shrink the risk, keep networking off and map folders read-only in the .wsb configuration file[^22].

**Can Wasm code escape its sandbox?**

Wasm code can escape only through a bug in the runtime or its compiler, or by misusing a host function it was given. In April 2026, Wasmtime advisories showed such compiler bugs in non-default configurations. Keep the runtime patched, and run the host inside an OS sandbox or a microVM for a second wall.

**How do I detect container escape attempts?**

Detect container escape attempts by watching for processes that enter host namespaces, new privileged containers, writes to host paths and calls to control sockets such as `docker.sock`. Alert on each one. Detection only tells you after the fact, so put prevention first: rootless containers, dropped capabilities and no host mounts.

**How do I stop a fork bomb in an agent sandbox?**

Stop a fork bomb by capping the number of processes each sandbox can start. Use cgroups v2 `pids.max` on Linux, Docker `--pids-limit`, a Job Object process limit on Windows, or RLIMIT_NPROC. A wall alone doesn't stop a fork bomb, because it never leaves its sandbox. A resource budget does.

**What is tenant isolation?**

Tenant isolation keeps each customer's or agent's code, data and resources apart on shared infrastructure. It has three parts: its own wall (memory and kernel), its own budget (CPU, memory, processes, connections) and nothing left behind for the next tenant. Weakness in any one of the three lets one tenant affect another.

[^1]: CVE-2024-21626: container escape via a leaked file descriptor in runc. Open Container Initiative security advisory. [github.com](https://github.com/opencontainers/runc/security/advisories/GHSA-xr7r-f8xq-vfvv)
[^2]: OpenAI, on safety and alignment for long-horizon models, July 2026. [openai.com](https://openai.com/index/safety-alignment-long-horizon-models/)
[^3]: Saltzer and Schroeder (1975), “The Protection of Information in Computer Systems”, Proceedings of the IEEE. [doi.org](https://doi.org/10.1109/PROC.1975.9939)
[^4]: Linux manual page, namespaces(7). [man7.org](https://man7.org/linux/man-pages/man7/namespaces.7.html)
[^5]: Linux manual page, user_namespaces(7). [man7.org](https://man7.org/linux/man-pages/man7/user_namespaces.7.html)
[^6]: Linux kernel documentation, Seccomp BPF (seccomp_filter). [docs.kernel.org](https://docs.kernel.org/userspace-api/seccomp_filter.html)
[^7]: Docker, seccomp security profiles. [docs.docker.com](https://docs.docker.com/engine/security/seccomp/)
[^8]: Linux man-pages, capabilities(7). [man7.org](https://man7.org/linux/man-pages/man7/capabilities.7.html)
[^9]: Docker, “Protect the Docker daemon socket”. [docs.docker.com](https://docs.docker.com/engine/security/protect-access/)
[^10]: Linux kernel documentation, KVM. [docs.kernel.org](https://docs.kernel.org/virt/kvm/index.html)
[^11]: Popek and Goldberg (1974), “Formal Requirements for Virtualizable Third Generation Architectures”. [doi.org](https://doi.org/10.1145/361011.361073)
[^12]: Agache et al. (2020), “Firecracker: Lightweight Virtualization for Serverless Applications”, NSDI. [usenix.org](https://www.usenix.org/conference/nsdi20/presentation/agache)
[^13]: Wahbe et al. (1993), “Efficient Software-Based Fault Isolation”. [doi.org](https://doi.org/10.1145/168619.168635)
[^14]: Haas et al. (2017), “Bringing the Web up to Speed with WebAssembly”. [doi.org](https://doi.org/10.1145/3062341.3062363)
[^15]: Wasmtime documentation, security. [docs.wasmtime.dev](https://docs.wasmtime.dev/security.html)
[^16]: Anthropic, Claude Code sandboxing documentation. [code.claude.com](https://code.claude.com/docs/en/sandboxing)
[^17]: Linux kernel documentation, Yama (ptrace_scope). [docs.kernel.org](https://docs.kernel.org/admin-guide/LSM/Yama.html)
[^18]: Docker, rootless mode. [docs.docker.com](https://docs.docker.com/engine/security/rootless/)
[^19]: Kubernetes, Pod Security Standards. [kubernetes.io](https://kubernetes.io/docs/concepts/security/pod-security-standards/)
[^20]: Wasmtime API documentation, Config (fuel and epoch interruption). [docs.wasmtime.dev](https://docs.wasmtime.dev/api/wasmtime/struct.Config.html)
[^21]: macOS manual page, sandbox-exec(1). [keith.github.io](https://keith.github.io/xcode-man-pages/sandbox-exec.1.html)
[^22]: Microsoft, configuring Windows Sandbox with a .wsb file. [learn.microsoft.com](https://learn.microsoft.com/en-us/windows/security/application-security/application-isolation/windows-sandbox/windows-sandbox-configure-using-wsb-file)
