Post

AI agent sandboxes need egress contracts

A container is not the security boundary for a coding agent. The useful boundary is an egress contract: destination, identity, data, approval, and evidence.

AI agent sandboxes need egress contracts

A sandbox with unrestricted egress is not a serious security control.

It is a laptop-shaped production credential leak.

That sounds harsh, but look at the setup many teams are drifting toward: put a coding agent in a container, mount a repository, give it shell access, let it use a browser, add a few API keys, and put a human approval button somewhere near the dangerous commands. Then call it sandboxed.

The container is real isolation. The approval can be valuable. The prompt can help. None of those things answer the question that actually matters once the agent is allowed to act:

What is this workload allowed to send out, where, under which identity, and with what record?

That is the boundary I would build around. I call it an egress contract.

It is less glamorous than a new agent framework, but that is usually a good sign. Serious engineering is mostly a collection of useful boring things.

a sandbox is a place, not a policy

Sandboxes are necessary because agents need somewhere to do work. They read files, run tests, install dependencies, generate artifacts, maybe keep state while a human reviews the result.

But a sandbox is compute isolation, not permission design.

OpenAI’s sandbox guidance makes this distinction clearly: the harness is the trusted control plane for routing, approvals, tracing, and recovery; the sandbox is the execution plane where model-directed code handles files and commands. That split is sensible. The model-directed side should not quietly become the place where permanent credentials, audit records, and broad authority live.

Network access is where the distinction becomes painfully practical. Agent-generated code can use every file, credential, and network path exposed to its environment. If the environment can reach the internet and has a production-flavoured credential lying around, the agent has a route from untrusted input to an external side effect.

The agent does not need to be malicious for this to go wrong. A prompt injection in a dependency README, a convincing issue comment, a typo in a host name, or a badly chosen tool call is enough. Agents are unusually good at chaining locally reasonable steps into a globally surprising outcome.

So the question should not be, “is outbound access enabled?”

It should be, “what egress is allowed for this task, and what must happen at the boundary before it leaves?”

what belongs in an egress contract

An egress contract is a versioned policy attached to an agent run, task class, or sandbox template. It says more than “allow api.example.com.” At minimum, I want it to answer seven things:

  1. Destinations. Exact APIs, package registries, source-control hosts, and MCP services. Default-deny everything else.
  2. Resolution and transport. Which DNS resolver, proxy, TLS requirements, ports, redirect behaviour, and whether raw IP connections are allowed.
  3. Data classes. What may cross each boundary: public source code, dependency metadata, redacted logs, customer data, or nothing at all.
  4. Identity exchange. Which broker can mint credentials for the destination, with which workload claims and scopes.
  5. Lifetime and delegation. How long a token lasts, whether it can be refreshed, and whether the task may create a further credential.
  6. Approval tier. Whether the request is automatic, requires a human step-up, or is impossible from an agent sandbox.
  7. Evidence. The task, sandbox image, policy version, destination, request class, identity claims, approval, and outcome recorded in a durable activity trail.

The point is not to build a heroic gateway that understands every HTTP request in the world. The point is to make the allowed route explicit enough to review, test, and revoke.

Kubernetes already gives us the underlying mental model: isolate by default, then add egress rules deliberately. The agent-specific addition is that a network allow rule is incomplete without an answer to identity and evidence.

three familiar ways teams lose the plot

The first is the API key in the environment.

It is easy. It is also a gift to every command the agent runs, every dependency it installs, and every process it accidentally starts. Moving the key from a config file into an environment variable is an improvement for source control hygiene; it is not a meaningful security boundary when model-directed code can read the environment.

The second is the broad cloud role.

This usually arrives dressed as pragmatism: the agent needs to inspect logs, read a queue, update an infrastructure file, and perhaps deploy a fix. Rather than model each action, someone gives it a role with enough permissions to get the demo working. Now the difficult part is hidden in an IAM policy that cannot explain why this particular task should touch this particular resource today.

