Topic 4 of 6 · 6 min read
Building sandboxed agent eval harnesses
Goal: Design a harness that runs an agent task reproducibly and resets state between trials.
An agent eval harness runs each task in a fresh, isolated environment, gives the agent its tools, records everything and resets before the next trial.
Check yourself · 1 of 3
Why reset the environment between trials?
Why it matters
Agents change things. They write files, call APIs and update databases. If trial 2 starts from the mess trial 1 left behind, your results measure leftover state, not the agent. If the agent runs against production, a bad trial costs real money. A harness removes both problems.
The parts
- Isolated environment. A container or VM built from a pinned image, with fixed dependencies and a fixed starting dataset. Inspect, from the UK AI Security Institute, runs agents in sandboxes such as Docker for this purpose.
- Tools. Real tools give realistic behaviour, but they need sandboxing. Mocked tools are fast, cheap and deterministic, but only as good as the mock. A common split: real tools for files, code and a local database; mocks for email, payments and third-party APIs.
- Task definition. Each task has a prompt, a starting state, and a grader that checks the end state.
- Reset between trials. Create a new container or restore a snapshot for every trial. Never reuse a dirty one.
- Simulated user. For conversational agents, a second model plays the customer with a script and a goal. Tau-bench uses this. Fix the user's instructions and keep its temperature low so trial differences come from the agent.
- Limits. Set a step limit, a time limit and a cost cap, so a looping agent stops.
- Logs. Save the full trajectory, tool calls and final state for each trial.
Before and after
# Weak: shared state, real network, no limits
task: refund-order-4471
env: shared-staging-db
network: open
# Better: fresh and bounded
task: refund-order-4471
env:
image: shop-sandbox@sha256:7c1e...
seed: fixtures/orders-small.sql
reset: per-trial
tools:
real: [read_db, write_db]
mock: [send_email, charge_card]
network: none
limits: { steps: 30, seconds: 300, cost_usd: 0.50 }
What goes wrong
- Shared state. Trial results depend on order, which makes failures impossible to reproduce.
- Mocks that are too kind. A mock that never errors hides the failures real tools cause.
- No limits. One looping trial can eat the whole budget.
- Drifting images. An unpinned dependency changes results between weeks.
Examples
Fresh container per trial
A coding agent task starts from one container image with the repo checked out at a fixed commit. After each trial the container is discarded. Trial 7 cannot see files that trial 6 created.
A mock that always succeeds
A payment mock returns success every time. The agent scores 95 percent in the eval. In production the payment API times out about once in twenty calls, and the agent has never been tested on that. Add failure injection to the mock.
Key points
- Run every trial in a fresh, isolated environment built from a pinned image.
- Use real tools inside the sandbox and mocks for email, payments and external services.
- Reset or restore state between trials so earlier runs cannot affect later ones.
- Simulated users need fixed goals and instructions so the agent is the only variable.
- Set step, time and cost limits, and save the full trajectory of each trial.
Common mistakes
- Running trials against a shared database that is never reset.
- Mocking every tool with versions that never fail.
- Leaving out step and cost limits so a loop runs until the budget is gone.
- Building the sandbox from unpinned dependencies.
Check yourself · 2 of 3
Which tools are best mocked in an agent sandbox?
Check yourself · 3 of 3
A mock API never returns errors. What is the main risk?
Practice items, not counted towards your mastery.
Start here
- Demystifying evals for AI agents (Anthropic) (opens in a new tab)ArticleFree
Anthropic's practical guide to grading agents: graders, trials, pass@k versus pass^k and reading transcripts.
- tau-bench: Tool-Agent-User Interaction in Real-World Domains (Yao et al.) (opens in a new tab)PaperFree
Introduces pass^k and grades agents on the final database state with simulated users and policy rules.
- SWE-bench (opens in a new tab)ToolFree
The reference benchmark built from real GitHub issues, graded by tests the agent never sees.
More for this topic
- Inspect: Agents (opens in a new tab)DocsFree
How a sandboxed agent eval framework defines agents, tools and scoring.