Back to blog

AI Agent Sandbox Architecture: Secure Tool Execution & Code Sandboxing (2026)

How to create AI agent sandbox architecture diagrams for secure tool execution. Covers microVMs, container isolation, WASM sandboxes, network egress boundaries, resource limits, and human-in-the-loop approval gates — with AI prompt templates.

R
Ryan·Senior AI Engineer
·

AI agent sandbox architecture diagrams have become one of the most requested diagram types of 2026 as production agent systems move from “chat that calls a function” to autonomous loops that write and execute code, browse the web, and take real-world actions. Most agent systems now converge on a three-layer architecture — perception (ingesting context: files, retrieved docs, tool outputs), memory (persisting state across steps and sessions), and action (executing tools and code in the outside world). The action layer is the newest and least understood of the three, because it's the one where a mistake stops being a bad response and starts being a real-world incident — a deleted table, a leaked credential, or a runaway cloud bill. This guide covers how to diagram the sandboxing architecture that makes agent autonomy safe.

Why sandboxing matters

An agent with a code-execution tool or unrestricted API access is, functionally, an attacker with root — except the attacker is a language model that can be wrong in ways humans rarely are: hallucinated file paths, misremembered API semantics, or a prompt injected into a webpage, PDF, or tool response that hijacks the agent's next action. Without isolation, any of these can touch production systems, exfiltrate secrets to an attacker-controlled endpoint, or spin up compute in a loop until the bill is enormous. Sandboxing architecture exists to bound the blast radius: an agent can act freely inside the sandbox, but everything that crosses the sandbox boundary — filesystem writes, network calls, resource consumption, irreversible actions — is mediated, limited, and logged.

Core components of an AI agent sandbox architecture diagram

  • Agent runtime / orchestrator: The loop that calls the LLM, receives its proposed tool calls, and drives execution — LangGraph, a custom agent loop, or a managed runtime. Show it as the coordinator sitting outside the sandbox boundary, never inside it.
  • Tool-call interception / policy layer: Every tool call the model proposes passes through a policy engine before execution — an allow/deny list of tools and arguments, per-tool rate limits, and rules that route high-risk calls (payments, deletions, sending email) to an approval gate instead of executing immediately. This is the single most important box on the diagram: it's the choke point between “model intent” and “real-world effect.”
  • Sandboxed execution environment: Where code actually runs — a microVM (Firecracker, Cloud Hypervisor), gVisor's user-space kernel, a Docker container hardened with seccomp profiles and a read-only root filesystem, or a WASM runtime (Wasmtime, WasmEdge) for lighter-weight, language-level isolation. Label which one is in use; it determines the diagram's entire security story.
  • Filesystem / network egress boundary: By default the sandbox should have no outbound network access at all. Where egress is required (package installs, API calls the agent needs to make), show an explicit allowlist of domains or IPs enforced at the network layer (egress proxy, firewall rules, VPC security groups) — never trust the sandboxed process to self-restrict.
  • Resource limiter: CPU, memory, disk, and wall-clock timeout caps applied per sandbox instance, plus a step/iteration cap on the agent loop itself. This is what turns a hallucinated infinite retry loop into a bounded failure instead of a runaway bill.
  • Audit / observability layer: Every tool call, its arguments, the sandbox's stdout/stderr, and the result returned to the model should be logged to an immutable store (e.g., append-only log shipped to a SIEM or object storage) — both for post-incident forensics and for detecting prompt-injection patterns over time.
  • Human-in-the-loop approval gate: For irreversible or high-consequence actions — payments, production deploys, data deletion, sending external communications — the policy layer should pause and require explicit human approval (Slack prompt, dashboard confirmation, or a synchronous UI step) before the action executes.

Common sandbox implementation patterns

  • Ephemeral per-session microVM: A fresh microVM is spun up when a task/session starts and destroyed when it ends, so no state or credentials persist between tasks. This is the pattern used by E2B, Modal Sandboxes, and Daytona, and it's the default choice for coding agents that need near-full OS capability (installing packages, running test suites) without long-lived risk.
  • Shared multi-tenant container pool: A warm pool of containers is reused across many short-lived tasks for lower cold-start latency, with strict namespace, cgroup, and filesystem isolation between tenants (each container gets its own network namespace, no shared volumes, and is recycled — not just wiped — after suspicious activity). This pattern trades a slightly larger blast-radius risk (kernel-level container escape) for cost and latency efficiency at scale.
  • Browser / computer-use sandbox: For agents that control a UI, an isolated VM runs a real browser or desktop behind a virtual display (Xvfb, VNC), with the agent driving it via screenshots and simulated input rather than direct OS access. Session cookies, saved credentials, and downloaded files are scoped to the VM and destroyed with it.

Prompt examples for AI agent sandbox diagrams

Coding agent with ephemeral microVM and egress allowlist

