Caloogy Article
中文

Egress Control: Where Can an Agent Connect?

Date
Jun 6, 2025
Series
Agent Sandbox
Reading
4 min
Topics
SandboxNetworkEgressAllowlist

The one-sentence version

When an injected Agent wants to steal data, the final step is always sending the data out. Controlling where it can connect (egress / outbound traffic) cuts off this final step. The most secure approach is default deny, allowlist only, and ensuring all traffic passes through a unified proxy for inspection. However, be careful of several easily overlooked egress points: DNS queries, websites within the allowlist that can "store data" (code hosting, documentation, pastebins), and images that are automatically loaded within model outputs.

This article has three layers:

  1. Layer 1: The Intuition: A building with only one exit and a security guard at the door.
  2. Layer 2: Real-World Use: Enterprise networks, cloud execution environments, and AI Agent practices.
  3. Layer 3: Principles and Engineering details.

Layer 1: The Intuition

1.1 Only One Exit

If a building has a hundred exits and you have to station a person at every single one, leaks are inevitable. A better way is: open only one exit and have a security guard at the door to inspect everyone and everything allowed to leave.

The internet works the same way:

1.2 "Disallowing Internet Access" is much simpler than "Disallowing Specific Websites"

Strategy Difficulty
No internet access at all Simplest and most reliable
Access only a few specified websites (Allowlist) Feasible, requires a proxy and list maintenance
Access everything except "bad websites" (Blocklist) Almost impossible to do well: attackers can register new domains at any time

Layer 2: Real-World Use


Layer 3: Principles and Engineering

3.1 Implementation Methods

Method Description
Network Isolation The sandbox has no network card or no default route, resulting in total disconnection
Firewall Rules Allow by IP and port; the problem is that modern website IPs change frequently and many share CDNs
Outbound Proxy All traffic must pass through a proxy, which allows traffic based on a domain allowlist (HTTPS can be determined via SNI or the domain in the CONNECT request) and logs all activity
TLS Inspection Proxy The proxy decrypts HTTPS to inspect content (requires the sandbox to trust the proxy's root certificate); enables content-level inspection but is more complex

Another benefit of the proxy solution: the proxy can inject credentials. The Agent in the sandbox does not see the actual API keys; the proxy automatically adds them when forwarding requests (see "Credential Leakage and Context Window").

3.2 DNS Exfiltration

Even if all HTTP traffic is blocked, if the sandbox can still perform DNS queries, data can still leak:

Encode data into subdomains and query:
  6d7920736563726574.attacker-domain.com
The attacker controls the DNS server for this domain, allowing them to read the data from the query logs.

DNS queries typically pass through multiple layers of recursive resolvers before reaching the attacker's server, and firewalls may not intercept them.

Countermeasure: The sandbox should only use a controlled DNS resolver; the resolver only resolves allowlisted domains; or only the proxy is allowed to perform DNS resolution, while the sandbox itself cannot.

3.3 "Legitimate Websites" in the Allowlist can be abused

Allowlists typically include code hosting, documentation, and package repositories. The problem is that these websites themselves allow users to upload content:

Allowlisted Website Possible Abuse
Code hosting platforms Pushing data to an attacker's repository, or writing it into Issues or comments
Package repositories Publishing a package that contains data (requires credentials)
Pastebins, Cloud docs Creating public documents
Any site with search functionality Placing data into search terms, which then appears in the recipient's logs

Countermeasures:

3.4 Don't forget "Client-side Egress"

An Agent's output is ultimately displayed in the user's browser or terminal. If the output contains external resources that are automatically loaded (images, iframes), these requests are sent from the user's browser, completely bypassing the sandbox's egress control (see "Markdown Image Data Exfiltration"). Therefore, egress control must be managed at both ends: the sandbox's egress and the rendering end's CSP.

3.5 Default Deny

If the proxy is unavailable or the allowlist fails to load, the system should deny all traffic rather than allowing it (see "Fail-closed"). Every denied request should be logged: an injected Agent attempting to connect to an unknown address is itself a highly valuable alert signal.


Summary

Layer Key points
Principle Default deny, allowlist only, unified proxy
Easy to miss DNS queries, write functions of allowlisted websites, client-side auto-loaded resources
Benefits Cuts off the final step of exfiltration; proxy can also manage credentials and log activity
Complementary measures Read-only credentials, path-level rules, rendering-end CSP, deny-as-alert