Building-block guide · Tools and orchestration

Sandboxing and code execution

How to isolate agents that run code, browse or operate computers: choosing an isolation boundary, hosted or self-run sandboxes, egress and filesystem scope, keeping secrets out, resource limits, session lifetime and the supply chain of packages an agent installs.

Draft for review · researched 30 Nov 2026

Contents
  1. At a glance
  2. Scope and where it sits
  3. When to use what
  4. Decision criteria
  5. Reference patterns
  6. Recommended defaults
  7. Anti-patterns
  8. Sizing and cost notes
  9. Security and compliance hooks
  10. Test and eval checklist
  11. Related plan sections and inventory
  12. Unverified or needs review
  13. Sources

At a glance

  • Assume any code an agent writes or any page it reads can be hostile. The sandbox is the control that still holds when prompt-injection defences fail.
  • Isolation strength runs from shared-kernel containers, through user-space kernels (gVisor), to microVMs and lightweight VMs (Firecracker, Kata, Hyper-V). For untrusted, agent-generated code, default to a microVM or gVisor, as plan section 10C requires for A4 agents and anything that runs code, browses or reads untrusted content [4] (10C).
  • Filesystem and network isolation are both needed. Without network isolation a compromised agent can exfiltrate files; without filesystem isolation it can escape and reach the network [7].
  • Deny egress by default and allow-list destinations through a proxy. NVIDIA's guidance lists network egress controls as a mandatory control [4].
  • Never put long-lived secrets inside the sandbox. Inject short-lived, scoped credentials from a broker, or have a proxy outside the sandbox add them to outbound requests [4][7][10].
  • Prefer ephemeral sandboxes per task. If you must persist, snapshot deliberately, set idle and maximum lifetimes, and recreate on a schedule [4][11].
  • Agents install packages. LLMs hallucinate package names (5.2% for commercial models and 21.7% for open-source models in one study), which attackers can register [17]. Route installs through a vetted mirror.
  • Browser and computer-use agents need their own VM or container with a domain allow-list, no sensitive data and human confirmation for consequential actions [8].

Scope and where it sits

This guide covers where agent-executed code, shell commands, browser sessions and desktop automation run, and the boundaries around them: kernel isolation, filesystem, network, credentials, resources and lifetime. It also covers the packages and binaries that agents pull into those environments.

In the 10-layer reference architecture, sandboxes are part of layer 4, Agent runtime and durable execution (where steps execute), are reached as tools in layer 8, Tools and integration (code interpreter, browser and computer-use tools), and are a control in layer 9, Trust, safety and policy. In the Anatomy crosswalk the primary system is the Immune system (containment of hostile input and code), with Hands (tools that act) and Habitat (network placement and segmentation).

Covered elsewhere:

When to use what

Option Use when Avoid when Cost/latency notes
OS-level process sandbox (bubblewrap, Seatbelt, sandbox-runtime) Coding agents on a developer machine or CI runner; trusted code with untrusted inputs [7] Fully untrusted code on shared infrastructure; shared kernel Near-zero start-up; reduced permission prompts by 84% in one deployment [7]
Standard container (runc) Trusted, reviewed code; build steps Agent-generated code, browsing, untrusted content Fastest; shares host kernel, so kernel bugs reach the host [13]
gVisor (user-space kernel) Untrusted code where container ergonomics matter; Kubernetes via RuntimeClass [2][16] Syscall-heavy or exotic workloads; not every syscall is implemented [2] Lower fixed cost than VMs, higher per-syscall overhead [2]
Firecracker microVM Multi-tenant untrusted code at scale; per-task VMs [1] Workloads needing GPUs or broad device support (only a few emulated devices) [1] Boots in under 125 ms with under 5 MiB overhead per VM [1]
Kata Containers (lightweight VM) Kubernetes pods that need VM isolation with OCI and CRI compatibility [3] Teams without capacity to run a VM-based runtime Dedicated kernel per pod; choice of hypervisor [3]
WebAssembly in the user's browser Light data analysis or plotting on the client side; no server execution wanted [5] Native libraries, long jobs, server-side data No server sandbox cost; limited packages [5]
Managed code interpreter (cloud or model provider) Data analysis and file transforms with low ops effort [9][14][15] Need for custom network, images or residency the service cannot meet Per-session or per-use pricing; fixed limits per service
Hosted sandbox platform (open-source or paid) Agent products needing many fast, isolated sandboxes with snapshots and SDKs [10][11][12] Data that may not leave your boundary unless self-hosted Per-second or active-CPU billing; check concurrency limits
Dedicated browser or desktop VM Browser use and computer use [8] Sessions holding personal or production credentials Heavier than code sandboxes; screenshots add tokens

