Egress filtering decides which outbound traffic may leave a network, a host or a container, and where it may go. Most networks check incoming connections with care and let nearly all egress traffic out, because a bad outbound rule breaks something people notice the same day. AI agents make that gap harder to live with. They open their own connections from laptops, sandboxes and Kubernetes Pods, under the identity of whoever started them.

What is egress filtering?

Take a build server. It needs a package registry, a git host and an artifact store, and nothing else on the internet. Egress filtering is how you write that down and enforce it: every outbound connection is checked against rules, and anything the rules don’t allow is blocked or at least logged. One of those rules might read: the build server may reach registry.npmjs.org on TCP 443.

The NIST glossary is shorter still: “Filtering of outgoing network traffic,” citing NIST SP 800-41 Rev. 1, its guide to firewalls and firewall policy. You’ll also see outbound traffic filtering, egress traffic filtering and egress control, which all name the same practice, while egress security tends to mean the broader goal that filtering serves. Egress just means leaving.

Each rule has a source, a destination, a protocol or port, and an action (allow, deny or log). How precise the source can be depends on where the rule runs. A perimeter or cloud firewall sees an IP address. A host firewall knows which machine sent the packet. A forward proxy can read the hostname the client asked for, and an agent on the host, or a sidecar container in the Pod, can tell which process opened the connection.

What is egress traffic? Ingress vs egress filtering

A laptop in the office calls an API on the internet. For the office network, the request is egress traffic and the reply is ingress traffic. Egress traffic is whatever crosses a boundary on the way out, whether the boundary is a corporate network, a cloud VPC, one host or a Kubernetes Pod. Ingress filtering and egress filtering are the rule sets for each direction, and they usually sit on the same device.

Because direction depends on the boundary, one connection can be both. A request leaving a Pod is egress for the Pod and, one hop later, ingress for the database it reaches. A rule set only makes sense once you’ve said which boundary it guards.

The public address outbound traffic leaves from, usually a NAT gateway’s, is the egress IP. Partners allowlist it, so it pays to keep it stable.

Ingress filteringEgress filtering
DirectionArriving from external networksLeaving for external networks
What it protectsYour services, from outside attackersYour data and other networks, from a compromised host inside
Typical rulesExpose only published services; drop spoofed internal source addressesAllow only the destinations each workload needs; send only your own source addresses
Example threatAn exploit sent to an exposed portMalware uploading stolen files or calling its operator

The two directions get very different attention. Inbound is where attacks visibly arrive, so its rules get reviewed. Outbound is where a wrong rule causes an outage, so it’s often left at allow-all.

Why does egress filtering matter?

Egress filtering earns its keep after something has already gone wrong. A phishing click, a poisoned dependency or a leaked credential puts code inside your network, and that code is no use to whoever planted it until it can open a connection out. Outbound rules decide whether it can. The attempts that fail land in the deny log, where someone can notice them.

Almost everything an attacker wants next is an outbound connection. Stolen files have to be uploaded somewhere. Malware has to check in with its operator for instructions, which is what a command-and-control callback is. A worm has to reach its next host, and a device drafted into a botnet has to reach its target. Even with no attacker involved, someone running a personal mail server or a tunnel is routing around the controls on the official ones.

The Software Engineering Institute at Carnegie Mellon (SEI) makes a point in a 2018 article that’s easy to lose: egress filtering protects other organizations’ networks first. WannaCry is one example. It spread in 2017 over SMB on port 445, and filtering that port in both directions would have slowed it. The other is the 2016 attack on the DNS provider Dyn, where infected devices sent floods of DNS traffic over port 53, traffic that had no reason to leave most of those networks: if your clients use your own resolvers, only the resolvers need port 53 outbound.

Default deny vs default permit egress

The two postures fail in opposite directions. Default permit lets everything out and blocks a list of known-bad destinations, so a channel nobody has listed yet stays open. Default deny blocks everything and allows a list of known flows, so a flow nobody listed breaks. The SEI calls default deny the more secure stance, on one condition that decides everything: you need to know every flow that has to leave.

PostureWhat leavesRollout effortHow it fails
Default permitEverything except what you blockLow: add blocks as threats appearOpen: a new exfiltration channel works until someone blocks it
Default denyOnly the flows you allowHigh: every needed flow has to be known firstClosed: a missing rule breaks an application until someone allows it

On a new network that condition is cheap, since each application asks for its rule as it arrives. On an existing one, switching in a single change breaks every application nobody listed, so we’d go one workload at a time. Pick something with few destinations and a lot to lose, such as a build server or a CI runner, and run its rules in log-only mode long enough to see the monthly jobs, which means a full month. Then enforce default deny on that workload alone. Every deny after that is either a rule you missed or an attempt someone should look at, and reading the log is how you tell which. Once it goes quiet, move on to the next workload.

Egress filtering best practices

