AI agent firewall: limiting what your coding agent can reach
An AI agent firewall, for a coding agent on your Mac, is a limit on where the agent's commands may connect. You set it in the agent's own sandbox or in a container, because Apple's built-in firewall is about unwanted contact started by other computers. The defaults differ from agent to agent, and the table below lists them. First action in Claude Code: run /sandbox.
A file fence alone is half a defence, and an AI agent firewall is the other half. Effective sandboxing needs both file and network isolation, and without the network side a compromised agent could send out your SSH keys. This page shows how to close that route for each agent and what it still leaves open. The wider picture of every layer is in AI agent guardrails.
01Is there a firewall for an AI agent?
Not as one product you install and forget. An AI agent firewall is a setting, and what you can do is limit the network side of the agent's sandbox. A sandbox is a fenced area the operating system builds around commands, so they touch only what the fence allows. The comparison is on AI agent sandbox.
Two terms help. Egress means traffic going out of your machine, as opposed to traffic coming in. An allowlist is the list of hosts the agent may reach, with everything else refused. Most settings below are egress allowlists, so each one names what may go out.
02What the agent can reach by default
| Agent or setup | Network default | How to tighten it |
|---|---|---|
| Claude Code sandbox | Off until you turn the sandbox on; then a proxy checks hosts against allowed domains, which start empty | Add only the hosts you need, because a broad one such as github.com is a path out |
| Cursor sandbox | Blocked by default, opened by a network mode and sandbox.json; the default mode adds package managers and language tools | The sandbox.json Only mode allows just your list |
| Codex | Network off, with an OS-enforced sandbox; in workspace-write, the mode that lets it edit inside the project folder, it stays off unless enabled in config | Codex's docs say to use caution when enabling network access or web search |
| Gemini CLI | Sandbox turned on with a flag, a variable or a setting; its default macOS profile permissive-open allows broad reads and network | Choose the strict-proxied profile with the SEATBELT_PROFILE environment variable, which sends network through a proxy |
| Docker Sandboxes | Each sandbox is a microVM, a small virtual machine, with its own network; presets Open, Balanced and Locked Down | Balanced permits common dev services and blocks other destinations unless approved; in Locked Down destinations need an allow rule |
| Dev container | The reference container includes init-firewall.sh, a script that limits outbound traffic to allowed destinations | Pair the no-prompt flag with egress limits |
A proxy is a middleman program that checks each connection before it leaves your Mac.
03Claude Code: the sandbox proxy and its limits
Run /sandbox in a session, or set sandbox.enabled to true in a settings file such as ~/.claude/settings.json. With the sandbox on, network access goes through a proxy that checks each host against the allowed domains. A host that is not on the list is not simply refused. In the modes where Claude asks you first (manual, acceptEdits and plan) you get a prompt. In bypassPermissions mode, which skips prompts, the host is allowed. If you set sandbox.network.strictAllowlist or allowManagedDomainsOnly, the proxy refuses it in every mode. Two limits are worth knowing. The proxy does not inspect TLS by default, meaning it does not look inside encrypted traffic. And a broad allowed domain such as github.com creates ways to send data out.
One trap sits outside the sandbox. A WebFetch rule alone does not prevent network access if Bash is allowed, because Claude can still use curl, wget or other tools. A deny rule also misses the same program called by its path or inside sh -c, so pair the restriction with the sandbox's network allowlist. More on the fence itself is on Claude Code sandbox.
04Cursor: three network modes
Cursor's sandbox blocks the network by default and opens it by mode. The default mode is sandbox.json plus Defaults, the package managers and language tools, and the default allowlist includes github.com. Allow All lets the sandbox reach everything. sandbox.json Only allows only your list and does not add Cursor's defaults. A file at ~/.cursor/sandbox.json applies to all projects. In Auto-review, a command that needs full network access can't use the sandbox and goes to the classifier instead, so the sandbox list is not a hard wall there.
A local config cannot weaken team-admin policies or Cursor's hardcoded security rules. Details are on Cursor sandbox.
05Codex and Gemini CLI
Codex starts with the network off. In the Auto preset it asks for approval before commands that need network access. For its cloud version the advice is to point Codex only at trusted resources. Keep internet access as limited as possible: off, or on with a domain allowlist. See Codex sandbox.
Gemini CLI is the one to change. Once its sandbox is on, the default profile allows broad reads and network. The strict-proxied profile restricts reads, writes and network through a proxy. A Docker or Podman container is the other route. The sandbox itself is switched on with a command flag, the GEMINI_SANDBOX environment variable or settings.json, in that order of precedence.
06A container with a firewall in front
When an agent runs without prompts, a container or VM is the fence, and the network rule goes with it. Claude Code's --dangerously-skip-permissions flag, which stops the prompts, is meant for isolated environments such as containers, VMs and dev containers without internet, and Anthropic's docs recommend pairing it with the egress limits above. A dev container is a container your editor opens your project in. The setup is on Claude Code devcontainer, Docker's own sandbox tool is on Claude Code in Docker, and the flag's story is on dangerously-skip-permissions.
07Outgoing firewalls on the Mac
An outgoing firewall is an app that asks you before a program on your Mac connects out. Apple's built-in one is about incoming connections. LuLu is a free open-source firewall that blocks unknown outgoing connections, and Little Snitch shows a connection alert so you can allow or deny each one. LuLu's alert names the process trying to connect and the destination. They watch the whole Mac, not one agent. For the built-in firewall, read Mac firewall, and for one outgoing app, Little Snitch.
08What an AI agent firewall does not do
It does not shrink the allowed list for you, so a host you permitted stays a route out. It does not look inside encrypted traffic. And it limits where a command may connect; it does not show which programs started on the Mac.
A too-wide list has caused a real advisory. In CVE-2025-55284, an overly broad allowlist of safe commands let Claude Code read a file and send its contents over the network without confirmation, and standard auto-update delivered the fix. The advisories are listed on Claude Code security.
Artificial Immunity's free, open-source core sits on the other side of this: it does not limit connections, it watches agent sessions and program starts on your Mac and reports what it finds. How to see what ran is on AI agent monitoring.
09The short version
An AI agent firewall is the network setting of your agent's sandbox or container. Check the default of the agent you use, close what you do not need, and keep the allowed list short. For the layers around it, see AI guardrails.
FAQ
Is there an AI firewall?
For a coding agent on your Mac, the working version is a network limit inside the agent's sandbox or container. Claude Code, Cursor, Codex and Gemini CLI each have one, and the table on this page lists the defaults.
Can AI agents control my computer?
A coding agent can run shell commands, and an approved Bash command in Claude Code can write anywhere your user account can. A sandbox and a network limit narrow that.
Are AI agents a security risk?
They can be. Without network isolation, a compromised agent could send out sensitive files such as SSH keys, which is why a file fence needs a network limit beside it.
Who are the big 4 AI agents?
For coding on a Mac this page covers four: Claude Code, Cursor, Codex and Gemini CLI. Each has its own network default, listed in the table.
Does the built-in Mac firewall limit an agent?
No. Apple's firewall protects against unwanted contact started by other computers, and its settings choose how much to block incoming connections. Limiting where an agent connects out needs the agent's own settings or an outgoing firewall.
Is closing the network enough?
It closes the biggest route for sending files out, but allowed hosts stay open. A broad allowed domain such as github.com can still become a path out.
Related guides
Sources
- Claude Code docs: sandboxing
- Claude Code docs: permissions
- Claude Code docs: development containers
- Cursor docs: run modes
- OpenAI Codex docs: approvals and security
- OpenAI Codex docs: internet access
- Gemini CLI docs: sandbox
- Docker docs: sandboxes
- Apple Support: block connections to your Mac with a firewall
- Objective-See: LuLu
- Objective Development: Little Snitch
- Artificial Immunity