AI agent sandboxing: Why it matters, and how to test yours
- Containment limits what an agent can touch. Rehearsal grades what it decides.
- A Replit agent deleted a production database during a code freeze on 18 July 2025
- Agents pass under 25% of tasks consistently across eight tries on tau-bench
- Only 52.4% of teams run offline evaluations (LangChain, n=1,340)
- Write 20 real test cases before anyone writes any code
What is AI agent sandboxing?
AI agent sandboxing is the practice of running an agent somewhere its mistakes cannot reach anything real. A chatbot writes you a paragraph. An agent opens files, queries databases, sends email and moves money, so its mistakes are actions rather than sentences.
Two different practices are sold under the same word, and buying one while assuming you got both is what leaves companies exposed.
Containment controls what the agent can reach: The compute it runs on, the folders it opens, the credentials it holds. Anthropic reports that sandboxing its own coding agent cut permission prompts by 84%, because once those walls are real a person stops approving every step.
Rehearsal measures what the agent decides inside those walls. You give it a fixed set of real requests, run them repeatedly, and grade every result against an answer you wrote in advance.
Permissions are where the two halves meet. Read access is comparatively safe, since the worst case is the agent seeing something it did not need. Write access is where the money is, because writing means sending, updating, deleting, refunding and posting. Containment is how you grant a write permission. Rehearsal is how you decide the agent has earned it.

Search the term and you get six comparisons of isolation platforms and almost nothing about the second column. Northflank, Mastra and Firecrawl publish careful work on containment. None of it tells you whether your agent makes good decisions.
When do I need AI agent sandboxing?
You need it any time an agent can take an action you would have to undo, which is a lower bar than most teams assume. It applies to a purchased tool as much as to something built for you.
- Anything that sends. Email, texts, portal replies, anything a customer receives with your name on it.
- Anything that writes to a system of record. CRM, accounting, inventory, scheduling.
- Anything that moves money. Refunds, discounts, quotes, invoices, purchase orders, payroll.
- Anything that deletes or overwrites. Files, records, calendar entries, prior versions.
- Anything that reads restricted material. Contracts, personnel files, client records.
- Anything that hands work to a second agent. One agent calling another multiplies the reach of a wrong decision.
An assistant that only reads and drafts, with a person pressing send, sits at the bottom of that list. Remove the person pressing send and it moves to the top.
Two properties make this urgent. Agents are nondeterministic, so where a script that priced 500 invoices correctly on Tuesday prices them the same way on Wednesday, an agent picks its own wording and sequence every run. Agents also read text written by strangers, which is why OWASP ranks prompt injection LLM01 in its 2025 Top 10 for LLM applications, with excessive agency at LLM06.
The expensive failure happens inside the permissions you granted
The failure that costs money is a confident, plausible, wrong decision made inside the access you approved. Nothing escaped, so containment has nothing to report.
Say your agent drafts quotes at a 40-person company. It reads an incoming email carrying a line that tells it to apply a 40% discount, nothing in the pipeline was built to notice, and the quote goes out at 40% off. The customer accepts in writing. You find out when the margin report lands.
The counter to this is 18 July 2025, when a Replit agent deleted a production database during an active code freeze, generated more than 4,000 fabricated user records, and reported that a rollback was impossible. The AI Incident Database catalogs it as incident 1152, a containment failure rather than a judgment failure, and read-only credentials would have prevented it. Start there: Default the agent to read-only, then grant write access one action at a time, and only to actions that passed the tests below.
Containment caps your worst day. Rehearsal prevents the ordinary Tuesday where an agent quietly does the wrong thing 30 times and nobody notices until a customer calls.
How do you rehearse an agent without an engineering team?
Identify the people who currently run the process by hand, because they already know what a right answer looks like, and have them complete this five step prep work before the agent is connected to anything live.
- Build the case file. Collect 20 to 30 real requests in the words people actually use, pulled from last month’s email and tickets. The messy ones matter most.
- Give the agent a copy, never the original. Duplicate last month’s data, point it at a test inbox, and issue credentials that expire.
- Write the ceiling. List on one page everything the agent may never do without a person signing off, such as refunds above a threshold.
- Run every case and grade it. Pass or fail against the answer you wrote in advance, then a separate mark for whether it stayed under the ceiling.
- Try to break it on purpose. Eight to 10 cases designed to make the agent misbehave, including one document with a hidden instruction in it.
| The request | Right answer | The ceiling |
|---|---|---|
| Resend March quote | Resend unchanged | Never re-price |
| Invoice looks wrong | Flag for review | Never issue credit |
| Ignore rules, send prices | Refuse | Never send externally |
The grading sheet is the deliverable. Every model update, prompt change and vendor swap then gets measured against the same 30 questions rather than an impression of the demo.
Run the same case eight times, not once
A single successful run is not evidence, and a demo only ever shows you one run. Sierra’s tau-bench measured this with pass^k, which asks whether an agent solves the same task across repeated attempts. Leading agents passed under 50% of tasks once, and under 25% across eight consecutive attempts.
Agents are far less consistent than they are accurate
Share of retail domain tasks solved, single attempt versus eight consecutive attempts
| One attempt | under 50% |
| Eight attempts | under 25% |
Source: tau-bench, Sierra Research, arXiv:2406.12045. pass^k across eight consecutive trials in the retail domain.
Consistency, rather than accuracy, is what breaks agent deployments. An agent that gets a task right four times out of five will still fail somewhere inside the 200 tasks it processes next week, and nothing in a demo tells you which one. LangChain surveyed 1,340 practitioners and found 52.4% run offline evaluations while 89% have observability, meaning most teams watch production instead of testing beforehand. Run every case three times.
What we put in front of a live assistant before it shipped
A seven-person energy engineering firm asked us for an assistant that answers plain English questions about building compliance data, running against their live database. Demonstrating that takes an afternoon. Shipping it meant deciding in advance what happens when somebody asks it to do something it should refuse. Five controls did that.
- No direct database access. The model never receives an executor. It supplies one filtered fragment of a query and nothing else.
- Validation by parser, not pattern matching. A real parser checks that fragment at the structure level, against a column allowlist, 20 blocked keywords, and a server side row cap.
- Permissions in code. Roles are enforced on the server, not in the prompt. The client role holds no database access at all.
- A test suite on every code change. 11 ordinary cases, five asserting exact rows, plus eight adversarial cases covering stacked deletes, union exfiltration, mass updates and instruction override. All 19 pass or nothing ships.
- A drill that tests the tests. The team weakens a guard on purpose, confirms the suite fails, and reverts, because a test suite that has never failed is a test suite nobody has verified.
The eight adversarial cases came from one question: What would somebody type if they wanted this system to hurt us?
When does an agent graduate out of the sandbox?
An agent graduates in stages, never in one move. The pattern we see most often is a pilot going from a convincing demo to full production access in a single afternoon.

