Prompt injection cannot yet be reliably prevented, so the control that decides whether an injected agent can actually leak data is where its traffic is allowed to go. An agent that reads a poisoned web page, ticket or email can be told to send secrets somewhere, but it needs an outbound channel to do so. Egress control removes those channels: a deny-by-default network, a proxy that only reaches named destinations, and output paths (rendered URLs, email and webhook tools) that cannot reach arbitrary recipients. This guide covers the exfiltration channels agents use, the enforcement layers available and how they compare, how to design per-agent allowlists, the identity behind egress policy, a rollout plan, and detection. It is written for platform, network and AppSec engineers running agents in production or giving coding agents network access. It builds on the sandbox guidance in the AI Agent Sandboxing and Code Execution Guide and goes deeper on the network and output side.
Key takeaways
- Assume injection, control the exit. Treat egress as the containment layer for prompt injection: an agent that cannot reach an attacker's server or send to an arbitrary recipient cannot complete most exfiltration.
- Hostname allowlists are necessary but leaky. Proxies that decide on the requested hostname without inspecting TLS can be bypassed through broad allowed domains and domain fronting, as agent vendors' own documentation warns.
- Egress is more than the network. Rendered markdown images, links, email, chat and webhook tools are all outbound channels; product-level controls such as trusted URL lists matter as much as firewalls.
- Policy should follow agent identity. Give each agent or workload its own egress identity (a client certificate, a service account, a pod label) so the proxy can apply that agent's allowlist and the logs show who sent what.
- Block the internal targets too. Cloud metadata, private ranges and localhost services are SSRF targets; the MCP specification recommends blocking them and using an egress proxy for server-side clients.
Why egress is the decisive control for agents
Indirect prompt injection works by placing instructions where an agent will read them. Model-level defences reduce the success rate but do not remove it, and every new tool or data source adds another place to plant instructions. What the attacker needs after a successful injection is a channel out: an HTTP request to their server, a URL the client will fetch, a message to an address they control, or a DNS lookup that carries data in the name.
That makes egress the place where an injection becomes an incident or stays a failed attempt. The ForcedLeak research against Salesforce Agentforce is a clear example: the injected instruction worked, but the exfiltration depended on the agent's output reaching an external URL, and Salesforce's fix was to enforce Trusted URLs for agent output. See the ForcedLeak breach analysis.
Exfiltration channels agents use
| Channel | How it works | Control |
|---|---|---|
| Direct HTTP request from code execution | Agent runs a command or script that POSTs data to an external host | Network deny by default; proxy allowlist; restrict methods to GET, HEAD, OPTIONS where possible |
| Data in URLs the client renders | Agent output contains an image or link whose URL carries data; the chat client or browser fetches it | Trusted URL allowlists for rendered content; Content Security Policy; disable automatic image rendering from untrusted hosts |
| Allowed broad domains | Data sent to a permitted platform the attacker can also read: code hosting, paste sites, object storage, collaboration tools | Narrow entries (exact hosts, paths); TLS-inspecting proxy for high-risk agents; tenant restrictions |
| Domain fronting and SNI tricks | TLS SNI names an allowed host while the encrypted request targets another behind the same CDN | TLS termination and Host header checks at the proxy; resolved-IP validation |
| DNS | Data encoded in lookups to an attacker-controlled domain | Only the platform resolver reachable; DNS allowlisting or analysis; block direct port 53 out |
| Non-HTTP protocols | Raw TCP, SSH, UDP or QUIC bypass HTTP proxies | Network namespace whose only route is the proxy; block UDP and non-proxy ports |
| Communication tools | Agent uses its email, chat, ticket or webhook tool to send data to an outside recipient | Recipient and destination allowlists in the tool; approval for external recipients |
| Internal targets (SSRF) | Agent or MCP client fetches metadata endpoints, internal admin APIs or localhost services | Block private, loopback and link-local ranges; IMDSv2; no route to metadata |
Enforcement layers compared
No single layer covers every channel. Combine one network layer that the agent cannot bypass with product-level controls on output and tools.
| Layer | Example mechanisms | Strengths | Limits |
|---|---|---|---|
| Agent runtime sandbox with proxy | Claude Code sandbox (bubblewrap network namespace on Linux, Seatbelt on macOS) with allowedDomains and deniedDomains | Per-session control on developer machines; non-proxy-aware tools and non-TCP traffic cannot leave | Decides on hostname without TLS inspection by default; MCP servers, hooks and file tools run outside the sandbox |
| Forward egress proxy | Smokescreen (HTTP CONNECT, per-role ACLs from mTLS identity), Squid and similar | Central, identity-aware policy; blocks private IPs after DNS resolution; report mode for rollout | Hostname-level unless it terminates TLS; clients must be forced through it |
| TLS-inspecting proxy | Proxy that terminates TLS with a CA trusted inside the sandbox | Path, method and content rules; defeats domain fronting | Certificate management, privacy and pinning issues; higher operating cost |
| Kubernetes NetworkPolicy | policyTypes: [Egress] default deny; explicit DNS allow | Native, per-pod-label, cheap | Layer 3 and 4 only, no domain names; needs a CNI that enforces it |
| CNI with FQDN policy | Cilium toFQDNs with matchName or matchPattern plus a DNS inspection rule | Domain allowlists per pod with port limits | Depends on the DNS proxy path; still not content-aware |
| Cloud network firewall | AWS Network Firewall domain lists using TLS_SNI, HTTP_HOST and AWS_ROUTE_53_RESOLVED_DOMAIN | Covers whole VPCs, hard for workloads to bypass | SNI and Host can be manipulated, so add IP or resolved-domain rules; coarse per workload |
| Product-level output controls | Trusted URL lists for agent output, CSP in chat clients, Codex method restrictions | Closes rendered-URL and tool channels the network cannot see | Vendor-specific; must be configured per platform |
For the difference between forward proxies and reverse proxies and how to deploy them, see the Proxies and Forward vs Reverse Proxy Security Guide.
Choosing for your environment
- Developer laptops with coding agents: use the agent's own sandbox with a managed allowlist (Claude Code supports
allowManagedDomainsOnlyandstrictAllowlist), plus the corporate secure web gateway behind it. - Hosted agents on Kubernetes: default-deny NetworkPolicy for the namespace, egress only to a forward proxy, FQDN or proxy allowlists per agent service account.
- Cloud-hosted agent platforms: run the agent in a VPC with no internet gateway route except through a firewall or proxy, and configure the platform's own trusted URL or connector restrictions.
- Small teams: one forward proxy with per-agent lists and report mode gives most of the value; skip TLS inspection unless an agent handles regulated data or runs untrusted code.
- Large organisations: central egress service with identity-based policies, TLS inspection for high-risk tiers, and policy as code reviewed like firewall changes.
Designing per-agent allowlists
- Start from tasks, not from "the internet": list what each agent must reach, typically model API endpoints, one or two package registries, specific SaaS APIs and internal services. Codex Cloud's presets (none, common dependencies, all) illustrate the spectrum; start at none.
- Exact hosts beat wildcards:
api.github.comis far narrower than*.github.com. Note the different wildcard semantics: in Smokescreen and Cilium a leading*.does not match the apex domain, while in AWS Network Firewall a leading.matches the domain and all subdomains. - Avoid attacker-writable destinations: any host where anyone can create content (gists, paste sites, public buckets, form services, link shorteners) is an exfiltration endpoint. Claude Code's documentation explicitly warns that allowing broad domains such as
github.comcreates exfiltration paths. - Restrict methods and ports: read-only research agents rarely need POST. Codex Cloud lets you restrict agents to GET, HEAD and OPTIONS. A Claude Code
allowedDomainsentry without a port allows every port on that host, so add:443. - Keep a deny list above the allow list: known paste and tunnelling services, newly registered domains and personal storage domains stay blocked even if a wildcard would allow them. In Smokescreen the global deny list wins over per-role policy.
- Block internal ranges explicitly: the MCP security best practices list the ranges server-side clients should block (
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,127.0.0.0/8,169.254.0.0/16,fc00::/7,fe80::/10) and warn against hand-written IP parsers that miss octal, hex and IPv4-mapped IPv6 encodings. Smokescreen blocks non-public addresses after resolution by default. - Handle DNS deliberately: allow only the platform resolver, pin resolution between check and use where you can (the MCP guidance flags DNS rebinding as a time-of-check to time-of-use risk), and log queries.
- Review allowlists for expiry: an allowlisted domain that lapses can be re-registered by an attacker, which is exactly what made ForcedLeak's exfiltration path work.
Output and tool channels
Network controls do not see what happens after the agent's answer reaches a user's browser or what a tool sends on the agent's behalf. These need their own allowlists.
- Rendered content: chat interfaces that auto-render markdown images will fetch whatever URL the model writes. Restrict rendering to trusted hosts, proxy images through a service that strips query strings, or render links as text. EchoLeak used data placed in a URL and a Content Security Policy that trusted broad Microsoft domains. See the EchoLeak breach analysis.
- Communication tools: email, chat and webhook tools should have recipient allowlists (internal domains, named channels) and require approval for external recipients.
- MCP servers: each server is a potential egress path with its own network access. Run remote MCP servers behind the same egress controls as agents, and do not assume a sandbox around the agent's shell also covers MCP servers: Claude Code's documentation states that MCP servers run outside its sandbox. See the Remote MCP Server Hardening Guide.
- Browser and computer-use agents: these generate arbitrary navigation by design; give them a separate egress tier with the strictest destination list and no access to internal networks.
Where identity fits
An egress rule is an authorisation decision: which workload may talk to which destination. It needs an authenticated workload identity, or the policy collapses to "anything on this subnet".
- Identity at the proxy: Smokescreen identifies clients by mTLS certificate (common name by default) and applies a per-role ACL. Issue each agent its own short-lived client certificate from a workload identity system such as SPIFFE, so policy and logs follow the agent, not the IP address. See the Cloud Workload Identity Guide.
- Identity in the cluster: label pods by agent and bind NetworkPolicies and FQDN policies to those labels and service accounts.
- Credentials at the edge: where possible, keep API keys out of the agent and inject them at the proxy for approved destinations only. Claude Code's experimental
tlsTerminatesetting exists to support credential masking at its proxy. A key that only works through the proxy cannot be used from an attacker's server if it leaks. - Metadata endpoints: blocking
169.254.169.254from agent workloads stops injected code inheriting the host's cloud role. See the EC2 Instance Metadata Service Hardening Guide.
Implementation steps
- Map agents and channels. For each agent record where it runs, what it can execute, its tools that send data out, and how its output is rendered.
- Force a single route out. Put agent workloads in a network namespace, subnet or namespace whose only egress is the proxy or firewall. Verify with a test that direct connections and UDP fail.
- Observe in report mode. Run the proxy in report or alert mode (Smokescreen's
reportmode, firewall alert rules) for two to four weeks to learn real destinations per agent identity. - Write per-agent allowlists. Exact hosts and ports, methods where supported, global deny list for paste, tunnelling and personal storage services, private ranges blocked.
- Enforce in rings. Switch to enforce for internal or low-risk agents first, then customer-facing and high-privilege agents. Rollback is a per-agent switch back to report mode, not removal of the proxy.
- Close output channels. Configure trusted URL lists and CSP for rendered output, recipient allowlists for communication tools, and egress controls for MCP servers.
- Add inspection for high-risk tiers. TLS-terminating proxy for agents that run untrusted code or handle sensitive data, with path and method rules.
- Test continuously. Include exfiltration attempts (POST to an unknown host, data in an image URL, DNS lookups to a test domain, a message to an external address) in red team and CI suites, and assert they fail.
Detection and measurement
| Signal | Source | Why it matters |
|---|---|---|
| Denied egress by agent identity | Proxy and firewall logs | A spike after reading external content is a likely injection attempt |
| Denied requests to metadata or private ranges | Proxy, firewall, VPC flow logs | High-confidence signal of SSRF or injected code |
| Large or frequent uploads to allowed domains | Proxy byte counts, TLS inspection logs | Exfiltration through permitted platforms |
| Long or high-entropy DNS names | Resolver logs | DNS tunnelling |
| Rendered URLs with long query strings to external hosts | Chat client or image proxy logs | URL-based exfiltration |
| External recipients in agent email or chat tools | Tool audit logs | Tool-mediated exfiltration |
| Allowlist changes | Policy repository, change logs | Silent widening of egress |
Metrics
- Agents with deny-by-default egress enforced: target 100 per cent of production agents.
- Wildcard and attacker-writable entries: count across all allowlists, trending down.
- Egress identity coverage: share of agent traffic attributed to a named agent identity rather than an IP.
- Exfiltration test pass rate: share of red team exfiltration cases blocked, per release.
- Time to review a denied-egress alert: median under one working day.
Framework mapping
| Area | Reference |
|---|---|
| Adversary behaviour | ATT&CK T1567 Exfiltration Over Web Service (T1567.002 to cloud storage), T1048 Exfiltration Over Alternative Protocol, T1071.004 DNS, T1572 Protocol Tunneling, T1105 Ingress Tool Transfer, T1552.005 Cloud Instance Metadata API; ATLAS AML.T0086 Exfiltration via AI Agent Tool Invocation, AML.T0025 Exfiltration via Cyber Means, AML.T0051.001 Indirect prompt injection |
| Defensive techniques | MITRE D3FEND D3-OTF Outbound Traffic Filtering, D3-DNSAL DNS Allowlisting, D3-DNSTA DNS Traffic Analysis |
| Boundary and flow controls | NIST SP 800-53 SC-7, SC-7(5) Deny by Default, SC-7(8) Route Traffic to Authenticated Proxy Servers, AC-4 Information Flow Enforcement, CM-7 |
| Monitoring | NIST SP 800-53 SI-4(4) Inbound and Outbound Communications Traffic, AU-12; CSF 2.0 DE.CM-01 |
| Programme level | CSF 2.0 PR.IR-01, PR.DS-02; ISO/IEC 27001:2022 A.8.20, A.8.22, A.8.23; CIS Controls v8.1 Control 9, 12 and 13 |
| AI risk | OWASP LLM01:2025 Prompt Injection, LLM02:2025 Sensitive Information Disclosure, LLM06:2025 Excessive Agency |
Common failure patterns
- Proxy variables without a closed network: setting
HTTPS_PROXYwhile the workload still has a direct route out. Tools that ignore proxy variables, and attackers, go straight past. - Allowing whole platforms:
*.github.com,*.amazonaws.comor a collaboration suite in full, any of which an attacker can also write to. - Forgetting the client side: a locked-down agent whose answers are rendered by a chat client that fetches any image URL.
- Sandbox around the shell only: MCP servers, hooks and plugins running outside the sandbox with full network access.
- Stale allowlists: entries for domains that have expired or changed hands, as in ForcedLeak.
- Policy by IP address: rules that cannot tell one agent from another on a shared node, so the most permissive agent's list applies to all.
Lessons from incidents
- Trusted URL enforcement: ForcedLeak's injected instructions in a public web-to-lead form led Agentforce to send CRM data out through an image URL on a domain that was allowlisted but had expired; Salesforce enforced Trusted URLs for agent output on 8 September 2025 and secured the domain.
- Trusted domains in CSP: EchoLeak showed that a Content Security Policy trusting broad first-party domains did not stop data leaving: the exploit placed data in a URL and got past link redaction and a CSP that trusted Microsoft domains. Allowlisting whole first-party estates is not the same as allowlisting destinations nobody else can write to.
- Agents with developer egress: in the Sentry MCP agentjacking research, coding agents ran commands from fake error reports with the developer's full network access; default-deny egress from the agent's shell would have stopped the package download.
Practitioner checklist
- Give every agent workload a single, enforced route out through a proxy or firewall; verify direct and UDP connections fail.
- Identify agents at the proxy by workload identity (mTLS certificate, service account, pod label) and apply per-agent allowlists.
- Write allowlists as exact hosts and ports, restrict methods where possible, and keep a global deny list for attacker-writable services.
- Block metadata, private, loopback and link-local ranges for agents and server-side MCP clients.
- Allow only the platform DNS resolver and monitor for tunnelling patterns.
- Configure trusted URL lists and CSP for rendered agent output and recipient allowlists for communication tools.
- Put MCP servers, hooks and plugins behind the same egress controls as the agent.
- Use TLS-inspecting proxies for agents that run untrusted code or handle sensitive data.
- Roll out in report mode, enforce in rings, and keep per-agent rollback switches.
- Run exfiltration test cases on every agent release and review allowlists quarterly for expired or transferred domains.
Standards and references
- Model Context Protocol: Security Best Practices
- Anthropic: Claude Code sandboxing
- OpenAI: Codex agent internet access
- Stripe: Smokescreen egress proxy
- Kubernetes: Network Policies
- Cilium: Locking down external access with DNS-based policies
- AWS: Network Firewall domain list rule groups
- MITRE D3FEND: Outbound Traffic Filtering
Related NHI Mgmt Group resources: AI Agent Sandboxing and Code Execution Guide · Confused Deputy in AI Agents Guide · Network Segmentation Guide · Prompt Injection Incident Response Playbook