Decision criteria

  1. Who wrote the code? Human-reviewed code can run in containers. Agent-written code or code influenced by untrusted content needs microVM, Kata or gVisor isolation [4] (10C).
  2. Does the agent read untrusted content? Email, web pages, tickets and uploaded files count. If yes, treat the sandbox as hostile and cut its route to internal networks (10C).
  3. Does it need the network? Most code-interpreter tasks do not; the Claude code execution tool, for example, has no internet access [9]. Grant egress only to named destinations through a proxy [4].
  4. What data enters the sandbox? Restricted or personal data rules out shared hosted services unless contracts and residency allow it; some managed tools are not eligible for zero-data-retention or HIPAA arrangements [9].
  5. What must persist? Nothing: ephemeral. A workspace across turns: a session with idle timeout. Days or weeks: snapshots or volumes with scheduled recreation [4][10][11].
  6. What credentials does the task need? If any, broker short-lived scoped tokens or inject them at a proxy outside the sandbox; never mount long-lived keys [4][7].
  7. Self-run or hosted? Self-run (Firecracker, Kata, gVisor, Kubernetes Agent Sandbox) for residency and network control; hosted for speed of delivery and scale [16]. Inventory: Sandboxing and code execution.
  8. What autonomy tier is the agent? A3 and A4 agents must run in ephemeral, isolated sandboxes without standing credentials (14).

Reference patterns

1. Ephemeral microVM per task

Problem. Agent-generated code may contain mistakes or attacker-chosen commands; a shared kernel lets a single kernel bug cross tenants.

How it works. Each task gets a fresh microVM or gVisor sandbox from a warm pool, with a read-only base image, a scratch workspace, no internal network route and no standing credentials. Results leave through a defined output channel; the sandbox is destroyed at the end. Firecracker is designed for this: a minimal device model, a jailer process, and up to 150 microVMs per second per host [1]. The Kubernetes Agent Sandbox project offers Sandbox, SandboxTemplate, SandboxClaim and SandboxWarmPool resources and uses gVisor or Kata through RuntimeClass [16]. A hosted provider's write-up on a 2026 Linux kernel page-cache flaw (CVE-2026-31431) shows why: it was dangerous in shared-kernel environments, while a per-sandbox microVM with its own kernel contained it [13].

When to use. Code interpreters, data-analysis agents, any A3 or A4 agent, anything that reads untrusted content.

Pitfalls. Warm pools that reuse sandboxes across users; base images with credentials or SSH keys baked in; metadata endpoints reachable from inside.

2. Default-deny egress through an allow-list proxy

Problem. The fastest way to exfiltrate data is an outbound HTTP request, a DNS lookup or a rendered image link.

How it works. The sandbox has no direct route out. All traffic goes through a proxy that allows only named domains (package mirror, specific APIs), blocks private and link-local ranges and cloud metadata addresses, logs every request, and can inject credentials so they never enter the sandbox [4][7][18]. Claude Code's sandbox routes network access through a proxy outside the sandbox, and its web sandbox keeps git credentials outside, adding them in the proxy [7]. The MCP security guidance recommends blocking private ranges and using an egress proxy such as Smokescreen against request forgery [18].

# Illustrative egress policy (generic)
default: deny
allow:
  - host: pypi-mirror.internal.example   # vetted package mirror
  - host: api.partner.example
    methods: [GET]
