Skip to content

Fix Codex CLI “Network Access Restricted” in 2 Commands (2026)

For / Key Points

For: People whose npm, curl, or API calls are denied only inside Codex

Key Points:

  • Keep the workspace-write filesystem boundary
  • Enable outbound connections with network_access=true
  • Test a one-run override before changing persistent configuration

If network access is the only requirement, start with this minimum configuration:

codex -s workspace-write \
  -c 'sandbox_workspace_write.network_access=true'

For a non-interactive run:

codex exec -a never -s workspace-write \
  -c 'sandbox_workspace_write.network_access=true' \
  "Run npm install, then run the tests"

Identify the error before changing settings

Several unrelated failures look like “Codex has no internet.” Use the exact message to choose the right branch.

Error textWhere to troubleshoot
Network access is restricted or a sandbox denialThe network_access setting in this guide
missing field sandboxPolicyBrowser / Computer Use and node_repl compatibility; this setting will not fix it
Reconnecting... or WebSocket timeoutReconnecting troubleshooting
Could not resolve hostDNS, VPN, proxy, or host networking
HTTP 401 or 403API authentication or destination authorization

If the exact error is missing field sandboxPolicy, go to the node_repl sandboxPolicy fix guide. Disabling the sandbox does not resolve that error because the MCP metadata check fails before JavaScript starts.

Enable network access for one run

Test with a CLI override before changing persistent configuration:

codex -a on-request -s workspace-write \
  -c 'sandbox_workspace_write.network_access=true'

Each option controls a different boundary:

  • -a on-request: ask for approval when needed
  • -s workspace-write: restrict writes to the workspace
  • network_access=true: allow outbound connections inside that sandbox

Network access does not require removing the file sandbox. Try this minimum permission set before considering danger-full-access.13

Save the setting in config.toml

Persist the setting only if most sessions need it. The file is $CODEX_HOME/config.toml, normally ~/.codex/config.toml when CODEX_HOME is not set.

sandbox_mode = "workspace-write"

[sandbox_workspace_write]
network_access = true

For an unattended workflow that must not ask for approval, add the policy deliberately:

approval_policy = "never"
sandbox_mode = "workspace-write"

[sandbox_workspace_write]
network_access = true

CLI arguments take precedence over config.toml. If the result differs from the file, inspect shell aliases, wrapper scripts, and IDE launch arguments.

Limit outbound destinations by domain

After enabling network access, you can also use network proxy domain rules to narrow the allowed destinations.2

[features.network_proxy]
enabled = true
domains = {
  "registry.npmjs.org" = "allow",
  "api.github.com" = "allow"
}

This block does not enable networking by itself; sandbox_workspace_write.network_access = true is still required. Unlisted domains are denied, and a deny rule wins when allow and deny rules overlap.

If curl or npm still fails

Enabling network access does not repair DNS, VPN, proxy, certificate, or destination authentication failures. Check them in this order.

1. Inspect the active installation and configuration

codex --version
codex doctor --summary
codex --help

codex doctor --json can help with an issue report, but review the output before sharing it. Redact local paths, project names, and any other details that do not belong in a public issue.

2. Test the host connection

curl -I https://api.openai.com

If the command fails outside Codex, fix the host environment first. Corporate VPNs, DNS, TLS inspection, and authenticated proxies are common causes.

3. Inspect proxy environment variables

env | rg '^(HTTP|HTTPS|ALL|NO)_PROXY='

Never paste proxy credentials into an article, issue, or screenshot. Remove usernames and passwords embedded in proxy URLs.

4. Check destination authentication

HTTP 401 normally means the request reached the service but authentication failed. 403 often indicates authorization or policy denial. Repeating the sandbox setting will not fix either one.

Keep the network boundary safe

Network access lets the agent fetch packages, call APIs, and transmit data. Decide the boundary before running the task.

  • Use lockfiles and review dependency changes
  • Keep .env files and cloud credentials out of the working directory
  • Use scoped development credentials instead of production credentials
  • Use disposable runners and least-privilege tokens in CI
  • Remove persistent network_access=true when it is no longer needed

FAQ

Does -a never enable network access?

Not by itself. Approval policy and network access are separate. Add sandbox_workspace_write.network_access=true when using the workspace sandbox.

Should I switch to danger-full-access?

Not just for networking. It removes file protections too. Keep workspace-write and enable only network access first.

Will this fix missing field sandboxPolicy?

No. That error has been reported as a metadata compatibility problem between Codex and the bundled node_repl used by Browser / Computer Use. Use the dedicated guide.

Summary

  • Combine workspace-write with network_access=true for a one-run test
  • If curl also fails outside Codex, fix host DNS, VPN, or proxy first
  • Do not remove file protections with danger-full-access just to enable networking