Skip to content
Yassir Kachri

Agentic AI Security

Sandboxing Agent Code Execution: Choosing the Isolation Boundary

Coding agents run code that anyone able to reach their context can influence. How OS sandboxes, containers, userspace kernels and microVMs differ, and how to choose a boundary by what the code can reach.

Yassir Kachri 7 min read

Coding agents and many other agents write code and then run it. The OWASP Top 10 for Agentic Applications, published in December 2025, gives this risk its own entry, ASI05, Unexpected Code Execution, and explains why ordinary controls struggle with it: “Because this code is often generated in real-time by the agent it can bypass traditional security controls.” The entry names prompt injection that leads to “execution of attacker-defined code” as its first example.

Its guidance on the execution environment is direct: “Never run as root. Run code in sandboxed containers with strict limits including network access,” and “Where possible, restrict filesystem access to a dedicated working directory and log file diffs for critical paths.” The word sandbox, however, covers isolation boundaries of very different strength. Choosing among them is an architecture decision, and it depends on two questions: who can influence the code the agent runs, and what that code can reach.

Four boundaries, from shared kernel to separate kernel

The useful distinction is what the code shares with the host. Every option below restricts the code in some way; they differ in how much of the host’s kernel and devices the code can still touch, and in what that costs.

Exhibit 1 The four common sandbox boundaries differ in what untrusted code shares with the host
BoundaryWhat the code shares with the hostDocumented examplesDocumented trade-off
OS-level process sandboxThe host kernel and the user’s session, with files and network restricted by OS primitivesClaude Code sandboxing (bubblewrap on Linux, Seatbelt on macOS); Codex CLI (Seatbelt, a Linux sandbox, a Windows restricted token)Light to run, since Anthropic’s runtime works “without the overhead of spinning up and managing a container”; the code still runs on the host kernel
ContainerThe host kernel; containers “mount file systems like /sys and /proc from the underlying host” (Kubernetes)Standard container runtimesStrength depends on the kernel and on hardening such as seccomp and user namespaces
Userspace kernelBy default, “a minimal set of host system calls,” made by gVisor’s own kernel; “No system call is passed through directly to the host”gVisor“reduced application compatibility and higher per-system call overhead” (gVisor)
MicroVMA hardware virtualization boundary with a minimal device modelFirecracker, used by AWS Lambda and Fargate; Kata ContainersA host that supports KVM; boot time and memory per VM (see below)

Source: Anthropic Engineering (20 October 2025); openai/codex, codex-rs/README.md at commit 3b7334d (31 May 2026); Kubernetes documentation, Multi-tenancy; gVisor documentation; Firecracker website (April 2026) and Agache et al., NSDI 2020. Classification is the author's.

OS-level process sandboxes are what desktop coding agents provide. Anthropic introduced sandboxing for Claude Code’s bash tool in October 2025, enabled with the /sandbox command, and described it as two boundaries, “Filesystem isolation, which ensures that Claude can only access or modify specific directories” and “Network isolation, which ensures that Claude can only connect to approved servers,” built “on top of OS level primitives such as Linux bubblewrap and MacOS seatbelt.” Anthropic reported that “in our internal usage, we’ve found that sandboxing safely reduces permission prompts by 84%,” an internal figure that shows why the boundary matters for autonomy as well as safety. OpenAI’s Codex CLI offers a comparable set of modes: a default read-only sandbox, a workspace-write mode that allows “the agent to write within the current workspace while still blocking network access,” and a full-access mode that the repository’s README, as of May 2026, annotated “only do this if you are already running in a container or other isolated env.” Codex starts in its read-only sandbox by default; in Claude Code the sandbox is switched on by the user. These sandboxes run on the developer’s own kernel, inside the developer’s session.

Containers separate processes, file systems and networks, but the Kubernetes documentation on multi-tenancy notes that “containers are processes running on a shared kernel,” and describes sandboxing as a way to “insulate the host from container escapes, where an attacker exploits a vulnerability to gain access to the host system and all the processes/files running on that host.” Hardening narrows that surface. Kubernetes documents user namespaces as a way to let “a process running as root in a container” run “as a different (non-root) user in the host,” which can “reduce the damage a compromised container can do to the host or other pods in the same node.”

Userspace kernels put a second kernel between the code and the host. gVisor describes itself as “an application kernel that implements a Linux-like interface,” written “in a memory-safe language (Go)” and running in userspace. It “was created in order to provide additional defense against the exploitation of kernel bugs by untrusted userspace code.” Its documentation states the cost: “reduced application compatibility and higher per-system call overhead,” and possibly “poor performance for system call heavy workloads.”