deny_ranges: [10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, 169.254.0.0/16, 127.0.0.0/8]
dns: resolve-via-proxy-only
log: all
credentials: inject-at-proxy   # sandbox never sees the token

When to use. Every sandbox that needs any network access.

Pitfalls. Allowing whole cloud or code-hosting domains, which lets an attacker host a payload or upload data there; DNS resolution inside the sandbox (a DNS tunnel); forgetting non-HTTP protocols.

3. Scoped filesystem with protected configuration

Problem. An agent with write access to its own configuration, hooks or tool definitions can persist an attack or switch its own controls off.

How it works. Mount only the task's workspace read-write; mount everything else read-only or not at all. Block writes to agent configuration, hooks, skills and MCP configuration files at OS level, not just by prompt [4]. Enforce at OS level so spawned subprocesses inherit the restriction; NVIDIA lists blocking writes outside the workspace as mandatory and recommends sandboxing the whole IDE and every spawned process [4]. Open-source agent runtimes such as NVIDIA's OpenShell apply one policy across the filesystem, network and process layers [6].

When to use. Coding agents, agents with repositories or shared drives, any agent that runs a shell.

Pitfalls. Writable home directories with shell profiles or package manager configuration; symlinks that leave the workspace; approvals cached for later commands (NVIDIA advises never caching approvals) [4].

4. Secrets broker outside the sandbox

Problem. Agents need to call APIs, but anything in the sandbox's environment or filesystem can be read and leaked by injected code.

How it works. The sandbox gets either nothing, or a short-lived token scoped to one task, issued by a broker against the agent's identity (10A). Better still, the egress proxy attaches credentials to allowed requests, so the sandbox never holds them [7]. Hosted platforms increasingly offer brokered or injected credentials and short-lived OIDC tokens for workload identity [10][11]. Approve with the minimum scopes and expire on task end.

When to use. Any sandbox that calls an authenticated service.

Pitfalls. Environment variables holding provider keys; long-lived cloud keys in images; tokens logged in command output.

5. Isolated browser and computer-use session

Problem. Browsing and desktop agents read untrusted pages, and a page can instruct the agent to click, download or submit.

How it works. Run the browser or desktop in a dedicated VM or container with minimal privileges, no sensitive data and no logged-in personal accounts, restrict reachable domains with an allow-list, and require a human to confirm actions with real-world consequences or that accept terms [8]. Provider classifiers that scan screenshots for injected instructions help, but the documentation itself says they are not a replacement for a human in the loop [8].

When to use. Web research, form filling, legacy application automation.

Pitfalls. Reusing a browser profile with saved passwords; letting the agent download and open files on the host; no recording of sessions for audit.

6. Vetted package supply

Problem. Agents install packages on request, may invent names that attackers have registered, and pull from public registries with no review.

How it works. Point package managers inside the sandbox at an internal mirror or proxy that allows only approved packages and versions, with malware scanning and a quarantine for new packages. A study of 576,000 generated code samples from 16 models found 205,474 unique hallucinated package names; hallucination rates averaged 5.2% for commercial and 21.7% for open-source models [17]. Pre-build images with common libraries so agents rarely install at all.

When to use. Every sandbox that can run pip, npm or similar.

Pitfalls. Allowing direct registry egress "temporarily"; trusting install scripts; no record of what was installed per run.

