Agent Auth Gateway v1.0

Guides / 7 min read

How to Sandbox an AI Agent's Tool Calls

Published 2026-11-14 · Reviewed 2026-11-14 · By the Ingenious AI team

Policies decide what an agent may ask for. A sandbox decides what can possibly happen when the answer is wrong — it is the physical boundary underneath the policy boundary, and you want both.

The short answer

Sandbox an agent on four surfaces: the filesystem it can write, the network destinations it can reach, the data stores it can query, and the spend it can incur. Run tool execution in an isolated environment with only the directories, hosts and credentials the task needs, enforce egress through the authorising proxy so unlisted destinations are refused, and let the sandbox be rebuilt from a known state for each run. A policy can be argued with by a clever prompt; a sandbox cannot — the resource simply is not there.

Check your own setup as you read: run the free Spend Guard self-check or test a policy in the playground — five minutes, no signup, and the gaps it names map to the controls below.

Worked example: the cleanup agent that found the backups

Tidewater Clinics, a fictional group of dental practices, gave a document-management agent a tidy-up job: archive scans older than seven years from a shared drive. The agent's tool ran with the service account's full drive access. Given an ambiguous instruction about 'duplicates', it moved 3,900 current patient scans — including, for one alarming hour, the only copies of a week's imaging — into an archive folder structure nobody could navigate. Recovery took two days; no data was ultimately lost, and the postmortem's main line was that the agent should never have been able to touch those folders at all.

The rebuilt agent works inside a per-run sandbox: a working directory containing only the archive-eligible files, no route to the live imaging store, egress limited to the practice's document API, and a gateway policy allowing move operations only within the sandbox. Its successor has run weekly for five months. It has twice tried to follow instructions embedded in scanned documents; both times the requested destination simply did not exist in its world, the refusal was logged, and the run completed its legitimate work around the refusal.

Containment is about possibility, not permission

Permission systems evaluate requests. Containment removes options. The distinction matters most under prompt injection and plain misunderstanding, the two failures where the agent sincerely believes its bad action is authorised. If the production database is not mounted, the credential is not present and the route does not exist, then no belief the agent forms can reach it. Design sandboxes by asking what the worst plausible instruction — malicious or confused — could touch from inside this environment.

Build the sandbox per run, from a known state

A long-lived agent environment accumulates state: files left by earlier tasks, cached credentials, half-finished work from a failed run that the next run inherits as fact. Per-run sandboxes start clean, contain only the task's inputs, and are discarded or archived whole when the run ends. That gives you a second benefit for free — reproducibility. When a run misbehaves, its entire world can be reopened and inspected exactly as the agent saw it.

Egress is the sandbox wall people forget

Filesystem limits are intuitive; network limits are not, and they matter more. An agent that can reach arbitrary hosts can exfiltrate to any of them and can be instructed to fetch malicious content from any of them. Route tool traffic through the proxy, allowlist the destinations the task needs — the document API, the model provider, the customer's webhook — and refuse everything else by default. Tidewater's agent could not have sent scans anywhere even if a scanned document had politely asked it to.

Spend belongs inside the sandbox too

Treat budget as a sandbox dimension: the run starts with a finite purse — its caps and step budget — and the purse is not refillable from inside. An agent that can raise its own limits, or borrow another agent's identity to continue spending, has no sandbox in the dimension that produces invoices. Keep limit changes outside the run, in human hands, and log every request an agent makes that touches its own boundaries: those requests are high-value review material.

Sizing a sandbox without strangling the work

The common objection is that a tight sandbox will break legitimate work in ways nobody predicted. The answer is to build the sandbox from the work: run the agent once in observe mode, inventory every file, host and store it genuinely touches, and provision exactly that, plus a margin you choose consciously. Then watch the refusal log for the first weeks — each refusal is either the sandbox catching something real or a provisioning gap with a task attached to it. Sandboxes built this way rarely strangle anything; what they strangle is the unexamined assumption that the agent needed the whole estate because the whole estate was what it was given.

Five actions to sandbox an agent's tool calls

  1. Run tool execution in an isolated environment containing only the files and data the task needs.
  2. Route all network egress through the authorising proxy with a destination allowlist per task.
  3. Provision credentials per run, scoped to the sandbox, and remove every route to production stores the task does not need.
  4. Rebuild the sandbox from a known clean state for each run and archive the finished run's world for inspection.
  5. Include the spend purse inside the sandbox: caps the agent cannot raise and an identity it cannot swap.

Source note and related guides

Figures in the worked example are illustrative, drawn from a fictional company created for this guide; the controls, failure patterns and procedures described are the gateway's documented behaviour — see the Agent Auth Gateway documentation and the policy patterns in allowlists vs denylists, spend caps and the agent kill switch. Reviewed by the Ingenious AI team, 2026-11-14.

Sources

  • NIST AI Risk Management Framework (AI RMF 1.0), the voluntary framework for managing AI risk across design, development and use: nist.gov, 2023
  • OWASP Top 10 for Large Language Model Applications, the OWASP GenAI Security Project's risk list for LLM and agent systems: owasp.org, 2025
  • RFC 6749, The OAuth 2.0 Authorization Framework, the IETF standard behind scoped, expiring access tokens: rfc-editor.org, 2012

Frequently asked questions

What is sandboxing for an AI agent?

Running the agent's tool execution inside boundaries — filesystem, network, data and spend — that limit what can possibly happen, not just what is permitted. A sandboxed agent cannot touch resources that are not present in its environment, whatever prompt it is following.

How is a sandbox different from an allowlist policy?

A policy evaluates each request and can be bypassed by a path the policy does not mediate. A sandbox removes the resource from reach entirely. Use both: policy for judgement calls, sandbox for hard containment.

Why rebuild the sandbox for every run?

Long-lived environments accumulate leftover files, cached credentials and half-finished state that later runs inherit as fact. A clean per-run sandbox is both safer and reproducible — you can reopen a bad run's exact world.

What network access should a sandboxed agent have?

Only the destinations its task needs, reached through the proxy: the model provider, the specific APIs it serves, a named webhook. Arbitrary egress is the exfiltration route and the malicious-content route in one.

Can a sandboxed agent still do useful work?

Yes — Tidewater's rebuilt agent has run its archive job weekly for five months inside its sandbox. The work it legitimately needs was provisioned inside; everything it lost access to was work it should never have been able to do.

Governing agents in production?

Spend caps, approval queues, policy simulation, burn forecasting, and step-up lockdowns — all built into the gateway. Free tier to start. Or test policies in the playground with no signup.

Share this: X Facebook LinkedIn WhatsApp
← Multi-Agent Spend Attribution: Finding W… All guides Human-in-the-Loop Patterns for AI Agents… →