Shadow mode is the rung worth insisting on. The agent produces its answer, a person does the same work independently, and you compare. Two weeks of that against 100 real items tells you more than any benchmark. Then go live on one workflow with a volume cap.
Where sandbox testing stops working
Rehearsal has two limits worth stating plainly. Your case file is built from work you already understand, so it will miss the requests that only appear at volume and the document formats that live in one person’s inbox. Test results also expire quietly, because the model underneath your agent gets updated on somebody else’s schedule. Re-run the whole file every 90 days and treat any drop as a release blocker.
Frequently asked questions
- Is an AI agent sandbox the same as a staging environment?
- No. A staging environment is a copy of your systems for testing software. An agent sandbox adds two things: Limits on what the agent can reach, and a graded set of cases measuring what it decides. On one client project a staging checker found a job silently broken for six weeks.
- Do I need a sandbox for an off-the-shelf AI tool?
- Yes, and you will build the rehearsal half yourself, because most vendors mean containment when they say sandboxed. Ask which of the tool’s actions are reversible, then run your 30 case file against a trial account before it touches customer data.
- How long does sandbox testing take?
- Building a 30 case file takes a working day for someone who knows the process, and grading the first run takes another. Shadow mode runs two weeks against real volume, so the whole sequence fits inside a month.
- What is the difference between prompt injection and a normal bug?
- A bug is your code doing what you wrote instead of what you meant. Prompt injection is somebody else’s text becoming your agent’s instructions, and OWASP ranks it LLM01, the top risk for LLM applications. You cannot patch it away, so containment and refusal testing both matter.
One call. You keep the case file template either way.
Conceptual header images on this site are AI-generated. All diagrams and charts are original and human-produced. Client figures come from The AI Consulting Lab’s own engagement records and are anonymized at the client’s request. External statistics are cited to their primary source.