Setting Default Range or options Why
Isolation for agent-generated code MicroVM (Firecracker, Kata) or gVisor Container only for human-reviewed code Plan 10C; full virtualisation preferred over shared kernel [4]
Network No egress Allow-listed destinations via proxy Mandatory control [4]
Private ranges and metadata endpoints Blocked None Request forgery defence [18]
Filesystem Workspace read-write; rest read-only or absent Per task Mandatory control [4]
Agent config, hooks, skills, MCP config Not writable by the agent None Mandatory control [4]
Credentials in sandbox None; inject at proxy or broker short-lived tokens Task-scoped token, minutes to hours Sourced [4][7]
Session lifetime Ephemeral per task Session with idle timeout; snapshots for longer Sourced recommendation [4]; plan 10C
Idle timeout 5 to 15 minutes Up to service maximum Practitioner default; services default to 5 to 15 minutes [11][14]
Maximum lifetime 1 hour Up to 24 hours on hosted platforms [11][12] Practitioner default
Persistent environments Recreated at least weekly Daily for high-risk agents Sourced example of periodic recreation [4]
CPU and memory 1 vCPU, 2 to 4 GB Size per workload Practitioner default; one managed tool uses 1 CPU and 5 GiB [9]
Execution time per command 60 to 120 seconds Longer for batch jobs via async Practitioner default
Package installs Internal mirror only Pre-built images Hallucinated package risk [17]
Approval caching Never cache approvals None Sourced [4]
Logging Every command, file write and egress request Retained per audit policy Plan section 10 controls; practitioner default

Anti-patterns

  • Running agent-generated code in the application container. Fix: separate sandbox per task with no route to the application network.
  • Relying on a standard container for untrusted code. Fix: gVisor, Kata or microVMs; shared-kernel flaws cross containers [13].
  • Filesystem isolation without network isolation, or the reverse. Fix: both, always [7].
  • "Temporary" open egress for package installs. Fix: internal mirror; egress allow-list.
  • API keys in environment variables. Fix: broker or proxy injection, short-lived tokens [4][7].
  • Long-lived sandboxes that accumulate state and tools. Fix: ephemeral by default; scheduled recreation [4].
  • Letting the agent edit its own hooks or configuration. Fix: OS-level write protection on those paths [4].
  • Browser agents in a profile with personal sessions. Fix: dedicated VM with no saved sign-ins and a domain allow-list [8].
  • Caching a user's approval for a command class. Fix: approve per action or per plan; never cache [4].
  • Assuming the provider's sandbox meets data obligations. Fix: check retention, residency and certification eligibility per tool [9].
  • No record of what ran. Fix: command, file and egress logs tied to the run trace.

Sizing and cost notes

  • Start-up. MicroVMs can boot in under 125 ms [1]; warm pools hide most remaining start-up time [15][16]. Expect user-visible latency to come from package installs and data loading, not boot.
  • Density. Firecracker reports under 5 MiB memory overhead per VM and creation of up to 150 microVMs per second per host [1]. Your workload memory dominates.
  • Hosted pricing example. One hosted sandbox provider's own example for 1 vCPU and 2 GB in one region is about USD 1.05 a day for an idle persistent sandbox and USD 4.09 a day for a fully busy one under active-CPU billing [10]. Illustrative: 200 analysts each holding one persistent sandbox that is busy two hours a day would cost very roughly USD 1.05 × 22/24 + 4.09 × 2/24 ≈ USD 1.30 per analyst-day, about USD 5,700 a month for 200 analysts over 22 working days (weekends ignored). Check current rates.
  • Managed tool limits. Example limits from providers: one model-provider tool gives 5 GiB RAM, 5 GiB disk and 1 CPU, expires containers 30 days after creation and checkpoints after about 5 minutes idle [9]; one cloud interpreter defaults to 15 minutes and allows up to 8 hours per session [14]; one hosted platform defaults to 5 minutes with a 24-hour maximum [11]; another allows 24 hours of continuous run on its paid tier and 1 hour on its free tier [12].
  • Hidden costs. Egress proxy capacity, mirror storage, log retention and image builds. Screenshots for computer use add model tokens per step.

Security and compliance hooks

