Stop your SSH agent from following your coding agentForwardAgent, sbx and a deploy-key agent
A forwarded SSH agent lets anything running as you on the far side sign with every key you have loaded. Turn forwarding off by default, then forward a separate agent that holds one repo-scoped key, constrained or gated by a touch, to the hosts where an agent has to push.
-
01
Source
Laptop agent
Every key you ssh-add, unlocked
SSH_AUTH_SOCK on the laptop -
02
Channel
Forwarded socket
ForwardAgent, sbx, dev containers
/tmp/ssh-*/agent.* -
03
Exposure
Agent signs as you
Push, clone, hop to the next host
No key copied, no prompt
TL;DR· the answer, in twenty seconds
What happened: On November 9 a Hacker News post claimed the ChatGPT desktop app forwards your SSH agent to remote machines, so an agent there can push to your private repos. The linked Codex pull request was an opt-in change that never merged, but the exposure is real wherever your SSH config, Docker Sandboxes or a dev container forwards the agent, and in sbx it is on by default.
The minimum fix: Put ForwardAgent no under Host *, run sbx settings set ssh.agentForwardingEnabled false, and for hosts where an agent must push, forward a second agent that holds one deploy key, constrained with ssh-add -h or stored on a FIDO key.
The lesson: An agent socket is a signing service for every key in it. Decide which keys the far side gets, the same way you decide which tokens go into its environment.
A forwarded SSH agent lets any process on the remote machine that can reach the socket sign with every key you loaded on your laptop, and a coding agent on that machine is such a process.
On November 9 a post titled "ChatGPT Desktop forwards your SSH agent to remote machines" reached the Hacker News front page and drew 222 points. The poster, DenGorbachev, wrote that "the agent running on a remote machine can authenticate using your local SSH credentials," which means it "can push to your private repos on GitHub." The evidence was a review comment on a Codex pull request. Several commenters pointed out that the pull request was closed without merging, and one asked whether there was any other evidence of Codex extending an SSH agent on its own.
I read the pull request and the issue it fixes, because the headline and the thread disagree, and both matter for what you do next. The rest of this guide covers where forwarding happens in coding agent setups today, how to find out whether yours does, and how to give a remote agent push access without handing it every key you own.
I checked every command against the OpenSSH 10.5p1 man pages and ran the ssh -G and ssh-add steps on that version. I did not run the Codex app's remote mode or install Docker Sandboxes for this guide. Where a claim rests on vendor docs, I link the docs.
What the Codex pull request does and what the thread missed
The pull request is openai/codex#28131, opened June 13 and closed unmerged on June 29. It proposed an opt-in codex app-server proxy --forward-ssh-agent mode. A long-running app server on a remote host keeps the SSH_AUTH_SOCK path from the SSH session that started it, and once that session ends the path points at a deleted socket. The patch would refresh a stable symlink, forwarded-ssh-agent.sock, so the app server follows whichever SSH connection is current. The review comment the HN post linked shows the launch line: SSH_AUTH_SOCK=~/.codex/app-server-control/forwarded-ssh-agent.sock nohup codex app-server.
The issue it fixes, openai/codex#22567, runs the other way from the headline. A user had ForwardAgent yes for a host in ~/.ssh/config, and the Codex app's Remote SSH projects did not get a working agent, which broke docker buildx build --ssh default. The complaint was that forwarding did not work. Its status changed to closed as completed on July 30.
So the HN headline overstated what OpenAI shipped. The Codex app does not decide to forward your agent. OpenAI's remote connections page says the app reads concrete host aliases from ~/.ssh/config and connects through OpenSSH, and its example host block has no ForwardAgent line. If your config forwards the agent to that host, the remote app server and the agent it runs get your agent. If it does not, they do not.
That is the part the thread got right. The users who filed #22567 wanted forwarding on, because private Git over SSH from a remote box is the common case, and one of them posted a prompt that told Codex what to do when a push failed: check whether $SSH_AUTH_SOCK is a live socket, and if not, find the newest codex app-server proxy process and read its SSH_AUTH_SOCK from /proc/<pid>/environ. That prompt is a good workaround for a stale socket. It also shows that an agent told to find a working agent socket on the box will do it, and nothing about the socket stops it.
What a forwarded agent hands the far side
The ssh_config man page states the risk in the ForwardAgent entry. Users who can bypass file permissions on the remote host for the agent's socket "can access the local agent through the forwarded connection." It goes on: "An attacker cannot obtain key material from the agent, however they can perform operations on the keys that enable them to authenticate using the identities loaded into the agent."
That second sentence is the threat model for a coding agent. The agent does not need to bypass file permissions. It runs as your remote user, the socket belongs to your remote user, and SSH_AUTH_SOCK is in its environment. It can ask the socket to sign, and the socket signs for any key on your laptop's agent. On a typical developer laptop that includes the key GitHub knows as you, which can push to every repository you can push to, and often keys for production hosts.
Four properties make this worse than an API key in the environment:
- The agent holds every key you have loaded, not one credential for one service.
ssh-add -lon the remote box lists them. - Signing leaves no trace on your laptop by default. The stock OpenSSH agent does not prompt or log a signature request.
- The socket works for onward hops. An agent on the dev box can
sshto a third host with your identity, and if that hop also forwards, the chain continues. - It lasts as long as the connection. A detached app server or a tmux session that kept the socket path can use it until you disconnect.
Docker Sandboxes shows the same pattern without a remote host. Rupert Rutledge wrote on July 30 that he ran a Pi agent in sbx with its own GitHub identity, and it cloned a private repository that identity had no access to. Inside the sandbox, ssh -T git@github.com authenticated as his own account, because sbx had forwarded his host agent into the microVM. Docker's credentials page says "SSH agent forwarding is enabled by default" and that processes in the sandbox "can request signatures from the forwarded agent, but they can't read or copy a private key." Both statements are true. The second makes the same point as the OpenSSH man page, and it was never the reassurance it sounds like.
VS Code points the same way. The Dev Containers credential page says the extension "will automatically forward your local SSH agent if one is running." The Remote-SSH troubleshooting page tells you to add ForwardAgent yes under Host * so Git on the remote can use your keys. Follow that advice once and every host you SSH to gets your agent, including the ones you never meant to run an agent on.
Find out where your agent is forwarded today
Start on the laptop. ssh -G prints the configuration OpenSSH will use for a host after it applies every Include, Match and Host * block, so it catches the forwarding line you added two years ago and forgot. This loop checks every concrete alias in your config:
# Every concrete Host alias in ~/.ssh/config (skips patterns like *)
awk 'tolower($1)=="host" {for (i=2;i<=NF;i++) if ($i !~ /[*?!]/) print $i}' \
~/.ssh/config | sort -u | while read -r h; do
printf '%-30s %s\n' "$h" "$(ssh -G "$h" 2>/dev/null | awk '$1=="forwardagent"{print $2}')"
done
# Which keys a forwarded socket would expose right now
ssh-add -l
Any alias that prints yes or a socket path forwards an agent. ssh -G resolves includes, but this loop only lists aliases written in ~/.ssh/config itself, so also grep the files it includes. Then look at the second command's output, because that list is what the far side can sign with.
Then check from the other side. Connect to the dev box the way your agent's tool connects, and run:
echo "$SSH_AUTH_SOCK"
ssh-add -l
ls -l /tmp/ssh-*/ 2>/dev/null
If ssh-add -l lists your laptop keys, so can the agent. The /tmp/ssh-* directories are where OpenSSH's server places forwarded sockets on most Linux systems. A leftover directory from a session you think you closed is worth a second look; on a shared box, root and anyone who can act as your user can use a live one.
For Docker Sandboxes, run the same ssh-add -l inside a sandbox with sbx exec <name> ssh-add -l. For a dev container, open a terminal in the container and run it there. If either lists keys, forwarding is on.
Turn forwarding off by default and on for one host
OpenSSH uses the first value it finds for each option, so the order of blocks matters. Put specific hosts first and the catch-all last:
# ~/.ssh/config
# A bastion you only pass through: jump, never forward
Host prod-db
HostName 10.20.0.15
ProxyJump bastion.example.com
# The dev box where an agent pushes: forward a one-key agent (next section)
Host devbox
HostName devbox.example.com
User you
ForwardAgent ~/.ssh/agent-devbox.sock
# Everything else
Host *
ForwardAgent no
ForwardAgent no is already the OpenSSH default. Writing it under Host * at the end still earns its line, because it documents intent and you will notice it when a tool's setup guide tells you to add ForwardAgent yes under the same pattern. If you added that line for VS Code, delete it and forward to the specific hosts that need it.
ProxyJump replaces the most common reason people forward. If you forward to a bastion so you can ssh onward from it, the bastion can use your agent. ProxyJump opens a TCP tunnel through the bastion and runs authentication from your laptop, so the bastion never sees the socket. One HN commenter, minitech, called it the safer default, and it is.
For Docker Sandboxes, version 0.42.0 added the off switch after docker/sbx-releases#305 asked for one. The settings reference lists ssh.agentForwardingEnabled with a default of true:
sbx settings set ssh.agentForwardingEnabled false
sbx daemon restart
The restart applies the change to forwarders that already exist. Before 0.42.0, the workaround from that issue was to stop the daemon, unset the agent variable and start sbx again, and a commenter found the container still tried to reach a host agent. Upgrade instead of relying on it.
For dev containers, the docs describe forwarding as automatic when an agent is running, and the page I read does not document an off switch. The lever you control is which agent VS Code can see. Point SSH_AUTH_SOCK at a one-key agent in the environment that launches VS Code, or keep the container's Git remote on HTTPS with a token scoped to that repository.
Give the remote agent one key, not your keyring
Turning forwarding off breaks the thing people wanted in #22567: an agent on the dev box that can git push to a private repo. The fix is to stop forwarding your keyring and forward a second agent that holds one key for one job. ForwardAgent accepts a socket path for this reason, and I confirmed with ssh -G on OpenSSH 10.5p1 that a ~/ path expands to your home directory.
Create a deploy key for the repository and a separate agent to hold it:
# 1. A key for one repo. Add the .pub as a deploy key with write access
# on that repository only, not to your GitHub account.
ssh-keygen -t ed25519 -f ~/.ssh/id_devbox_billing -C "devbox billing-api deploy"
# 2. A second agent on a fixed socket
ssh-agent -a ~/.ssh/agent-devbox.sock
# 3. Load only that key, constrained to GitHub via devbox
SSH_AUTH_SOCK=~/.ssh/agent-devbox.sock \
ssh-add -h devbox.example.com \
-h "devbox.example.com>git@github.com" \
~/.ssh/id_devbox_billing
The Host devbox block from the previous section forwards this socket instead of your main agent. The agent on the dev box now sees one key, and GitHub will accept that key for one repository. A deploy key also gives you a clean revocation: delete it from the repository settings and nothing else you own changes.
The -h flags are destination constraints, added in OpenSSH 8.9. The ssh-add man page explains the two forms. A bare [user@]host lets the key be used from your laptop to that host. A src>dst form lets it be used through a forwarded agent from the first host to the second. Keys you add without -h "are not destination constrained," which is how most people's agents run today. The man page also states the limit: the agent enforces constraints only when a cooperating ssh uses or forwards the key, and they do not stop someone with access to a remote SSH_AUTH_SOCK from forwarding it again. Both ends need OpenSSH 8.9 or later, and the agent checks host keys against your known_hosts, so connect to each host once before you rely on a constraint.
If you want a human in the loop for each use, ssh-add has two options and neither is free:
ssh-add -cmakes the agent ask for confirmation before each use, throughssh-askpass. macOS does not ship an askpass program, so on a Mac you need to install one, or the agent has no way to ask and the request fails.- A FIDO key, made with
ssh-keygen -t ed25519-sk, needs a touch for each signature by default. Add-O verify-requiredand it also needs a PIN, if your authenticator supports it. The ssh-keygen man page notes that not every authenticator does.
Both have the problem alsdkgjhgd raised in the thread: the blinking key or the dialog does not tell you what you are approving. If a tool forwarded your agent and something on the far side asks for a signature while you are not pushing, you get a prompt with no context. Treat an unexpected prompt as a finding, not an inconvenience, and deny it. On a Mac, Secretive stores keys in the Secure Enclave, can require Touch ID per key, and "notifies you whenever your keys are accessed." A notification you can see beats a signature you cannot.
None of this needs to apply to your main agent, which can stay as it is for your own terminal. The separation is the point: the keyring you use by hand stays on the laptop, and the far side gets one key you can revoke in a minute.
What this means for your stack
Run the ssh -G loop above and fix every alias that forwards an agent without a reason. Add ForwardAgent no under Host *, switch bastions to ProxyJump, and set ssh.agentForwardingEnabled false in Docker Sandboxes. If an agent on a remote box or in a sandbox needs to push, give it a deploy key in its own agent, forwarded to that one host. Then check what is loaded in your main agent with ssh-add -l, and remove keys you do not use every day.
The pattern under all of it is the one that applies to API keys: a credential the agent can use should be scoped to the job, live no longer than the job, and leave a record you can read later. SSH gives you scope through deploy keys and destination constraints, and presence through FIDO touches. It gives you little in the way of an audit trail unless you add a tool like Secretive or read the server's logs.
hasp does not broker SSH signatures; it handles the other half of the problem, the API keys and tokens a remote agent would otherwise read from its environment. On the box where the agent runs, hasp run --project-root . --env GITHUB_TOKEN=@GITHUB_TOKEN --grant-secret window --grant-window 15m -- gh pr create hands the token to the one child process that needs it, for a 15-minute window. Source-available (FCL-1.0), local-first, macOS and Linux, no account.
Whatever you use for tokens, treat the agent socket as a credential in its own right. It does not show up when you grep the environment for KEY or TOKEN, and that is why people forget it.
Sources· cited above, in one place
- Hacker News ChatGPT Desktop forwards your SSH agent to remote machines
- openai/codex PR #28131: refresh SSH agent for app-server proxy (closed, not merged)
- openai/codex Issue #22567: Codex App Remote SSH does not honor ForwardAgent
- OpenAI Remote connections: SSH hosts for Codex in the ChatGPT desktop app
- Rupert Rutledge The SSH Security Hole in Docker Sandboxes
- docker/sbx-releases Issue #305: provide an option to disable SSH agent forwarding
- Docker Docs Docker Sandboxes: Settings reference (ssh.agentForwardingEnabled)
- Docker Docs Docker Sandboxes: Manage credentials
- VS Code Docs Sharing Git credentials with your container
- VS Code Docs Remote development tips and tricks: local SSH agent on the remote
- OpenBSD manual pages ssh_config(5): ForwardAgent and ProxyJump
- OpenBSD manual pages ssh-add(1): confirmation and destination constraints
- OpenBSD manual pages ssh-keygen(1): FIDO key options such as verify-required
- maxgoedjen/secretive Secretive: SSH keys in the Mac Secure Enclave
Stop handing the agent your real keys.
hasp keeps secrets in one local encrypted vault, brokers them into the child process at exec, and never lets the agent read the value.
- Local, encrypted vault — no account, no cloud, no telemetry by default.
- Brokered run — agent gets a reference, the child process gets the value.
- Pre-commit + pre-push hooks catch managed values before they ship.
- Append-only HMAC audit log answers "did the agent touch the prod token?" in seconds.
macOS & Linux. Source-available (FCL-1.0, converts to Apache 2.0). No account.