Back to blog
AI

Your Agent Doesn't Need Your API Key to Spend Your Money

An agent can leak files through an approved domain without escaping its sandbox. What egress proxies protect, and why hiding the API key is only half the job.

#AI Security#Egress Proxies#Sandboxing#Secrets
Date
11/02/2026
Read
8 min read
Cat
AI

Uploading to an attacker account on an allowed domain

An agent reads malicious instructions in its workspace. Those instructions tell it to upload local files using an attacker-controlled API key. The agent obliges.

The request goes to api.anthropic.com, which the network policy allows.

That is the uncomfortable example in Anthropic's May 2026 containment write-up: Cowork uploaded files into the attacker's account through an approved service. It was not a sandbox escape. The traffic went somewhere the network policy permitted, just under the wrong person's authority.

A domain allowlist doesn't distinguish between the user's account and an account controlled by an attacker.

This is why egress proxies are interesting for agent security. They can sit outside the environment an agent controls, constrain its network access, and attach credentials the agent never receives. But getting those benefits requires answering three separate questions: where can it connect, whose account will it use, and what is it allowed to do?

Enforcing the network route

Setting HTTPS_PROXY makes compatible clients use a proxy. It does not prevent a program from opening its own socket.

For an ordinary application, that distinction might be a configuration problem. For an agent that can execute arbitrary code, it is the security model. The code you're trying to constrain gets to decide whether to honor your environment variable.

Istio explicitly documents this limitation: routing through an egress gateway is not a secure guarantee that a workload cannot bypass it. A separate network control has to enforce the route.

The architecture I want looks roughly like this:

Untrusted sandbox
       |
       v
Externally enforced route -----> External network logs
       |
       v
Policy and credential broker <-- External secret store
       |
       +-----------------------> External request logs
       |
       v
Approved upstream operation

"External" needs a definition. A separately protected proxy outside an agent process can survive that process being compromised. A host-side proxy can keep working after an attacker gets root inside a VM guest, provided the host independently enforces the route and remains trusted.

Host root is a different problem. An attacker who controls the machine enforcing the policy may be able to change or disable it. Protecting against that requires another boundary outside the host, including control over alternate routes and network configuration.

Likewise, root inside a container is not automatically a host escape. Name the boundary you expect to survive rather than putting every compromise under the word “sandbox.” Firecracker's production guidance makes the division concrete: guest packets reach a host TAP device, and host firewall rules handle filtering.

To test route enforcement, remove the proxy settings and try to reach a destination the policy forbids. Check where the traffic actually went. Transparent interception can still enforce the policy even when the application thinks it connected directly. If the forbidden destination receives the traffic, the route is not being enforced.

What a CONNECT proxy can inspect

A standard CONNECT proxy sees a request to establish a tunnel to something like api.github.com:443. After that, TLS can run through the tunnel end to end.

The proxy can observe the tunnel and its traffic volume. It cannot read the encrypted HTTP headers or body merely because those bytes pass through it. That's how CONNECT works.

This matters when someone promises that their proxy will inspect prompts, restrict API operations, or inject an authorization header. Those features require application-layer access: TLS termination and re-encryption, a service-specific reverse proxy, or a broker that constructs the upstream request itself.

TLS interception brings certificate trust and protocol compatibility into the design. A purpose-built broker can be simpler: the agent calls the broker's own API, and the broker makes a separate authenticated call to the provider.

For a task that only needs to read repository files, I'd expose read_file(path). That gives the broker fewer inputs and operations to validate than a general-purpose URL forwarding service.

Restricting operations as well as credentials

Keeping provider credentials outside the worker is a real improvement. An agent can't print an environment variable containing a key it never received.

Docker documents host-side credential replacement: the sandbox can use a sentinel such as proxy-managed, and the proxy substitutes the real credential. Its OAuth passthrough option changes that property by allowing real token responses into the sandbox. Configuration matters.

But suppose the proxy lets the agent make unlimited model API calls. The agent can spend your money without learning your API key. Give it a mail-sending operation and it can send an unwanted email without stealing a password.

Hiding the credential does not remove the authority available through it.

The sentinel isn't authentication, either. A task identity, scoped bearer token, or accessible broker socket still gives its holder permission to request work. After compromise, the attacker can use whatever permission remains. Authenticate the task through trusted orchestration, then look up what that task may do.

This is also where the proxy becomes security-critical code. In One Slash Away From the Whole AI Account, a caller-controlled path let a thin proxy apply powerful credentials to unintended API resources. Moving the key behind another HTTP endpoint doesn't help if the caller gets to choose everything that endpoint does.

A broker for reading repository files

Let's make this concrete. A research agent needs to read files from acme/docs-site at an approved commit. It doesn't need to create issues, open pull requests, update workflows, or browse a different repository.

This is a proposed design, not a tested implementation. The identifiers are fictional. The useful part is the shape of the permission.

Trusted orchestration creates this grant outside the sandbox:

task: research-42
identity: spiffe://agents.example/tasks/research-42
expires_at: 2026-10-30T18:10:00Z
github:
  installation_id: 42001
  repository_id: 123456
  repository: acme/docs-site
  commit: 0123456789abcdef0123456789abcdef01234567
  operation: read_file
limits:
  requests_per_minute: 30
  response_bytes: 1048576
  total_response_bytes: 10485760

The agent supplies one argument:

POST /v1/github/read-file HTTP/1.1
Host: broker.internal
Content-Type: application/json

{"path":"README.md"}

