[BUG] Sandbox Error: Failed to create bridge sockets when TMPDIR is non-existent or non-writable

Resolved 💬 4 comments Opened Nov 5, 2025 by Moredread Closed Jan 14, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

Claude Code crashes with ❌ Sandbox Error: [SandboxManager] Failed to create bridge sockets after 5 attempts when TMPDIR points to a non-existent or non-writable directory.

Triggering conditions:

  • TMPDIR is non-writable: Always fails
  • TMPDIR is non-existent: Fails unless node is in PATH (compile cache creates it as side effect)

This occurs when the sandbox initializes, which happens either:

  • At startup if sandboxing is already enabled, or
  • During a session when running the /sandbox command to enable sandboxing

What Should Happen?

Claude Code should either:

  1. Create the TMPDIR if it doesn't exist, or
  2. Fail with a clear error message: "TMPDIR not writable: /path/to/dir"

Error Messages/Logs

❌ Sandbox Error: [SandboxManager] Failed to create bridge sockets after 5 attempts

[repeated multiple times]

Steps to Reproduce

Easiest reproduction (always fails):

  1. Create a read-only directory:

``bash
mkdir /tmp/readonly && chmod -w /tmp/readonly
``

  1. Run: TMPDIR=/tmp/readonly claude
  2. Error occurs (either at startup if sandbox enabled, or when running /sandbox)

Alternative scenario (behavior depends on environment):

  1. Set TMPDIR to a non-existent directory:

``bash
TMPDIR=/tmp/doesntexist claude
``

  1. Outcome depends on whether node is in PATH:
  • Node in PATH: Works (compile cache creates directory first)
  • Node not in PATH (e.g., hardcoded in Nix packages): Crashes with bridge socket error

Claude Model

Not sure / Multiple models

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

2.0.33

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

Other

Additional Information

Why this particularly affects Nix packaging:
When Claude Code is packaged with Nix, the node executable is hardcoded via patchShebangs but not in PATH. Node.js v22's compile cache normally creates TMPDIR as a side effect, but this doesn't happen when node isn't in PATH. This makes the bug more visible in Nix environments.

Root cause analysis:
The sandbox initialization attempts to create Unix sockets in TMPDIR without first validating that TMPDIR exists and is writable. When socat fails (with errors sent to /dev/null), the code retries 5 times before failing with the misleading "bridge sockets" error.

This bug report was created with assistance from Claude (Anthropic)

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