Sandbox: allow outbound connections to localhost

Status Open
Maintainer reply None cached
Activity 8 comments · opened Feb 24, 2026

Problem

The sandbox blocks outbound TCP connections to localhost/127.0.0.1/::1 even when these are listed in sandbox.network.allowedDomains. The sock.connect() syscall gets EPERM (Operation not permitted).

This makes it impossible to run integration tests against local Docker services (e.g. http://localhost:8000) from within the sandbox.

What I've tried

In settings.json:

"sandbox": {
  "enabled": true,
  "network": {
    "allowLocalBinding": true,
    "allowedDomains": [
      "localhost",
      "127.0.0.1",
      "::1"
    ]
  }
}

None of these settings allow the outbound connection. The only workaround is either dangerouslyDisableSandbox: true on every bash call, or adding the command to excludedCommands, both of which defeat the purpose of the sandbox.

Requested feature

A sandbox setting that allows outbound TCP connections to loopback addresses, e.g.:

"sandbox": {
  "network": {
    "allowLocalhostConnections": true
  }
}

Or have allowedDomains with localhost/127.0.0.1/::1 actually allow the TCP connection, not just DNS resolution.

Use case

Running integration tests against services in local Docker containers. For example, starting a service via docker compose and then running integration tests that hit http://localhost:8000.

View original on GitHub ↗

6 Comments

akda5id · 5 months ago

I'm hitting this as well, would really like to be able to hit local servers with claude code, and stay inside the sandbox.

GautierBlandin · 5 months ago

Same problem here

lgruen-vcgs · 5 months ago

On MacOS, there's network.allowLocalBinding: https://code.claude.com/docs/en/settings#sandbox-settings

Would be nice to have fine-grained per port restrictions though.

zupd · 3 months ago

Cannot believe this hasn't been fixed yet. It's impossible to do local development if required to test things on the local webapp, etc.

Matt3o12 · 1 month ago

The problem is that claude is running inside an isolated network namespace, so claude's localhost and the real localhost are different. Claude has a proxy to access resources outside of it's network namespace (that's how allowedDomains works). Unfortunately, you almost never want proxy requests to localhost, except in this case.

So the easiest fix to start all commands with no_proxy="" (for example: NO_PROXY="" no_proxy="" ./run-tests.sh or curl --no-proxy "" localhost:1234 also works). Unfortunately, I am not sure what the proper way to fix this is. settings the following claude config:

"env": {
    "no_proxy": "",
    "NO_PROXY": ""
  },

Also doesn't seem to work because this setting gets either ignored or overwritten once it reaches the sandbox. Even claude itself has a hard time understanding the problem. I've just updated my skills to use curl --no-proxy "" if it's running inside of a sandbox and wants to access localhost).

collimarco · 1 month ago

This issue also blocks bin/rails test connections to PostgreSQL (which is listening on localhost).

Basically this sandbox is completely useless without a way to connect to local services / ports.

Ideally, it would be useful to allow sandbox connections to localhost only on specific ports.

Showing cached comments. Read the full discussion on GitHub ↗