EXAMPLE 05
  • git
  • ssh
  • agents

ssh-agent and git push

Agents push over ssh with your host's keys, which never enter the container.


The problem

An agent finishes its work on a branch and has to push it. Copying a private key into a throwaway container, or mounting ~/.ssh, hands the key to everything that runs there.

devsandbox forwards your host’s ssh-agent instead: ssh inside the sandbox asks it to sign, and the key never leaves the host. You only add GitHub’s host key and your git identity.

Let your agent set this up

Config

devsandboxes.toml
[sandbox.app]
folder = "../app"          # your repo, next to this config dir
image = "node:22"
# Your  login and settings, from the host.
mounts = ["source=${localEnv:HOME}/,target=/root/,type=bind"]
containerEnv = {  = "/root/" }

[sandbox.app.postCreateCommand]  # once, when an instance is created
git-identity = "git config --global user.name 'Your Name' && git config --global user.email you@example.com"
known-hosts = "mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts"  # trust github.com
agent = "npm install -g "
devsandboxes.toml
[sandbox.app]
folder = "../app"          # your repo, next to this config dir
image = "node:22"
# Your  login and settings, from the host.
mounts = ["source=${localEnv:HOME}/,target=/root/,type=bind"]

[sandbox.app.postCreateCommand]  # once, when an instance is created
git-identity = "git config --global user.name 'Your Name' && git config --global user.email you@example.com"
known-hosts = "mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts"  # trust github.com
agent = "npm install -g "

On macOS keeps its login in the Keychain: run /login once in any instance.

Try it

TERMINAL
ssh-add -l                                # on the host: your key is loaded
devsandbox run app --name fix-login
devsandbox exec fix-login ssh-add -l      # the same key, seen from inside

Start in it and have it commit and push its branch:

TERMINAL
devsandbox exec -it fix-login 
TERMINAL
devsandbox exec -it fix-login 

The remote must be an ssh URL (git@github.com:…); https:// remotes never use the ssh-agent.

How it works

  • No config: every devsandbox exec, dashboard terminal and lifecycle command gets SSH_AUTH_SOCK relayed to your host’s ssh-agent.
  • A plain docker exec shell gets no forwarding.
  • Works on Linux (docker, podman) and macOS (docker; Apple container untested). Native Windows: use WSL2.

Agent instructions

Prompt for your coding agentPaste into Claude Code, Codex or any agent with a shell.

Make git push over ssh work from my devsandbox sandbox <sandbox name>, using my host's ssh-agent; no keys in the container.

  1. Read the devsandbox-cli and config-toml-spec skills first (load them if they are installed, otherwise read them from https://github.com/Nemikolh/devsandboxes/tree/main/skills). Follow them over your own assumptions: unknown config keys are hard errors.
  2. Find my devsandbox config dir: the folder holding devsandboxes.toml, passed to devsandbox as -C <config dir>. If you cannot tell which one, ask me.
  3. Check the host: ssh-add -l lists a key, and devsandbox was installed from npm or a release archive (a cargo install build forwards only on Linux docker/podman).
  4. Add no keys or socket mounts. In [sandbox.<sandbox name>], add a postCreateCommand table that runs ssh-keyscan github.com into ~/.ssh/known_hosts, sets git user.name / user.email to <your name> / <your email>, and installs . Mount 's host config dir (its login) into the container.
  5. Check the repo remote is an ssh URL (git@github.com:…); ask me before changing it.
  6. Validate with devsandbox -C <config dir> ls and fix every error it reports before going on.
  7. Start an instance with devsandbox -C <config dir> run <sandbox name> --name <task>.
  8. Check devsandbox -C <config dir> exec <task> ssh-add -l lists my key and devsandbox -C <config dir> exec <task> --version works. Push only when I ask.
  9. Ask me before anything destructive: devsandbox rm, gc, rebuild --force, service rebuild, deleting files or branches.
fill in before sending Agent skills (opens in a new tab)

Source: site/src/content/examples/ssh-and-git-push.mdxEdit this page on GitHub(opens in a new tab)

MENU /
View on GitHub
EXAMPLES
All examplesEvery recipe on one page.Parallel coding agentsSeveral coding agents on one repo, fully isolated from one another.One shared PostgresOne development database for all your sandboxes and their instances.Private services per instanceEvery instance gets its own Postgres and Redis, so agents never touch each other's data.Shared package cachesNew sandboxes stop downloading the same packages again.ssh-agent and git pushAgents push over ssh with your host's keys, which never enter the container.Port forwarding on demandOpen a sandbox's dev server or database from your host, without restarting anything.Attach VS CodeOpen any instance in VS Code with one key.devcontainer FeaturesAdd Node, Rust or the GitHub CLI to any image, in TOML.Babysit pull requestsAn agent keeps your open PRs merged with their base, and pings you when it can't.Port a devcontainer.jsonTurn an existing devcontainer.json into a devsandbox config.