Question-led guide · decision

What should be sandboxed: code, the browser, or the whole AI agent?

A threat-driven sandbox decision for code execution, browsers, tools, files, network, credentials, processes, time, persistence, and teardown.

Direct answer

Sandbox every component that processes untrusted instructions or can reach valuable resources, but choose boundaries by consequence. Isolate code execution, browser state, files, processes, network destinations, credentials, tools, time, and persistence according to the task. For hostile code, a stronger kernel or microVM boundary may be appropriate; browser isolation alone cannot contain separate tools or credentials. Rebuild and destroy sandboxes predictably.

AI agent sandbox model covering runtime files network and governed results
Containment model: Isolation must cover the surfaces that can carry authority: code, browser state, files, network, credentials, and persistence. This is an author-created explanatory model, not measured system evidence.

Scope

Use this decision for agents that execute generated code, browse untrusted sites, manipulate files, call tools, or install dependencies. The goal is to contain resources and effects. Content policy and prompt-injection detection remain additional layers.

Why it happens

Teams ask which component to sandbox as though code and browser were alternatives. An agent may read an untrusted webpage, write a script, execute it, open a file, call a network tool, and persist a memory in one task. The attack path crosses component names.

A sandbox also fails when it is isolated computationally but receives production credentials, writable shared volumes, unrestricted egress, or a long-lived home directory. The boundary is defined by resources and channels, not the virtualization logo.

Diagnosis

For each task class, list untrusted inputs and intended effects. Then enumerate resources: CPU/GPU, memory, processes, kernel, devices, filesystem, clipboard, browser profile, network destinations, metadata services, credentials, tools, artifact stores, and persistent memory.

Run escape-consequence questions:

  • If code gains the sandbox user, what can it read or change?
  • If the browser is compromised, which credentials and local services are reachable?
  • Can a tool bypass egress or file restrictions?
  • Does the task share state with another tenant or run?
  • What remains after timeout, crash, or teardown?

Solution

Create task-specific profiles. A documentation formatter may use a locked-down container with no network and a disposable volume. Untrusted package execution may require a stronger kernel boundary or microVM, allowlisted egress through a proxy, no ambient credentials, and immutable base images. Browser automation needs an isolated profile, download quarantine, navigation policy, and separation from host secrets.

Keep the policy engine, credential broker, and audit sink outside the worker sandbox. Give the worker capability handles only for approved resources and duration. Apply CPU, memory, process, storage, network, and wall-clock budgets. Destroy the environment after the task and verify cleanup.

Test with known malicious files, websites, dependency behavior, network scans, fork bombs, resource exhaustion, and teardown failures in a dedicated environment.

Artifact

Complete a sandbox profile per task tier:

Dimension Required decision
Untrusted inputs Prompt, page, code, package, file, tool result, or memory
Isolation Process, container, userspace kernel, microVM, VM, or remote service
Files Read-only base, writable paths, mounts, downloads, size, and persistence
Network Deny by default, allowlist, DNS/proxy, metadata endpoints, and bandwidth
Credentials/tools None by default; brokered, task-bound handles and operations
Compute CPU/GPU, memory, process, device, and wall-clock limits
Cross-tenant Namespace, caches, images, artifacts, and cleanup proof
Observability Metadata, security events, content-capture policy, and tamper resistance
Teardown Kill, revoke, wipe, verify, and quarantine on failure
Escape consequence Reachable assets, detection, containment, and response owner

Common mistakes

  • Treating a browser sandbox as containment for shell and tool calls.
  • Mounting host credentials or broad sockets into a disposable worker.
  • Allowing unrestricted egress because the filesystem is isolated.
  • Reusing writable state across tenants or tasks.
  • Declaring teardown complete without verifying processes, volumes, tokens, and external jobs.

Evidence

  1. Container security requires controls across image, registry, orchestrator, host, runtime, and lifecycle, and containers do not remove kernel risk.

    NIST SP 800-190 describes container technology risks and security recommendations across major components.

    Primary source · standard · checked Aug 26, 2026

    Limit: The 2017 guide predates LLM agents and does not compare current browser sandboxes, gVisor, microVMs, or agent workloads directly.

  2. MicroVM architecture can provide a deliberately small virtualization surface with workload isolation and operational trade-offs.

    The Firecracker NSDI paper describes the microVM design, security-oriented device model, performance, and production experience.

    Primary source · paper · checked Aug 26, 2026

    Limit: One system's design and measurements do not guarantee isolation or performance for every host, configuration, or agent threat.

  3. A sandbox profile should specify resources, ingress/egress, credentials, persistence, budgets, reset, and escape consequences rather than a component label.

    The matrix below maps task risks to actual isolation and teardown controls.

    Signal Studio author framework · reviewed Aug 26, 2026

    Limit: Boundary selection requires platform-specific threat modeling, hardening, patching, and adversarial testing.

Limitations

No sandbox is perfect. Kernel, hypervisor, browser, driver, side-channel, supply-chain, and orchestration vulnerabilities remain possible. Remote services and human-visible effects can escape computational isolation. Maintain defense in depth and an incident plan.

FAQ

Is a Docker container enough for generated code?
It may be adequate for some trusted, low-impact tasks after hardening, but containers share the host kernel. Choose the boundary from the code's trust level, reachable assets, escape consequence, and layered controls.
Should the model run inside the sandbox?
Often the model API is external while tools run in isolated workers. The orchestrator, credentials, policy engine, and artifact store still need separate trust boundaries; placing everything together can increase blast radius.

Continue within AI agent security, or use one of these adjacent diagnostics:

Editorial QA: automated native-English, structure, source-presence, and link checks completed . This record is not an independent expert endorsement. Review boundary.