Most egress filtering best practices are port numbers, and the SEI’s 2018 list still holds. It was written with large organizations in mind, though none of it needs a large team:

  • Let packets leave only with your own registered, routable source addresses. Nothing from a private RFC 1918 range, such as 10.0.0.0/8, belongs on the internet, and the same anti-spoofing filter stops a compromised host from forging another network’s addresses.
  • Keep internal-only services inside. Windows file sharing and RPC (SMB on TCP 445, NetBIOS on TCP/UDP 137-139, MS RPC on TCP/UDP 135) and management protocols (SNMP on UDP 161-162, Syslog on UDP 514, TFTP on UDP 69) rarely need the internet. If a partner needs one, allow it to that partner’s addresses only.
  • Block services that see more abuse than business use. The SEI’s example is IRC, typically on TCP 6660-6669, a common command-and-control channel.
  • Pin DNS (53), SMTP (25) and web traffic to the few hosts that should send it: your resolvers, your mail relays, and your outbound web proxy if you run one.

Before any of that, list what actually has to leave: package registries, update servers, the SaaS APIs your code calls, partner endpoints. Write rules against hostnames or workload identities (a service account, a Pod label, a process) wherever the enforcement point can see them, since SaaS and CDN addresses move. Roll each new rule out in log-only or dry-run mode before enforcing it. And give the deny log an owner. A deny log nobody reads hides the rule that broke last week’s deploy and the host that tried to reach an IRC server, equally well.

Layer 3/4 vs layer 7 egress filtering

To a layer 3/4 rule, cloning a repository from GitHub and pushing to it look the same: TCP to port 443 on the same address. Layer 3/4 egress filtering reads only IP addresses, ports and the transport protocol. Layer 7 egress filtering reads the application protocol, and there the two differ. An HTTPS push is a POST to the repository’s git-receive-pack path, while clones and fetches use git-upload-pack, so a layer 7 rule can let one through and refuse the other.

The transport matters too. Over SSH, a push runs git-receive-pack as the remote command, and GitHub also serves SSH on port 443 at ssh.github.com for networks that block port 22. A rule that only closes port 22 misses that, and a rule that only parses HTTPS misses SSH entirely, which is why the git push guide in our docs handles both.

Shared infrastructure is the other place IP rules break down. When dozens of services sit behind one CDN or load balancer address, allowing the address allows all of them. A layer 7 rule reads the hostname from the TLS SNI field or the HTTP Host header instead. Reading past the hostname on HTTPS means decrypting the traffic, which is what SSL/TLS inspection does, and that’s the price of layer 7: a CA certificate to distribute and a list of clients to exclude.

What an IP allowlist misses: the Claude Code devcontainer

Anthropic’s reference devcontainer for Claude Code ships a layer 3/4 allowlist, and we took that firewall apart. Its init-firewall.sh resolves each allowed hostname with dig and adds the returned IP addresses to iptables. After that, nothing checks the hostname on the connection. We found three ways out. A load balancer on an allowed IP that routes by SNI or Host header serves other hostnames too. Port 22 is open to any address. And the allowed services accept uploads, so a secret can leave inside a published npm package or a GitHub gist.

Command allowlisting and Claude Code hooks work one level up. They check which shell commands an agent may run, and whatever traffic those commands produce still has to get past the egress rules.

Egress firewall vs egress proxy vs egress gateway

Ask how each one gets bypassed. That’s the quickest way to tell an egress firewall, an egress proxy and an egress gateway apart. A firewall matches packets on addresses and ports, so an allowed IP that serves other hosts gets around it, and so does a tunnel inside allowed traffic. A proxy terminates the client’s connection and sees the hostname, but in explicit mode it only sees clients that honor their proxy settings. A gateway works while nothing has another route out.

Where it runsWhat it seesIdentity it knows
Egress firewallNetwork edge, security group or hostIP addresses, ports, protocolSource address or host
Egress proxyOn a host, in a sidecar or at the edgeHostname; requests with TLS inspectionThe user or workload, if it authenticates them
Egress gatewayAt the exit of a network, VPC or meshWhatever runs there: firewall rules, a proxy or bothSource network, or the mesh’s workload identity

Plenty of products are two or three of these at once, which is why the names blur. The arrangement we’d recommend stacks them. The gateway is the only route out, hostname and request rules run on a proxy at the gateway or next to the workload, and a firewall drops anything that tries to leave some other way. That firewall rule is what turns an explicit proxy’s blind spot into a dropped connection.

Where egress control gets hard

Writing the first egress rules takes an afternoon. Keeping them correct is the real job, and it’s the reason the topic draws so many complaints on networking forums.

Allowlists age first. SaaS providers, package registries and CDNs change IP addresses without telling anyone, so a rule pinned to an address breaks on someone else’s schedule while a rule written against a hostname keeps working. Default deny then surfaces every flow nobody inventoried (OS updates, telemetry, license checks), and each one arrives as a ticket asking for the rule to be widened.

