---
title: ssh-agent and git push
description: Agents push over ssh with your host's keys, which never enter the container.
order: 4
icon: key-round
tags: [git, ssh, agents]
related: [parallel-agents, babysit-pr, caches]
---
import AgentPrompt from '../../components/AgentPrompt.astro';
import AgentPromptLink from '../../components/AgentPromptLink.astro';
## The problem
An agent has to push its branch, but a private key copied into the container is handed to everything that runs there. devsandbox relays your host's ssh-agent instead, so the key never leaves the host.
<AgentPromptLink />
## Config
Nothing to enable. Add GitHub's host key and your git identity:
```toml title="devsandboxes.toml"
[sandbox.app]
folder = "../app"
image = "node:22"
[sandbox.app.postCreateCommand]
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"
```
## Try it
```bash
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
devsandbox exec fix-login git push
```
## How it works
- Every `devsandbox exec`, dashboard terminal and lifecycle command gets `SSH_AUTH_SOCK` relayed to your host's agent. A plain `docker exec` doesn't.
- The remote must be an ssh URL (`git@github.com:…`).
- On a [machine](/docs/machines), the agent is relayed only once you turn it on.
## Agent instructions
<AgentPrompt
goal="Make `git push` over ssh work from my devsandbox sandbox <sandbox name>, using my host's ssh-agent; no keys in the container."
steps={[
'Check `ssh-add -l` on the host lists a key. Add no keys or socket mounts.',
'In `[sandbox.<sandbox name>]`, add a `postCreateCommand` table that runs `ssh-keyscan github.com` into ~/.ssh/known_hosts and sets git `user.name` / `user.email` to <your name> / <your email>.',
'Check the repo remote is an ssh URL (git@github.com:…); ask me before changing it.',
]}
verify={[
'Start an instance with `devsandbox -C <config dir> run <sandbox name> --name <task>` and check `devsandbox -C <config dir> exec <task> ssh-add -l` lists my key. Push only when I ask.',
]}
/>