Threat OWASP mapping Control
Agent runs attacker-chosen code ASI05 Unexpected code execution [19]; LLM05 Improper output handling MicroVM or gVisor, no internal route, resource limits
Exfiltration via network LLM02 Sensitive information disclosure; lethal trifecta [20] Default-deny egress, proxy logs, DLP on egress
Credential theft from sandbox ASI03 Identity and privilege abuse No standing secrets; proxy injection; short-lived tokens
Malicious or hallucinated packages ASI04 Agentic supply chain; LLM03 Supply chain Internal mirror, allow-list, scanning [17]
Persistence via config or hooks ASI06 Memory and context poisoning; ASI10 Rogue agents Read-only config paths; ephemeral sandboxes [4]
Browser or GUI injection drives harmful clicks ASI01 Agent goal hijack; LLM01 Prompt injection Isolated VM, domain allow-list, human confirmation [8]
Runaway compute LLM10 Unbounded consumption CPU, memory, time and process limits; budgets (14A)
Request forgery to internal services ASI02 Tool misuse Block private ranges and metadata endpoints [18]

Data protection. Treat the sandbox as a processing location: record where it runs, what data enters, how long workspaces and snapshots persist, and whether the provider retains inputs. Minimise data copied in; mount read-only views rather than full extracts.

Audit evidence to keep. Sandbox image digests and policies per release, egress allow-lists and change history, per-run command and egress logs, credential issuance records, package install records, and results of escape and exfiltration tests.

Governing plan sections. 10 Security (sandboxing and egress controls), 10A Identity (no standing credentials), 10B Cedar (which agents may call execution tools), 10C Network topology (autonomy-tier segmentation, NET controls), 11 (data protection), 13 (registry records the sandbox profile per agent), 14 and 14A (envelopes and kill switch), and ROE (to be defined, plan section 12) for what agents may run at all.

Test and eval checklist

  • [ ] Isolation profile (Design). Each agent's sandbox profile (runtime, network, filesystem, credentials, lifetime) recorded in the registry. Pass: profile exists and matches the autonomy tier.
  • [ ] Escape tests (Test). Known container escape techniques and kernel exploit probes. Pass: none reach host or neighbours.
  • [ ] Egress tests (Test). Attempt HTTP, DNS, raw socket and non-allow-listed hosts. Pass: all blocked and logged.
  • [ ] Metadata and private ranges (Test). Attempt cloud metadata and RFC 1918 addresses. Pass: blocked.
  • [ ] Filesystem scope (Test). Write outside workspace, follow symlinks, edit hooks and agent config. Pass: denied at OS level.
  • [ ] Secret scan (Test). Search environment, filesystem and process list for credentials. Pass: none found.
  • [ ] Injected exfiltration (Test). Untrusted document instructs code to send data out. Pass: no data leaves.
  • [ ] Resource limits (Test). Fork bomb, memory exhaustion, infinite loop, disk fill. Pass: contained, sandbox terminated, host unaffected.
  • [ ] Package hallucination (Test). Request an install of a non-existent or typosquatted package. Pass: mirror refuses.
  • [ ] Lifetime (Release). Idle and maximum lifetimes enforced; snapshots expire as configured. Pass: verified in staging.
  • [ ] Tenant separation (Release). Two users' sandboxes cannot see each other's files or processes. Pass: verified.
  • [ ] Browser isolation (Release). Browser agent profile has no saved sign-ins; domain allow-list enforced. Pass: verified.
  • [ ] Logging (Release). Commands, writes and egress appear in the run trace. Pass: 100% coverage in test.
  • [ ] Kill switch (Run). Terminate all sandboxes for an agent on demand. Pass: within agreed time.
  • [ ] Patch cadence (Run). Host kernels, hypervisors and base images patched per policy. Pass: within SLA.
  • [ ] Recreation (Run). Persistent environments rebuilt on schedule. Pass: no environment older than policy.

Governing policies and procedures

From the CoE policy set (draft; control IDs on the policy crosswalk):

Unverified or needs review

  • E2B's public docs pages did not state the isolation technology; it is taken from E2B's own security article [13]. E2B limits [12] were read from its docs index and should be rechecked against the current pricing page.
  • The Vercel Sandbox cost example [10] is the provider's own illustration; the 200-analyst calculation is illustrative arithmetic, not a quote.
  • The Kubernetes Agent Sandbox project is still in development; the version seen in its samples (v1.0.2) should be confirmed before adoption [16].
  • NVIDIA OpenShell [6] was described as an early preview in March 2026; current maturity not rechecked.
  • The plan states that Model Armor fails open in regions where it is unavailable; this is not re-verified here and matters for egress screening in those regions.
  • The lethal trifecta reference [20] is taken from CoE research notes, not reopened for this guide.
  • Idle timeout, maximum lifetime, CPU, memory and per-command time defaults are practitioner defaults for the CoE lead to calibrate against workloads.
  • Azure Container Apps dynamic sessions pricing and limits were not captured; only isolation and pooling behaviour were verified [15].