Encryption is the next wall. Layer 7 rules on HTTPS need TLS inspection, and clients that pin certificates or carry their own trust store fail when inspected, so every inspection policy grows an exclusion list. Our own docs tell you to keep applications that don’t trust the Formal certificate out of the TLS stage, naming some Python scripts that skip the system CA store, or they’ll raise trust errors.

Last, a proxy filters only what reaches it. An explicit proxy sees the clients configured to use it, and everything else goes straight out. You can block direct egress at the network layer so the proxy becomes the only route, or intercept transparently on the host so clients never need to know a proxy exists. On laptops we’d pick transparent interception, because nobody controls the proxy settings of every tool an engineer installs.

Egress traffic from AI agents and sandboxes

Start a coding agent in a terminal and look at its connections from the network’s side. It’s the engineer’s user, device and IP address. A firewall that decides by address can’t separate the agent from the person, or from the git, curl and headless browser processes the agent starts on its own, and cloud agents are harder still, running in short-lived VMs and Pods whose addresses change from one run to the next.

A domain allowlist is the usual first move, and it does less than it appears to. github.com takes pushes on the same hostname it serves clones from, and package registries and paste sites accept uploads just as readily. Anthropic’s docs for Claude Managed Agents say the same of its own sandbox: “Network access is granted by host, not by operation.” Kevin Qiu, Lead Security Engineer at Latent Health, describes the moment teams notice:

“Going from 0.0.0.0/0 to an allowlist felt like progress, until we realized every allowed domain is still an exfiltration channel. Formal lets our production agent do the work safely.”

— Kevin Qiu, Lead Security Engineer @ Latent Health

A perimeter firewall has none of the context this takes. The enforcement point has to know which process opened the connection and that process’s ancestors, so a curl the agent spawned counts as the agent, and it has to classify the protocol, since LLM calls, MCP tool calls, git, SSH and cloud APIs can all share port 443. Decisions are per request: a read goes through, a write to the same host doesn’t. The human behind the agent should come from a short-lived token such as OIDC rather than a shared secret, which is how we handle cloud agents ourselves, and every request gets logged against both.

Our egress proxy for AI agents page makes the agent-specific case against plain allowlists. AI tools employees install on their own raise the same questions, covered under shadow AI.

Egress traffic from Kubernetes Pods

A new Pod can reach anything. The Kubernetes documentation says a Pod is non-isolated for egress by default, so every outbound connection is allowed until a NetworkPolicy selects it. NetworkPolicy itself works at the IP address or port level (OSI layer 3 or 4): which Pods, namespaces and IP blocks a Pod may reach, and on which ports. Rules on hostnames or requests need an egress proxy in the Pod’s path, such as a Kubernetes egress sidecar.

How Formal filters agent egress

Formal Endpoint is the egress proxy we built for agent traffic. It runs on macOS and Linux machines, as a sidecar in Kubernetes Pods and Amazon ECS tasks, and inside cloud agent VMs. Network rules choose which connections it takes over, and Rego policies decide what happens to the traffic it inspects.

The git push case above shows the shape well. Its network rule is a CEL condition in three stages. The pre_tcp stage, which only macOS evaluates, is process.has_agent_ancestor: true for a known agent and for every process it spawns, git and ssh included. The pre_tls stage checks hostname in ["github.com", "ssh.github.com"]. The post_tls stage runs after the Endpoint has terminated TLS and classified the protocol, and checks technology in ["http", "ssh"]. The policy then blocks an HTTPS POST to a protected repository’s git-receive-pack path, or an SSH session whose command is git-receive-pack for that repository. Clones keep working, and a push from the engineer’s own terminal never matches the rule.

The Codex Desktop guide works the other way round and allows only what’s listed. Its rule selects Codex by its signed bundle ID on the process or any ancestor, and its policy allows model traffic, MCP servers registered by name and the ChatGPT calls Codex needs for sign-in. Anything else from that process tree, including Codex’s built-in web search and any browser it launches, gets a block that reads “Direct web access blocked: use an approved MCP server”. The engineer’s own browser has no Codex in its ancestry and is left alone. Both guides start their policies in Draft or Dry-run.

Interception is opt-in, and that’s the limit to understand first. A connection that matches no network rule passes through uninspected, so a default-deny policy in Formal covers the traffic a rule selects while the rest of the machine keeps the egress it had. Both guides are macOS-only because they rely on code-signed process identity; on Linux, agents are matched by process name. Network rules and Transparent Mode aren’t available on Windows yet. On Fargate, which doesn’t allow NET_ADMIN, the Endpoint runs as an HTTP/HTTPS proxy, and a client that ignores the proxy settings goes around it. Our secure web gateway for AI agents page goes further into TLS inspection and agent sandboxes.