Some Bits: Nelson's log

Claude Code, Nix, ssh, and Linux

Claude Code figured out it could use my Desktop ssh agent and did some surprising things on remote systems. Thankfully it only did good things but it was alarming. In short: the problem was I’d set allowAllUnixSockets: true to make Nix work. That enabled ssh access and Claude was smart enough to discover it. Details and a fix below.

ssh agents

ssh agents work by having a daemon listening on a Unix socket. Mine is in /run/user/1000/ssh-agent.socket and $SSH_AUTH_SOCK points to it. Claude is ambitious enough to find and use this agent to access other machines if it helps get a job done. The default sandbox denies access to Unix sockets though, so it’s usually prevented. But...

Nix

Nix’s default install has some elaborate daemon setup to do Nix operations like building new artifacts. The client tools talk to it via a Unix domain socket /nix/var/nix/daemon-socket/socket. That wasn’t working for Claude Code because the default sandbox disallows access to all Unix sockets. (Many are sensitive!) So the devil suggested I augment the sandbox with the policy allowAllUnixSockets: true. And then Nix worked! Only now Claude had access to all sockets. Including ssh-agent.

The fix on MacOS

I can’t test this, but the very sensible fix on MacOS is instead of giving access all Unix sockets, just set "allowUnixSockets": ["/nix/var/nix/daemon-socket/socket"].

Unfortunately this doesn’t work on Linux right now (Sep 2026), some limitation of the sandboxing system. The directive is a no-op on Linux so no access is allowed (and no warning). Your only easy option is to enable all sockets.

The fix on Linux

I’m not certain, but the best I can do on Linux is enable access to all sockets, then disable one by one “dangerous” sockets that Claude might try to use. Claude suggested this configuration based on what it found on my system today:

  "sandbox": {
    "credentials": {
      "envVars": [
        { "name": "SSH_AUTH_SOCK", "mode": "deny" },
        { "name": "SSH_AGENT_PID", "mode": "deny" }
      ],
      "files": [
        { "path": "~/.ssh", "mode": "deny" },
        { "path": "~/.aws/credentials", "mode": "deny" },
        { "path": "/run/user/1000/ssh-agent.socket", "mode": "deny" },
        { "path": "/run/user/1000/gnupg", "mode": "deny" },
        { "path": "/run/user/1000/op-daemon.sock", "mode": "deny" },
        { "path": "/run/user/1000/1Password-BrowserSupport.sock", "mode": "deny" },
        { "path": "/run/user/1000/kwallet5.socket", "mode": "deny" },
        { "path": "/run/user/1000/bus", "mode": "deny" }
      ]
    }
  }

Of course blacklisting some sockets is terrible security, no doubt next week (or next ssh session) some new socket I haven’t blacklisted will be created. Docker is a good example: its sockets are very powerful and I haven’t thought to block it here. (Might not want to, having Claude drive Docker is useful!)

Basically the Linux sandbox isn’t strong enough to protect against a real adversary. But Claude isn’t an adversary. It’s an enthusiastic and very curious puppy. I think it provides helpful protection to put puppy gates across the doors you don’t want it to go through.

The problem is Claude is also the devil. A very persistent one. If you ask it to try hard to get something done it will. It’d be much better to have a more solid sandbox stopping it. Hopefully they fix this limitation about only allowing certain Unix sockets soon. There’s various bug reports about it but I haven’t researched them.

I wonder if there’s some other way to let Nix do its thing without a Unix domain socket, or with some proxy script that Claude is allowed to use.