It doesn't choose the repository, commit, installation, credential, or upstream hostname. The broker fixes the hostname to GitHub's API and selects the remaining values using the grant associated with its authenticated identity. The broker must not trust a caller-supplied X-Agent-ID header as proof of task identity.

The broker's core flow looks like this:

identity = authenticate_workload(connection)
grant = require_active_grant(identity)  # expiry and revocation
require_route(request, "POST", "/v1/github/read-file")
args = strict_json(request, only_fields={"path": str})
path = validate_repository_path(args["path"])
require(grant.github.operation == "read_file")
reserve_request_and_byte_budget(grant)

token = scoped_installation_token(
    installation=grant.github.installation_id,
    repository_ids=[grant.github.repository_id],
    permissions={"contents": "read"})

response = github.read_contents(
    repository=grant.github.repository,
    path=path,
    ref=grant.github.commit,
    token=token,
    follow_redirects=False)

return validated_bounded_file_content(response)

GitHub installation tokens can be restricted by repository and permission. The Contents endpoint supports Contents: read and an explicit commit reference. That gives us two restrictions: the provider credential limits repository access, and the broker limits this task to one operation at one immutable version.

The helper names conceal actual engineering work: unambiguous decoding, safe URL construction, TLS validation, response limits, concurrency-safe budgets, and sanitized errors. Build fresh upstream headers. Reject unknown arguments. A function named validate_repository_path is a requirement, not a security implementation.

Suppose the README instructs the agent to publish the source in a GitHub issue for diagnostics. That request uses the same service but falls outside the granted read operation.

operation: github.create_issue
decision: deny
reason: operation_not_granted
credential_applied: false
upstream_request_sent: false

The broker denies the request because the task has no grant to create issues.

This grant intentionally permits reading the entire selected repository. GitHub's Contents API can resolve repository symlinks, so a path prefix alone shouldn't become a claim of directory confidentiality. And the files it returns can still contain secrets or malicious instructions.

This restricts one capability. If the same agent can upload arbitrary content to another SaaS service or include source in a model API request, that remains a disclosure channel. Those channels need their own restrictions.

Filtering responses and revoking access

Credential injection is only half a round trip. An upstream endpoint could echo the authorization header, return a session token, or hand back a signed download URL.

Forwarding those responses unchanged could expose credentials or reusable capabilities to the sandbox. Return the validated file content this operation needs. Don't relay arbitrary headers, cookies, redirects, or reusable download capabilities.

Secret scanning can help with credentials already present in source files or tool output. But detecting an exact string doesn't establish that encoded, split, or otherwise transformed data cannot leave. Restricting where data can go and what operations can carry it remains necessary.

Expiry needs equal care. GitHub installation tokens last an hour. A ten-minute task grant is a separate broker rule. On termination, reject new requests, stop refreshing credentials, and revoke the task's token where appropriate. Also decide what happens to downloads and tunnels already in progress. Changing a permission record doesn't retrieve bytes you've already sent.

A denied connection is not an escape detector

The most useful monitoring combines broker decisions, external network events, and runtime evidence.

A direct connection dropped by the firewall never reaches the proxy. There won't be a proxy request log for it. Proxy logs alone therefore cannot account for every attempted connection.

At the broker, record the trusted task identity, request ID, policy revision, operation, resource, decision, reason, byte counts, and upstream result. Record the connected address only if a connection occurred. Keep credential values out of those logs. Query strings and response bodies can contain secrets too.

Repeated direct-egress attempts, forbidden operations, unexpected tenants, and bursts against budgets are useful investigation signals. They don't prove intent. A missing allowlist entry can look suspicious, and a successful authorized request can carry the wrong data.

Runtime evidence helps establish what code ran and which boundary failed. gVisor's external runtime monitoring illustrates that separate observation layer. A denied network request alone cannot tell you whether the agent escaped, followed malicious instructions, or tried to install a dependency.

Testing the proposed boundary

I'd validate this with owned endpoints and fake credentials, then repeat the checks from a deliberately provisioned root process inside a disposable guest. There's no need to discover a hypervisor exploit to test the privileges you're assuming.

Start with a successful allowed read. Then remove proxy variables and try direct connections, including IPv6 and UDP. Exercise DNS separately: allowing a resolver is not enough if arbitrary query names can carry data to an attacker-controlled domain.

Have the mock upstream return redirects and change controlled DNS answers. Check the actual destination being dialed, not just a hostname validated earlier. OWASP's SSRF guidance is relevant here because the gateway can become the component with access to places the worker cannot reach.

Try the wrong repository, a write operation, an expired grant, and an exhausted budget. Make the mock server echo the fake token, including across streamed chunks. Stop the proxy and policy service. Confirm there's no convenient unrestricted fallback.

Finally, revoke a task during a long response. Check new requests and existing streams separately. Kubernetes documents implementation-dependent behavior for established connections after NetworkPolicy changes. Pair client-side failures with external policy decisions and records of what the controlled upstream actually received.

The purpose of this design is to limit the operations available after an agent follows malicious instructions. In the opening example, allowing the provider's domain did not prevent an upload to an attacker-controlled account. A review needs to follow the request further: which account it uses, which operation is permitted, what data it carries, and what the response returns to the agent.

Written by

Matthew Keeley

Matthew is the founder of PlatformSecurity and focuses on agent security. He previously led platform security at SeatGeek and security engineering initiatives at Fanatics. His work includes Checkpoint, SeatGeek’s platform for temporary, self-service access to cloud infrastructure, and security tooling built into engineers’ everyday workflows.

Share

More in AI

All posts