The third is an unrestricted browser or web tool.

People treat browser access as if it were merely another way to fetch documentation. It is often a fully authenticated human session with a giant attack surface: redirects, uploads, downloads, account settings, web forms, and whatever the agent can persuade itself to click next. A browser needs the same destination, data, identity, and audit rules as a shell command. Calling it “computer use” changes none of that.

These are different interfaces to the same mistake: handing a semi-autonomous workload ambient authority and hoping instructions will keep it polite.

the useful shape: proxy, broker, record

The pattern I like is deliberately unexciting:

1
2
3
task sandbox -> egress proxy -> destination-specific identity broker -> external service
                     |
                     +-> immutable activity record

The sandbox has no general internet route and no long-lived third-party secret. Its network path goes through an egress proxy that enforces the contract. For an allowed request, that proxy or a neighbouring broker exchanges the task identity for a short-lived, destination-specific credential. The credential is never handed back as a reusable secret if the architecture can avoid it.

The result is a useful change in the unit of authorization. You are no longer authorizing “the agent” or even “the container.” You are authorizing a particular workload, running a particular task, against a particular destination, for a short window, under a known policy version.

This is not exotic technology. GitHub Actions OIDC already issues tokens carrying claims about the repository, workflow, environment, and run. AWS documents using audience and subject conditions to limit which GitHub organisation, repository, or branch can assume a role. The same family of workload-federation patterns exists in Azure and Kubernetes ecosystems.

The lesson is not that every agent must pretend to be GitHub Actions. It is that short-lived, claim-bound identity is a much better primitive than putting a cloud key in a sandbox and wishing it well.

For example, a dependency-update task might be allowed to reach registry.npmjs.org through a cache and open a pull request through a source-control gateway. It should not be able to post to Slack, browse a production console, or discover every hostname in your internal DNS. An incident triage task might receive a short-lived, read-only log-query identity and a stricter audit tier. A production repair should be a separate task class with a different contract, an environment gate, and an explicit human approval.

Same agent. Different routes. Different authority. That is what good boundaries look like.

prompts and approvals still matter

This is not an argument against prompts, tool descriptions, review queues, or human approval.

Prompts shape behaviour. Tool schemas make the safe path easier. Human review catches mistakes and gives organisations an accountability point. All useful.

But none of them is a technical substitute for an egress boundary.

An approval screen that appears after an agent has already read sensitive data or contacted an arbitrary host is not a control; it is a receipt generator. A beautifully written system prompt cannot prevent a compromised package from receiving a credential that the sandbox was permitted to read. A reviewer cannot meaningfully assess an action when the platform cannot say which identity actually performed it.

Good systems use both layers. The agent is instructed and reviewed. The infrastructure makes the disallowed action unrouteable and the allowed action attributable.

That is defence in depth without the hand-waving.

a review checklist for platform teams

Before I would let a coding agent operate beyond a local developer sandbox, I would ask these questions:

  • Is egress default-deny, including DNS, package managers, browser traffic, and MCP connections?
  • Can we name every allowed destination and the data class permitted to leave for it?
  • Are long-lived third-party secrets kept outside model-directed compute?
  • Does each destination receive a short-lived identity scoped to the task, repository, environment, and action?
  • Can the workload refresh, mint, or export credentials? If yes, why?
  • Are high-risk actions a separate contract rather than an extra checkbox on a broad role?
  • Can we reconstruct an external action from the task, policy version, identity claims, approval, and result?
  • Can we revoke a destination or identity path quickly without rebuilding every sandbox image?

If the answers are vague, the platform is probably relying on a container boundary that ends at the first outbound TCP connection.

That is not enough for agents that can inspect code, operate browsers, install packages, and call production APIs.

The best security boundary for an agent is not the prompt. It is not the approval button. It is not even the container.

It is the contract that governs how the sandbox reaches the world.

references

To test my projects, I use Railway. If you want $20 USD to get started, use this link.

This post is licensed under CC BY 4.0 by the author.