"AI coding agent sandbox architecture. Agent runtime (LangGraph orchestrator) receives a task, calls the LLM, and proposes a tool call (run_shell_command). Tool call passes through a policy layer that checks the command against a denylist (no rm -rf on non-workspace paths, no curl to non-allowlisted hosts) before forwarding it. Execution happens inside a Firecracker microVM provisioned fresh per session (via E2B), with the repo checked out to /workspace only, a read-only root filesystem outside /workspace, and a 512MB memory / 2 vCPU / 10-minute wall-clock limit. Network egress is denied by default except for an allowlist: github.com, pypi.org, registry.npmjs.org, routed through an egress proxy that logs every request. All stdout/stderr and file diffs are streamed back to the orchestrator and written to an audit log in S3. microVM is destroyed after the session ends or the timeout is hit, whichever comes first. Show the boundary between orchestrator (untrusted-input-safe) and microVM (blast-radius-contained) clearly."

Multi-tenant SaaS agent platform with per-customer sandboxes

"Multi-tenant SaaS agent platform, one shared Kubernetes cluster serving code-execution requests for many customers. Each customer request is routed to a gVisor-sandboxed container (runsc runtime) drawn from a pre-warmed pool, with a dedicated network namespace, no shared filesystem or volume mounts between tenants, and a per-customer resource quota (CPU, memory, execution count per minute) enforced by the Kubernetes ResourceQuota and a rate limiter in front of the scheduler. Containers are tagged with tenant_id and torn down (not reused) after each execution to prevent cross-tenant data bleed. A policy layer sitting in front of the pool validates that requested packages/imports are on the tenant's approved list before scheduling. All executions are logged with tenant_id, code hash, resource usage, and exit code to a centralized audit store. Show the shared pool, tenant isolation boundaries, the quota enforcement point, and the audit pipeline."

Computer-use agent with isolated browser VM and payment approval gate

"Computer-use shopping agent architecture. Agent runtime sends screenshots of an isolated browser VM (Chromium running in a Firecracker microVM behind a virtual display) to the LLM, which responds with simulated mouse/keyboard actions (click, type, scroll). Actions are executed inside the VM only — no direct OS or host filesystem access. Session cookies and any entered credentials are scoped to the VM's ephemeral storage and wiped when the session ends. A policy layer inspects each proposed action: navigation and form-fill actions execute automatically; any action matching a 'checkout', 'confirm purchase', or 'submit payment' pattern is intercepted and routed to a human approval gate (push notification with a screenshot and order summary) that requires explicit user confirmation before the click is forwarded to the VM. All actions and the final approval decision are logged. Show the perception loop (screenshot → LLM → action), the VM isolation boundary, and the approval gate as a hard stop before payment actions."

MCP-based agent with a tool-call policy layer

"MCP-based agent architecture with centralized policy mediation. LLM orchestrator connects to multiple MCP servers (filesystem, Postgres, Slack, internal deploy tool) not directly, but through an MCP gateway/proxy that sits between the agent and every server. The gateway enforces: an allowlist of which MCP tools each agent identity may call, argument-level validation (e.g., Postgres tool blocks DROP/DELETE without a WHERE clause), per-tool rate limits, and routes any call to the deploy-tool MCP server to a human approval gate in Slack requiring a thumbs-up reaction before the call is forwarded. Every request/response pair is logged with the originating agent session ID and the MCP server name. Show the LLM, the MCP gateway as the single mediation point, the individual MCP servers behind it, and the approval gate branching off the deploy-tool path."

Comparing sandboxing approaches

ApproachIsolation strengthBest forLimitations
MicroVMs (Firecracker, gVisor)Very high — hardware-virtualized or user-space kernel boundaryUntrusted code execution, coding agents, multi-tenant platformsHigher cold-start latency; more operational complexity than containers
Docker containersModerate — shared host kernelFast iteration, internal tools, lower-risk trusted workloadsKernel-level escapes possible without seccomp/AppArmor hardening
WASM (Wasmtime, WasmEdge)High — capability-based, no ambient authority by defaultLightweight plugin execution, per-call sandboxing, edge deploymentLimited language/library support; not ideal for full dev environments
OS-level (seccomp, namespaces)Low to moderate — process-level restriction, no VM boundaryDefense-in-depth layered on top of containers/VMs, syscall filteringNot sufficient alone against a capable adversary; easy to misconfigure

What to annotate on an AI agent sandbox diagram

  • Resource limits: CPU, memory, disk, and wall-clock timeout per sandbox instance, plus the max iteration/step count for the agent loop itself.
  • Network egress rules: Whether egress is denied by default, and the explicit allowlist of domains/IPs if any calls are permitted — annotate the enforcement point (proxy, firewall, security group), not just the policy.
  • Approval gate triggers: Which specific actions or argument patterns route to a human approval step (payments, deletions, prod deploys, external comms), and who is authorized to approve.
  • Audit log destination: Where tool-call logs, sandbox stdout/stderr, and approval decisions are shipped — and whether the store is append-only/immutable.
  • Teardown / TTL policy: When a sandbox instance is destroyed — per-session, on timeout, or on suspicious activity — and whether state/credentials are wiped or persisted across sessions.
  • Credential scope: Which secrets the sandbox has access to, how they're injected (short-lived tokens vs. long-lived keys), and whether they're scoped per-tenant or per-session.

Related guides: computer-use architecture, MCP architecture diagrams, agentic AI security architecture, and multi-agent orchestration patterns.

Ready to try it yourself?

Start Creating - Free