What a sandbox does not solve for an AI agent
An agent can make the wrong production change without escaping its sandbox.
Imagine an incident-response worker investigating a queue backlog. The approved change is small: scale lab/queue-worker from two replicas to three. The worker runs in an isolated runtime and can reach a deployment API. Its credential has permission to scale workloads in both the lab and production.
Now the worker sends the same request for prod/queue-worker. Maybe a log line it summarized said the backlog was in production. Maybe a copied runbook used the production path, or the model simply picked the wrong environment name. No host file was opened. No new destination was contacted. The API accepts the credential and permits the change. The runtime boundary behaved exactly as configured, and the wrong workload changed anyway.
The scenario is fictional. When the cause is that log line, the failure has a name. A confused deputy is a program that holds legitimate authority and is tricked by a less-privileged party into using it. Norm Hardy described it in 1988 with a compiler that overwrote a billing file. Whoever wrote the log has no production access. The agent does. A plain targeting mistake produces the same change without anyone being tricked. Either way, containing the worker's code and authorizing its proposed changes are separate jobs, and a design review should ask about each one.
Three separate questions
Runtime isolation
What can this code touch?
Host interfaces, files, and network destinations. Answered by the sandbox and its network policy.
Workload identity
What may this credential do?
Verbs and resources the receiving API will permit. Answered by the API's authorization.
Action approval
Was this exact change approved for this run?
Target, parameters, state, expiry, and reuse. Answered by a check at execution time.
What is actually being isolated?
A sandbox reduces the ways a worker can interact with its surroundings. The specific boundary depends on the runtime and its configuration. A container, a virtual machine, and a restricted process do not provide interchangeable guarantees.
Consider gVisor's security model. It describes defenses against untrusted code exploiting the host's system interfaces. It also explains that sandboxed applications can use mapped files and make network connections. Network controls still need their own configuration. That is a useful scope statement, not a shortcoming to hide.
I would keep that isolation even if every tool call had a permission check. A defect in the worker's dependencies should not become an easy route into the host. But isolation alone does not establish that scaling this production workload is an acceptable response to this incident.
Some systems package runtime isolation, credential brokering, and action policy together. The packaging is fine. The question is whether each control exists, where it is enforced, and which route bypasses it.
Isolated worker
Analyze and propose
The agent computes over permitted inputs and submits a structured action. It cannot directly mutate the workload.
Trusted broker
Check this request
- Current identity scope
- Exact approved change
- Expiry and resource version
- Prior use of approval
Deployment API
Apply conditionally
The receiving service checks its own permissions and enforces the supported state precondition when applying the change.
A permitted endpoint can still be the wrong target
Allowing the deployment API's hostname does not tell us which workload the caller should change. Even an allowlist containing only a scaling tool leaves its arguments to decide. The same operation can target the lab or production.
Workload identity needs a separate answer. Kubernetes service accounts, for example, give workloads an identity, and RBAC or another mechanism decides what that identity may do. Kubernetes makes the authorization decision in its API server, using request attributes such as identity, verb, namespace, and resource. Putting a broadly authorized identity inside an isolated runtime does not narrow what that API will permit.
For our worker, removing production access from its identity would stop the example's cross-environment change. Do that when production is outside its job. A broker's access should be similarly limited; moving an unrestricted credential into another process does not make its authority disappear.
There is still a narrower question when an identity legitimately serves several workloads: which change was approved for this run?
Approve a change, not a conversation
A chat message saying "go ahead" leaves too much for the executor to reconstruct. I want the approval record to identify the change that the reviewer actually saw.
In the local example, there is only one operation: set a workload's replica count. The broker owns this approval record:
- Identity
agent-run-17- Resource
lab/queue-worker- Requested replicas
3- Observed resource version
7- Expiry
- Logical clock tick
120, exclusive - Reuse
- One successful execution in this process
The caller presents a lookup ID, review-42. That ID is not a bearer credential. The broker still checks the caller's current permissions, matches its identity to the record, and compares the proposed action with the approved action.
If the resource changes, or the requested replica count changes, the old approval no longer applies. If the workload's version has changed since review, this example stops for another decision. That is strict on purpose. A real system might tolerate harmless metadata edits.
None of this is new. The OWASP Transaction Authorization Cheat Sheet recommends showing significant transaction data, enforcing authorization server-side, invalidating authorization when that data changes, and checking authorization at the final execution gate. It was written with payments in mind. The same principles carry over to an infrastructure change proposed by an agent.
The model can explain why it wants thirty replicas instead of three. It cannot turn that explanation into permission.
Give the worker compute, not change authority
For the queue investigation, I would give the worker somewhere to parse measurements, compare time windows, and calculate a recommendation. It returns the evidence and a structured proposal. It holds no credential that can change a workload. A separate executor holds the narrowly scoped mutation credential and checks the proposal against the approval before acting.
That split still leaves three things to get right:
- Reads need limits too. Read-only access to every team's logs exposes every team's logs. Enforce the data scope at the service or data store, and remember that an allowed model endpoint is still a place data can go.
- The proposal is untrusted input. It can carry a bad recommendation or instructions copied from a log. The executor accepts only its defined action fields and applies its own policy.
- Limits live outside the worker. CPU, memory, deadlines, output size, and cleanup of cancelled runs are enforced by the platform, not requested by the code.
OWASP's excessive-agency guidance lands in the same place: minimize capabilities and privileges, and enforce authorization downstream rather than asking the model to decide.
Two objections come up quickly. Does this need a separate broker? Not necessarily. A narrowly scoped capability can carry the action grant instead of a broker-side lookup, as long as the receiving service enforces its restrictions. The control matters more than where it runs. And does a human have to click for every call? No. Routine actions can run inside an explicitly approved envelope, with limits on targets, parameters, cumulative changes, and duration. Leaving that envelope requires another decision. That avoids a stream of prompts nobody reads, but it gives the worker more discretion than the exact-action example below.
Run the policy model locally
This program models the broker, not a sandbox. No network calls or credentials; it only changes Python objects in memory.
Download the Python example
Python 3.10 or later; standard library only. After downloading, run python sandbox_demo.py. From a clone of this blog's repository, run:
python .\posts\sandbox-boundaries\sandbox_demo.py
The fixture deliberately gives the identity permission to change both workloads. The first output line about production therefore says True. The action-specific approval still rejects the production proposal.
Offline policy model. No sandbox, network calls, or infrastructure.
Broad identity permits production: True
approved request: APPLIED lab/queue-worker replicas=3 version=8
changed target: DENIED action_changed
changed replicas: DENIED action_changed
missing approval: DENIED approval_missing
different identity: DENIED approval_identity
expired approval: DENIED approval_expired
changed workload: DENIED workload_changed
replayed approval: DENIED approval_used
Each demonstration case starts from fresh state, except the replay case, which first performs a successful change. A rejected request leaves both the workloads and approval-use state unchanged. The broker runs its checks in a fixed order and stops at the first failure:
-
Request shape
- invalid_replicas
-
Identity now
- identity_scope
- unknown_resource
-
Approval record
- approval_missing
- approval_used
- approval_identity
- approval_expired
-
Exact change
- action_changed
- workload_changed
-
Apply
Update the workload, bump its version, and mark the approval used.
Broker.execute, in the order it checks them. State changes only in step five.The last two comparisons are the heart of it:
if approval.action != action:
raise Denied("action_changed")
if approval.resource_version != workload.version:
raise Denied("workload_changed")
The accompanying tests also revoke the identity's resource permission while keeping its approval intact. That request is denied. An earlier review does not override the permission in force when the action is attempted.
python -m unittest discover -s tests -p test_sandbox_demo.py -v
Which layer stops which failure
Put the pieces side by side and the gaps are easy to see. This assumes the worker's identity is scoped to its job and the broker runs the checks above. "Stops" means the policy is enforced on every mutation path. Replay protection here covers sequential requests within one process.
| Failure | Runtime isolation | Scoped identity | Action approval |
|---|---|---|---|
| Code exploits a host system interface | Reduces exposure | No | No |
| Worker contacts an unexpected destination | With network policy | No | No |
| Request targets production, outside the worker's job | No | Stops | Stops |
| Request targets an unapproved workload within the identity's scope | No | No | Stops |
| Parameters change after review | No | No | Stops |
| Approval is replayed | No | No | Stops |
| Workload changes after review | No | No | With conditional write |
| The diagnosis is wrong | No | No | No |
Where this example stops
All of the Python objects live in one process. Their separation is by convention, not an isolation boundary. The tests establish decisions about these fixtures. They do not measure container isolation, resist a malicious process in the same interpreter, or establish that a real deployment is secure.
The code is sequential and its used-approval set disappears on restart. A production service needs protected approval storage and a coordinated execution path. Two replicas of the broker must not both accept a one-use approval. And an API timeout after a change must not lead to an unexamined retry. Durable replay handling and outcome reconciliation are work this example does not implement.
There is also a gap between reading a resource version and sending a remote mutation. Checking version seven in the broker is insufficient if another writer can change the resource before the receiving API applies our request. Use the receiving API's supported conditional-write mechanism, or stop if the required condition cannot be enforced. The in-memory version check here does not demonstrate that distributed guarantee.
An unchanged version also does not prove that the proposed remedy is sensible. This approval model does not validate the diagnosis, model neighboring workloads, or establish that three replicas will clear the queue. Those need evidence and checks appropriate to the operation.
The useful review question is specific: can this worker cause a change that the runtime allows, the credential permits, and this run never approved? Trace that request all the way to the system applying it.
Sources and related writing
- Confused deputy problem: the term, Norm Hardy's original 1988 compiler example, and why ambient authority causes it.
- gVisor, Security Model: host system-interface isolation, allowed application interactions, and the need for network controls.
- Kubernetes, Service Accounts: workload identity, permission grants, default account permissions, and token mounting.
- Kubernetes, Authorization: API-server authorization and the request attributes it evaluates.
- OWASP, Transaction Authorization Cheat Sheet: significant transaction data, server-side enforcement, changes after approval, final execution checks, and replay handling.
- OWASP, LLM06:2025 Excessive Agency: minimal tool capabilities and permissions, user-scoped access, approval for high-impact actions, and downstream authorization.
Related: access control for agentic systems, permissions and recovery when inputs change, and the incident-response presentation.