MicroVMs give each workload its own guest kernel behind hardware virtualization. Firecracker “uses the Linux Kernel-based Virtual Machine (KVM) to create and manage microVMs” and exposes only five emulated devices, according to its website. Its jailer “provides a second line of defense in case the virtualization barrier is ever compromised.” The 2020 paper that describes it reports that, “with the provided minimal Linux guest kernel configuration, it offers memory overhead of less than 5MB per container, boots to application code in less than 125ms.” Those figures are AWS’s measurements under that stated configuration; they show that the per-session cost of a microVM can be small enough for short-lived agent tasks, and they need measuring again on any other configuration. Kata Containers applies the same idea behind a standard container interface, running containers inside lightweight virtual machines.

Choosing by what the code can reach

The Kubernetes documentation gives the general rule: sandboxing is “often recommended when you are running untrusted code,” and “Virtual machines and userspace kernels are two popular approaches to sandboxing.” For agents, the difficulty is deciding when code counts as untrusted. Agent-generated code is shaped by everything in the agent’s context, so I would treat it as no more trustworthy than the least trusted content the agent has read: an issue, a pull request from a fork, a web page or a retrieved document.

I would choose the boundary from three situations.

  1. A developer’s agent working in the developer’s own repository. An OS-level sandbox with writes limited to the workspace and network access limited to an allowlist fits this case. The developer reviews the result, and I would expect the overhead of a container per task to discourage developers from switching any sandbox on. The risk to manage is the content the agent reads: if it browses the web or reads untrusted issues, network restrictions matter more than file restrictions.
  2. A CI pipeline or background agent processing external input. Here nobody reviews each step, and the input can come from outside the organization. An ephemeral container per run is the minimum, started as a non-root user, with user namespaces and the runtime’s default seccomp profile, no production credentials and an egress allowlist. If the pipeline serves several teams or processes public contributions, a userspace kernel or microVM is the better fit.
  3. A platform that runs code for many users or tenants. Code from one session must not be able to affect another session or tenant. That is the situation Kubernetes describes, and each session should get its own kernel boundary: a gVisor sandbox or a microVM, created per session and destroyed afterwards, in line with OWASP’s call to “Isolate per-session environments with permission boundaries.”

The choice also has to fit the workload. Code that makes many system calls may run poorly under a userspace kernel, and a microVM needs hosts with virtualization support. Both constraints are worth testing on a representative agent workload before committing to a platform.

Exhibit 2 The boundary is one control in an execution path that also gates, limits and records

Code proposed by an agent first passes a gate with static scans, an allowlist for automatic execution and human approval for elevated runs. It then runs in a sandbox, created per session where the boundary allows it, which allows writes only to a working directory, allows network access only to an allowlist, holds no standing credentials and does not run as root. Runs and file diffs are logged. The sandbox boundary can be an OS-level process sandbox, a container, a userspace kernel or a microVM, in increasing order of separation from the host kernel

Source: Author's diagram, based on OWASP Top 10 for Agentic Applications for 2026 (December 2025), ASI05 mitigations.

What the boundary does not do

A sandbox limits what code can do to the host; the access the sandbox itself is given remains open to that code, and three gaps follow.

Network egress. Unless the sandbox is configured with an allowlist, it can send out anything it can read. OWASP’s guidance pairs sandboxing with “strict limits including network access,” and the egress allowlist needs the same review as the boundary itself.

Credentials inside the sandbox. Tokens, cloud credentials and SSH keys placed in the sandbox for convenience are reachable by any code that runs there, whatever the boundary. Credentials should be issued per task, scoped to what the task needs, and kept out of the sandbox when the code does not need them.

Hardware and architecture. gVisor’s documentation states that “In general, gVisor does not provide protection against hardware side channels,” and its security model contains a sentence that applies to every option in Exhibit 1: “A sandbox is not a substitute for a secure architecture.”

The rest of the OWASP guidance covers the steps around execution: “static scans before execution,” separating “code generation from execution with validation gates,” requiring “human approval for elevated runs,” keeping “an allowlist for auto-execution under version control,” and the instruction to “log and audit all generation and runs.”

For an organization deploying agents that run code, the decision covers four points: which boundary each class of agent runs behind, what network and credentials each sandbox holds, who reviews the allowlists, and where the record of each run is kept.