Guides · ← All guides
AI Agent Sandboxing: What to Isolate, and What a Sandbox Cannot Do
By the Ingenious AI team · Published: November 14, 2026 · Reviewed: November 14, 2026 · 8 min read
The short answer
Sandbox the four surfaces an agent can hurt you through: filesystem (only the work directory exists), network (only allowlisted destinations resolve), execution (no shell beyond the tools it needs), and credentials (short-lived, job-scoped, injected at call time). Then be clear about the limit: a sandbox decides where the agent runs, not what it may do — an agent with legitimate access to the customer database and the mail tool can exfiltrate from inside a perfect sandbox, using only permitted paths. Rogue-Agent Defense therefore treats sandboxing as the floor and policy verdicts as the walls: isolation contains accidents, policy contains intent.
Generate a free canary token → No signup, nothing stored: plant a tripwire where your agent works while you read — most controls in this guide start working the moment a canary, a policy check, or a spend cap is in place.
What is AI agent sandboxing? running an agent inside an isolated environment — restricted filesystem, network, processes and credentials — so that even a fully compromised agent process can only reach what the sandbox boundary exposes.
The filesystem: a room with one door
Give the agent a working directory and nothing else: no home directory wanderings, no sibling projects, no mounted secrets folders it might summarise into a reply. Read access and write access are separate grants — most agents need to write outputs and read one input tree, and the overlap between those trees should be deliberate. Temporary space should be genuinely temporary: wiped between runs, so a persistence plant has nowhere to live — the memory attack in red-teaming gets much harder when yesterday's files are gone.
Watch the quiet escalations: a log directory that grows into an archive of customer data, a cache that mirrors the production database for speed. Sandboxes fail by accretion more than by assault; audit the mounts quarterly against the job description.
The network: destinations as a whitelist, not a hope
Inside a sandbox, network policy is concrete: a proxy or firewall rule set naming the hosts the job needs — the CRM API, the mail service, the two data sources — and denying everything else, including arbitrary DNS-resolved surprises. This is the same default-deny logic as egress allowlists, enforced at the environment layer where the agent cannot argue with it.
Two details separate real network sandboxes from decorative ones. First, metadata and internal addresses — cloud instance metadata, localhost admin panels, the office printer's web UI — must be explicitly unreachable; injected agents probe them early. Second, the sandbox's own update and telemetry channels should not become a general-purpose tunnel: pin them to vendor hosts, and alert when their traffic shape changes.
Execution: tools instead of a shell
A general shell inside the sandbox is a sandbox with a master key: from a shell, the agent can re-implement any tool it was denied, encode any payload, and reach any mounted path. Replace shell access with the specific tools the job needs — a fetch tool, a query tool, a document tool — each mediated, logged and scoped. Where code execution is genuinely the job (data analysis, transformations), run it in a nested sandbox: no network, ephemeral filesystem, CPU and time limits, outputs returned as files for inspection.
Code execution also draws the line for MCP servers: a tool server that offers a shell should be treated as offering every capability a shell implies, whatever its description promises. Capability is what the tool can do, not what it says it is for.
Credentials: just-in-time, just-enough
The sandbox should hold no standing secrets. Inject credentials at call time from a broker: the agent's request to the boundary carries its identity, the boundary attaches the scoped credential for that one call, and nothing the agent can read contains a reusable key. This is the architecture that makes keeping keys out of context practical rather than aspirational, and it shrinks incident rotation to the broker's own records.
Where a tool genuinely requires a resident credential, make it short-lived and single-purpose: hours, not months; one service, one dataset, read-only unless writes are the job. A stolen eight-hour read token is an incident; a stolen standing admin key is a quarter.
What a sandbox cannot do
Be honest in the design doc: a sandbox cannot stop an agent from misusing access it legitimately has. The support agent must read tickets and send replies; both capabilities are inside the fence, and an injection that steers them harms through the front gate. That is why the layers compose: sandbox for environment, data boundaries for what classes may move where, policy verdicts for which actions execute, canaries for proof when something crosses.
Judge a sandbox proposal by its failure story. If the vendor or the design cannot say what happens on the day the agent inside is fully hostile — which calls it can still make, what data it can still reach, how fast you would know — the sandbox is a diagram. The failure story is the product.
Five actions to take today
- Map the four surfaces. Filesystem, network, execution, credentials — write what each agent can reach today on each.
- Cut the filesystem to the job. One work directory, split read and write grants, temp space wiped between runs.
- Whitelist the network at the proxy. Named hosts only, internal and metadata addresses explicitly denied.
- Remove the shell. Replace general execution with mediated tools; nest any real code execution with no network.
- Broker the credentials. Inject scoped keys at call time; resident keys short-lived, single-purpose, read-only by default.
A worked example: the analyst agent at Fjord Analytics
The following is a fictional example built from real threat classes and controls. The company and numbers are invented; the mechanics are not.
Fjord Analytics, a 28-person data consultancy, runs an agent that takes client CSVs, runs Python transformations and returns cleaned datasets. It is the highest-risk shape there is: arbitrary code, client data. Their sandbox: an ephemeral container per job, the input CSV mounted read-only, a results directory the only writable path, no network at all during execution, and a 20-minute lifetime.
In June, a client file arrives with a surprise: a second sheet whose cells contain an encoded payload that assembles into an instruction — fetch a remote script and run it against the environment. Inside the job, the decoded instruction executes its fetch into a wall: no network route exists. It tries the filesystem next and finds exactly one CSV and an empty results folder. The run's anomaly — a network attempt from a no-network job — pages the team with the full trail.
The contrast case is the same agent on a developer's laptop profile, which Fjord tested in a drill the same month: the payload reached a home directory, a cloud metadata address and two resident keys before the drill was stopped at minute six. Same model, same payload; the sandbox was the entire difference between a page and a breach notification.
Frequently asked questions
What is AI agent sandboxing?
Running the agent in an isolated environment that restricts what it can reach: a scoped filesystem, a whitelisted network, mediated execution instead of a shell, and short-lived job-scoped credentials injected at call time. Even a fully compromised agent process is then limited to what the boundary exposes.
Does a sandbox stop prompt injection damage?
It stops the environmental part: no wandering the filesystem, no arbitrary destinations, no resident keys to steal. It cannot stop misuse of legitimate access — an agent allowed to read the database and send mail can be steered through those permitted paths. Sandboxing is the floor; policy verdicts, data boundaries and egress control are the walls.
Should an AI agent have shell access?
Almost never a general one. A shell lets the agent re-implement denied tools and reach anything mounted. Provide the specific mediated tools the job needs instead; where code execution is the job, nest it — no network, ephemeral files, time and CPU limits, outputs inspected before release.
How should credentials work inside a sandbox?
Ideally they should not be inside at all: a broker at the boundary attaches the scoped credential to each call, so nothing readable in the environment is a reusable secret. Where a resident credential is unavoidable, keep it short-lived, single-service and read-only unless writes are the job.
How do you test whether a sandbox is real?
Attack it: run a hostile-payload drill and record what the payload could reach — network, files, metadata addresses, keys — and how fast the attempts alerted. Judge the design by its failure story; if nobody can state what a fully hostile agent inside can still do, the sandbox is a diagram, not a control.
Related guides
- Contain Prompt Injection in Production — the layers that compose with isolation.
- Keep API Keys Out of Your Agent's Context — the credential broker pattern in practice.
- Agent Permission Scoping — scoping as the sandbox's companion discipline.
- AI Agent Egress Control — network whitelisting at the boundary layer.
- MCP Server Security for AI Agents — why a shell tool negates a sandbox.
- AI Agent Data Boundary Rules — governing the legitimate access a sandbox cannot.
Generate a free canary token → No signup, nothing stored: plant a tripwire where your agent works, and let the next rogue action announce itself.