People ask this from two directions. Some want Claude Code to read the docs for a library it does not know. Others want to know whether a prompt hidden in a README could make it send a file somewhere. Both get the same answer: the agent has several separate routes to the network, and each one has its own switch.
Three routes out, and a few more
Anthropic's tools reference lists the built-in tools. Two are about the web, and a third reaches it whenever a command does.
| Route | What it does | What limits it |
|---|---|---|
| WebFetch | Fetches one URL, turns the page into Markdown and hands Claude what a second model call extracts from it | WebFetch(domain:...) permission rules |
| WebSearch | Runs a query on Anthropic's search backend and returns titles and URLs | A bare WebSearch rule, all or nothing |
| Bash | Runs any shell command: curl, git, npm install, a script | Bash permission rules, and the Bash sandbox's allowed domains |
Then there are the processes Claude Code starts that are not tools. Local MCP servers, hooks and helper commands run with your full access, according to the sandboxed Bash tool page, so they reach the network as any program you run does. And every turn goes to the model provider's API, which is how the agent works at all.
What it asks before it goes online
In the default mode, which Anthropic calls Manual, WebFetch prompts before each fetch. The exceptions are domains your rules already allow or deny, and a built-in set of preapproved documentation domains that fetch without a prompt. Shell commands prompt too, apart from a short list of read-only commands. Our notes on how Claude Code permissions work cover the order in which rules apply.
The prompt for a fetch has a third choice besides yes and no: "Yes, and don't ask again" for that domain. It saves a WebFetch(domain:...) allow rule to .claude/settings.local.json for the repository, so the host stays open in later sessions.
The faster modes change this. Auto mode and bypass permissions mode skip the fetch prompt unless an explicit ask rule names the domain, which is one reason skipping permissions in Claude Code is a network decision as much as a file one.
Two details are easy to miss. WebFetch refuses localhost and any hostname without a dot, and its error tells Claude to reach local servers with curl through Bash instead. And before any fetch, Claude Code sends the hostname, not the path, to api.anthropic.com for a safety check, as the Data usage page describes.
Blocking WebFetch does not block the internet
This is the part that is easy to get wrong. A deny rule on WebFetch stops one tool. Every shell command is another way out, and Anthropic's Configure permissions page says so directly.
Using WebFetch alone doesn't prevent network access.Claude Code docs, Configure permissions
The same page shows why a rule on the command text is a weak fix. A rule meant to limit curl to GitHub misses the same request written with an option first, another protocol, a redirect or a shell variable. A deny rule on curl also misses /usr/bin/curl and sh -c 'curl ...', and says nothing about wget, Python or Node.
Anthropic's suggestion is to deny the network tools in Bash, allow only the domains you want through WebFetch, and pair that with the sandbox when the restriction must hold:
{
"permissions": {
"allow": ["WebFetch(domain:docs.python.org)"],
"deny": ["Bash(curl *)", "Bash(wget *)"]
}
}
On its own, that is a speed bump. It catches the obvious command and nothing else.
The Bash sandbox: a host list the operating system holds
The built-in sandbox is off by default and turned on with /sandbox or sandbox.enabled. With it on, a shell command has no direct route to the network. On Linux and WSL 2 it runs in a separate network namespace; on macOS, Seatbelt blocks every connection except the one to a local proxy. That proxy checks each hostname against your allowed domains, and the list starts empty.
{
"sandbox": {
"enabled": true,
"allowUnsandboxedCommands": false,
"network": {
"allowedDomains": ["registry.npmjs.org", "pypi.org", "files.pythonhosted.org"]
}
}
}
What happens to a host outside the list depends on the mode: Manual asks you, auto mode refuses unless the classifier approved a host the command named, dontAsk refuses, and bypass mode allows it without a prompt. Setting strictAllowlist in your user or managed settings refuses it in every mode.
Two settings decide whether the boundary is real. When a command fails in the sandbox, Claude can ask to retry it unsandboxed; allowUnsandboxedCommands: false turns that retry off. And the sandbox wraps shell commands only. The page is plain that allowedDomains does not limit WebFetch, so the permission rules above still matter.
Know the proxy's limit as well. It decides from the hostname the client sends and does not inspect encrypted traffic by default, so the page warns that a broad entry such as github.com "can create paths for data exfiltration."
An allowed host can still carry data out
A host list answers where the agent can connect. It does not answer what it can say once connected. Even a plain download can carry data in the address it asks for.
Anthropic's advisory GHSA-fg94-h982-f3mm, published in June 2026, is a clean example. huggingface.co was on WebFetch's preapproved list as a bare hostname, so any path on it fetched without a prompt, including files in a repository an attacker controls. The site counts those fetches as downloads, which gave injected instructions a channel to encode files, environment variables or command output. Version 2.1.163 fixed it.
"Read-only access to a site is safe."
Revision 1: a read can carry data in its address, so every allowed host is a possible way out.This is the third part of the lethal trifecta: private data, untrusted text, and a way to send. Keep the list to hosts the task needs, and prefer hosts that do not count, store or echo what you request. Our list of AI agent security risks starts from the same wrong host.
In the cloud and in containers
Claude Code on the web runs each session in a virtual machine managed by Anthropic. Its cloud environments page offers three network levels: None, Limited (package registries, GitHub and cloud SDKs, plus domains you list) and Full. Whichever you pick, GitHub through its own proxy, the MCP connectors you enable and the Anthropic API stay reachable. Anthropic's page on Claude Code in the cloud notes that the API connection "may allow data to exit the VM."
On your own machine, Anthropic's page on sandbox environments covers the options that wrap the whole process, so built-in tools, hooks and MCP servers sit behind the same limit. Its example dev container ships a default-deny firewall with an allowlist. The page's own warning applies to all of them: any approach that allows egress can still leak data the agent can read.
None of these change what the model receives. The files Claude reads still go to the provider in its requests, as our notes on whether Claude Code is private explain.
What to set for what you want
No internet beyond the model. Deny WebFetch and WebSearch, and turn on the Bash sandbox with an empty host list, strictAllowlist and the unsandboxed retry off. Hooks and MCP servers still sit outside it, so for a hard limit run the whole process in a container whose firewall allows only the model endpoint.
Package installs, nothing else. The sandbox with your registries in allowedDomains, WebFetch rules for the docs you read, and strictAllowlist so a new host is refused instead of asked about.
The open web, with a person deciding. Manual mode, and read the host in each prompt before you say yes. "Don't ask again" is a permanent rule; save it for hosts you would put in the file by hand.
Whatever you pick, the same rule holds that we keep in agentic AI security: the agent reaches only the hosts the task needs, and a person approves the next one.
A side note on how we do it
We build Fenzi, which starts Claude Code in an OpenShell sandbox where every connection the agent and its programs make goes through one policy: a short list of hosts, read-only by default, plus the model endpoint, as the default access sheet lists. A host not in the policy looks like a failed DNS lookup or a refused connection, the log says why, and a person approves a new one. A container with a default-deny firewall answers the question in much the same way.
So, can Claude Code access the internet?
Yes, through web fetch, web search, every shell command and every process it starts, and in the default mode it asks first. A deny rule on one tool does not close the others; a host list enforced below the agent does, and even then each allowed host is a way out. Decide which hosts the task needs, then enforce that list where the agent cannot edit it. Anthropic's sandboxed Bash tool page is the place to start.