Network egress controls restrict what network connections an AI agent's runtime can make. They operate at the network level, below the application layer, providing a defense-in-depth measure against data exfiltration and command-and-control attacks.
Application-level controls (policy rules that restrict tool arguments) work for known tools. But an agent's runtime may have capabilities beyond the declared tools:
Network egress controls catch these cases because they filter all traffic from the process, regardless of how it originated.
Configure iptables, nftables, or cloud security groups to restrict the agent's outbound traffic:
# Allow only specific destinations
iptables -A OUTPUT -d api.openai.com -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -d your-control-plane.com -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -j DROP
If running in Kubernetes, use NetworkPolicy resources:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: agent-egress
spec:
podSelector:
matchLabels:
app: ai-agent
policyTypes:
- Egress
egress:
- to:
- ipBlock:
cidr: 10.0.0.0/8 # Internal services only
ports:
- port: 443
protocol: TCP
Restrict which domains the agent can resolve:
This prevents data exfiltration via DNS tunneling and blocks connections to unknown destinations.
Network egress controls and application-level policy rules are complementary:
| Layer | What it controls | Granularity | |-------|-----------------|-------------| | Policy engine | Tool call arguments (URLs, paths) | Per-tool, per-argument | | Network egress | All TCP/UDP connections | Per-destination IP/port |
The policy engine catches misuse of legitimate tools. Network egress catches bypass attempts through uncontrolled channels.
Run agent processes in containers with restricted networking:
# Agent container with restricted capabilities
FROM node:20-slim
RUN apt-get update && apt-get install -y --no-install-recommends dumb-init
USER node
Use Docker network configuration or container runtime security profiles to enforce egress restrictions.
Log blocked egress attempts. A spike in blocked connections may indicate:
Route these logs to your security monitoring system for investigation.
Explore more guides on AI agent safety, prompt injection, and building secure systems.
View All Guides