Topic 4 of 5 · 4 min read
Default-deny network egress for agents
Goal: Write an egress policy that lets an agent install packages and call one API while blocking every other destination.
Block all outbound traffic from the sandbox by default, then allow only the few named destinations the task needs, because most agent attacks end with data being sent somewhere.
Check yourself · 1 of 3
What does default-deny egress mean for an agent sandbox?
Why it matters
Prompt injection can make an agent read a secret and send it to an attacker. If the sandbox cannot reach the attacker's server, the leak stops, even when the model was fooled. Egress control is the part of a sandbox that turns "the agent made a mistake" into "nothing left the box".
How to do it
- List what the task needs. A typical coding job needs the package registry, the git host and perhaps one model or internal API. Write the exact hostnames.
- Deny everything else. Use a firewall rule or a network with no route to the internet, and send all traffic through one proxy.
- Allow by domain at the proxy. Package managers and tools respect proxy settings, and the proxy checks each requested hostname against the allow-list and logs the rest.
- Control DNS. Let the sandbox resolve names only through your resolver. Otherwise encoded data can leave inside DNS lookups.
- Log denials. A blocked request is useful information. Review it to see whether the agent needed something real or was steered.
Before and after
# Weak: open internet
network: bridge
# Better: proxy with an allow-list
network: internal
proxy: egress-proxy:3128
allow:
- registry.npmjs.org
- github.com
- api.example-model.com
default: deny
The second policy is short and readable. Anyone can review it in a minute.
What goes wrong
- Wildcards. Allowing
*.github.ioor a broad cloud domain lets an attacker host a receiver on a domain you just trusted. - Allowed domains as an exit. The agent can still push data to a public repository or paste service if the allow-list includes it. Keep the list narrow and token scopes small.
- Forgotten DNS. Blocking HTTP but leaving open DNS keeps a covert channel.
- Direct IP access. Allow-lists by name do nothing if the sandbox can connect to raw IP addresses. Force traffic through the proxy.
- Allow all after one failure. A single blocked domain leads someone to open everything.
Examples
Package install allow-list
{
"default": "deny",
"allow": ["registry.npmjs.org", "github.com"]
}
The agent can install dependencies and fetch code, and a request to any other host is refused and logged.
Reading a denial log
A log shows the agent trying to reach a paste site right after reading a .env file. That is a signal worth stopping on: check the prompt and the content it read for injected instructions.
Key points
- Default deny: the sandbox can reach nothing until a destination is named.
- Route traffic through one proxy that allows exact hostnames and logs denials.
- Control DNS, because blocked HTTP with open DNS still leaks data.
- Avoid wildcards and public hosting domains; an allowed domain can still be an exit.
- Fix a blocked call by adding the one domain it needs, never by opening the network.
Common mistakes
- Allowing a wildcard domain or a public hosting site.
- Blocking web traffic but leaving DNS open.
- Allowing direct IP connections that bypass the proxy.
- Opening the whole network after one blocked request.
Check yourself · 2 of 3
Why can an allow-list entry such as *.github.io be risky?
Check yourself · 3 of 3
A sandbox blocks all HTTP but allows any DNS lookup. What is the problem?
Practice items, not counted towards your mastery.
Start here
- Sandboxing (Claude Code docs) (opens in a new tab)DocsFree
How a coding agent's sandbox limits files and network, and how it pairs with permission prompts.
- Making Claude Code more secure and autonomous with sandboxing (Anthropic) (opens in a new tab)ArticleFree
Why filesystem and network isolation must work together, explained by the team that built it.
- Docker Engine security (opens in a new tab)DocsFree
What containers isolate, what they share with the host, and how capabilities and the daemon socket matter.
More for this topic
- OWASP Top 10 for LLM Applications (opens in a new tab)StandardFree
Names excessive agency and insecure output handling, the risks a sandbox contains.