Sandbox Boundaries for AI Agents: Isolate Network, Files and Keys
How to isolate an AI agent's network access, file system and credentials, so one faulty run cannot reach production systems. Practical steps and checks.

An AI agent sandbox is an isolated runtime where an agent can read, compute and write only inside boundaries you set in advance: which network destinations it can reach, which folders it can see, and which credentials it can use. The goal is that a wrong step in one run stays inside the sandbox instead of reaching billing, CRM or customer records. This guide shows how to draw those three boundaries before the agent touches anything real.
Key takeaways
- Define the three boundaries, network, files and keys, before connecting any business tool.
- Allow outbound traffic only to named hosts, and test that every other destination fails.
- Give each run its own scratch space, read-only reference data and a size limit on outputs.
- Keep credentials out of prompts and files, scope them to sandbox resources, and make them short-lived.
- Prove each boundary with tests that try to cross it, and repeat those tests after every change.
Why one bad run should not reach production
Agents fail in ordinary ways. A step is misread, a tool returns a format nobody expected, a loop repeats an action, or a web page or document contains text written to steer the model. None of these require a dramatic attack. What they share is reach: a run can touch whatever its credentials and network path allow. A sandbox reduces that reach before anything goes wrong, so the useful question changes from whether the agent will behave to what it could touch if it does not.
OWASP guidance on prompt injection makes the same point from the security side: instructions can arrive through any content the model reads, so defenses should not depend only on the prompt. Boundaries enforced outside the model, by the network, the file system and the identity layer, still hold when the model is persuaded to do the wrong thing. Write each boundary as a property of the environment, not as a sentence in the system prompt.
Network: allow named destinations and deny the rest
Start by denying all outbound traffic, then open named hosts for the APIs the role actually needs. Use exact hostnames rather than wildcards, and prefer a staging endpoint or a read-only gateway over a direct production host. If a production action is genuinely needed, route it through a service you control that applies its own rules, so the agent calls one narrow function instead of the whole API.
Watch redirects and name resolution as well. An allowed domain that redirects to an arbitrary host, or an agent that fetches a raw IP address, can bypass a list of names. Block both by default.
- Outbound rules list exact hostnames, with no wildcards.
- Redirects are not followed to hosts outside the list.
- Raw IP addresses are blocked for every run.
- Production hostnames are absent unless a named gateway mediates them.
- Each blocked attempt is logged with the run identifier and the destination.
Agents that execute code need the same discipline plus process-level limits, which are covered in sandbox checks for agents that run code.
Files: give each run a workspace, not a drive
Each run should receive a fresh working directory that exists only for that run and is removed when it ends. Reference material enters as read-only copies or read-only mounts. The run has no access to a home directory, the root of a shared drive, other agents' workspaces, or configuration files that contain credentials.
Outputs leave the sandbox through an outbox, not by writing directly into shared locations. A separate step checks the outbox for file type, size, expected structure and leftover secrets, then decides what gets promoted. An outbox also makes partial failure visible: a run that stops halfway leaves a folder that can be inspected and discarded.
Illustrative scenario: a team uses an agent to draft a weekly summary from exported reports. The agent reads a read-only copy of the exports and writes drafts to its outbox. A person reviews the drafts and moves approved ones to the shared folder. If the run fails after writing only some of the drafts, the shared folder is unchanged and the outbox shows exactly where the run stopped.
Keys: let the agent use credentials without seeing them
Give each agent its own named identity. A shared administrator login cannot be scoped, audited or revoked without affecting everything else. The guidance on service accounts for agents explains why the identity should be created before the first integration.
Credentials should enter a run at start time from a secrets store, and they should never be written into prompts, configuration files, memory notes, logs or outputs. Use tokens that cover only the sandbox resources the role needs, that expire within a short session, and that can be revoked in one step. Keep read and write credentials separate, so a run that only reads cannot hold a token capable of posting records.
- Each agent runs under its own identity.
- Tokens are issued per session and expire on their own.
- Staging and production credentials live in separate stores.
- Logs and outputs are scanned for secret patterns before they are kept.
- Revocation is a single documented step, and it has been tested.
A step-by-step plan for setting the boundaries
The order below forces the role definition to come before any technical setup. Skipping ahead to configuration is the most common reason boundaries end up too wide.
- First, list the tools the agent needs and the exact actions for each one: read, draft, write or approve.
- Second, map every action to one host, one folder and one identity. An action without a clear mapping is not ready.
- Third, build the sandbox with everything denied by default for network, files and credentials.
- Fourth, add only the mapped paths, hosts and identities, and record the reason beside each one.
- Fifth, run the boundary tests described below before the agent sees any real task.
- Sixth, agree with the process owner who may change a boundary and how that change is reviewed.
- Seventh, review blocked attempts and permission grants on a schedule the owner sets.
The mapping step is the same discipline described in least privilege for AI agents: begin with the smallest access that lets the role do its job, then widen it only with a stated reason.
How do you test that the boundary actually holds?
A boundary you have not tried to cross is only a description. Write tests that attempt the forbidden actions: open a file outside the workspace, call a production hostname, use an expired token, write directly to the shared folder, or follow a redirect to an unlisted site. Each attempt should fail, and each failure should appear in the logs with the run identifier.
Run the same tests after any change to tools, model version, dependencies or vendor endpoints. Treat a test that starts passing an action it used to block as an incident, not as a minor fix. Keep the results alongside the role definition, so anyone reviewing the agent can see what was attempted and what happened.
How Be Human handles sandbox boundaries in managed operations
In a Be Human engagement, sandbox boundaries come out of the role definition rather than being configured ad hoc. The first engagement names the role, the memory and tools it needs, the approval points and an observable success criterion, and the network, file and credential rules are written from that map. Managed operations then keep the boundaries current: permission reviews check that identities and allowlists still match the role, monitoring tracks blocked attempts, and integration maintenance updates rules when a vendor changes an endpoint. The service is remote and available in English and Portuguese.
Take the free Be Human AI diagnostic to find the first task in your operation worth handing to an agent, and to see which boundaries that task would need.
Frequently asked questions
Is a container enough to sandbox an AI agent? A container isolates processes, but it does not decide which hosts the run can reach, which folders it can write to, or which credentials it receives. Those rules have to be set explicitly in the network policy, the storage mounts and the identity layer. Treat the container as one part of the sandbox, not the whole of it.
Should an agent ever hold production credentials? Only for named actions that a person has approved, and usually through a gateway that exposes one narrow function instead of the full API. Start with read-only access in staging, then extend access step by step as the boundary tests and logs show the agent behaves as expected.
How often should sandbox boundaries be reviewed? Review them whenever a tool, role, vendor endpoint or model version changes, and on a fixed schedule set by the person who owns the process. The review should compare current allowlists, folder mappings and identities with the role definition, and it should read the log of blocked attempts for patterns.
Where should a small team start if it has no security staff? Pick one agent and one read-only tool, then write the three boundaries on a single page: hosts, folders and identities, with a reason beside each entry. Run the boundary tests before the first real task, and keep that page next to the role definition so every change stays visible to the people who rely on the agent.
Your next step
See where an AI agent fits in your company first.
Take the free Be Human AI diagnostic. A few questions about your work show which task to hand to an agent first, what it needs to know and where a person approves.
Be Human editorial guidance. Examples are illustrative unless explicitly attributed. Sources provide background; implementation choices depend on your workflow.