Sources

  1. Firecracker. Firecracker project. https://firecracker-microvm.github.io/, accessed 30 Nov 2026.
  2. gVisor documentation. gVisor project. https://gvisor.dev/docs/, accessed 30 Nov 2026.
  3. Kata Containers. OpenInfra Foundation. https://katacontainers.io/, accessed 30 Nov 2026.
  4. Practical security guidance for sandboxing agentic workflows and managing execution risk. NVIDIA Technical Blog (30 Jan 2026, updated 5 Mar 2026). https://developer.nvidia.com/blog/practical-security-guidance-for-sandboxing-agentic-workflows-and-managing-execution-risk, accessed 30 Nov 2026.
  5. Sandboxing agentic AI workflows with WebAssembly. NVIDIA Technical Blog (16 Dec 2024). https://developer.nvidia.com/blog/sandboxing-agentic-ai-workflows-with-webassembly/, accessed 30 Nov 2026.
  6. Secure autonomous AI agents with OpenShell. NVIDIA Blog (23 Mar 2026). https://blogs.nvidia.com/blog/secure-autonomous-ai-agents-openshell, accessed 30 Nov 2026.
  7. Beyond permission prompts: making Claude Code more secure and autonomous. Anthropic Engineering (20 Oct 2025). https://www.anthropic.com/engineering/claude-code-sandboxing, accessed 30 Nov 2026.
  8. Computer use tool. Claude Platform documentation, Anthropic. https://platform.claude.com/docs/en/agents-and-tools/computer-use, accessed 30 Nov 2026.
  9. Code execution tool. Claude Platform documentation, Anthropic. https://platform.claude.com/docs/en/agents-and-tools/tool-use/code-execution-tool, accessed 30 Nov 2026.
  10. Vercel Sandbox. Vercel documentation. https://vercel.com/docs/vercel-sandbox, accessed 30 Nov 2026.
  11. Sandboxes. Modal documentation. https://modal.com/docs/guide/sandbox, accessed 30 Nov 2026.
  12. E2B documentation. E2B. https://e2b.dev/docs, accessed 30 Nov 2026.
  13. Not affected by Copy Fail: here's why. E2B (30 Apr 2026). https://e2b.dev/resources/not-affected-by-copy-fail-heres-why, accessed 30 Nov 2026.
  14. Code Interpreter tool. Amazon Bedrock AgentCore Developer Guide, AWS. https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-tool.html, accessed 30 Nov 2026.
  15. Dynamic sessions in Azure Container Apps. Microsoft Learn. https://learn.microsoft.com/azure/container-apps/sessions, accessed 30 Nov 2026.
  16. Agent Sandbox. Kubernetes SIG Apps, GitHub. https://github.com/kubernetes-sigs/agent-sandbox, accessed 30 Nov 2026.
  17. Spracklen et al., We have a package for you! A comprehensive analysis of package hallucinations by code generating LLMs. arXiv 2406.10279 (USENIX Security 2025). https://arxiv.org/abs/2406.10279, accessed 30 Nov 2026.
  18. Security best practices. Model Context Protocol. https://modelcontextprotocol.io/docs/tutorials/security/security_best_practices, accessed 30 Nov 2026.
  19. OWASP Top 10 for Agentic Applications (2026 edition, released 9 Dec 2025). OWASP GenAI Security Project. https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/, accessed 30 Nov 2026.
  20. The lethal trifecta for AI agents. Simon Willison (16 Jun 2025). https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/, accessed 30 Nov 2026 (via CoE research notes).
↑