Once an AI coding agent runs inside a Docker Sandbox, the next question is practical: where does the Git checkout live, and how do the agent’s commits get back to you? The Docker docs now answer this in a dedicated guide, Use Git with sandboxes, which was reworked in late October 2026 to clarify checkout choices and parallel task workflows. This post walks through that guide with verified commands, explains the trade-offs between the four checkout options, and shows how the picture changes when you move from local sandboxes to Docker Cloud Sandboxes.
The short version: the workspace mode you pick decides who owns Git (you, the agent, or both), when changes become visible on your host, and how well parallel tasks stay isolated. Picking the wrong one is an easy way to end up with agent work tangled into your own edits.
Prerequisites
- The
sbxCLI installed and signed in. See the Docker Sandboxes install page for supported platforms (macOS, Windows and Linux) and setup steps. - An agent available to
sbx. The examples useclaude(Claude Code), the same agent the docs use. - Git installed on the host, and a local repository to work with.
- For commit signing: an SSH key loaded in your host SSH agent, with
SSH_AUTH_SOCKset. - For the cloud section: access to Docker Cloud Sandboxes and the
--cloudmode ofsbx.
All workspace modes in this post apply to local sandboxes unless stated otherwise. The cloud section covers what is different there.
Four ways to place your checkout
The guide frames the decision around two questions: when do changes show up in your host checkout, and can the agent run Git itself? Here is the comparison in plain terms:
- Direct mount: changes appear on the host immediately, and the agent can use Git.
- Mounted host worktree: changes appear immediately inside the worktree directory, but the agent cannot use Git.
- Clone mode (
--clone): changes reach the host only after you fetch and check out or merge a branch. The agent can use Git. - Mountless sandbox: changes reach the host only after you pull committed work from a Git remote. The agent can use Git.
The guide also makes an important point about parallel work: branches alone do not isolate edits in a shared working directory. If two tasks run in the same directory, they step on each other even if they sit on different branches. For simultaneous tasks, give each task its own worktree or clone inside the sandbox, or use separate sandboxes when the tasks also need independent tools and services.
Direct mode: share your working tree
Direct mode is the default. The sandbox mounts your host working tree, and the agent edits files in place. Both you and the agent can run Git against the same repository, so you need to agree on who handles branches and commits. If either side switches branches, the files change for both.
A typical host-driven flow looks like this. First create a branch on the host:
git checkout -b feat/my-feature
Then start the sandbox with no extra flags:
sbx run claude
While the agent works, you review and commit from the host as usual:
git diff
git add -p
git commit
git push -u origin feat/my-feature
Direct mode fits focused work on a single branch where you collaborate with the agent turn by turn.
Clone mode: a private checkout inside the sandbox
With --clone, sbx creates a separate Git clone inside the sandbox. The agent edits that clone, not your host working tree. Your host repository is still visible at /run/sandbox/source, but read only. The clone is not a linked worktree of your host checkout, so nothing the agent does touches your files until you fetch it.
The sbx run reference describes --clone as running the agent on a private in-container clone of the host Git repository, and notes that it must be set when the sandbox is created. You cannot switch an existing sandbox between clone mode and direct mode. To change modes, remove and recreate the sandbox, or create two sandboxes with different names if you want both modes against the same repository.
How the sandbox remote works
The CLI copies your host remotes such as origin and upstream into the in-sandbox clone. Local path remotes, such as file:// URLs, are skipped because the sandbox cannot reach them. On the host side, the CLI adds a remote named sandbox-<name> that points at a Git daemon running inside the sandbox. A few lifecycle rules follow from that:
sbx stopshuts down the daemon, sogit fetch sandbox-<name>fails until the sandbox runs again.- A restart assigns a new ephemeral port to the daemon, and the CLI updates the
sandbox-<name>remote URL in your host Git config for you. sbx rmremoves the sandbox, the daemon, the published port and thesandbox-<name>remote entry.
Single task
Start a clone-mode sandbox in the current repository:
sbx run --clone claude .
Ask the agent to create a branch, for example feat/my-feature, before it edits anything. When it is done, fetch and review the branch from the host:
git fetch sandbox-<name>
git log sandbox-<name>/feat/my-feature
git diff main..sandbox-<name>/feat/my-feature
To bring the work home, check out the fetched branch locally and push it, or ask the agent to push to your remote directly:
git checkout -b feat/my-feature sandbox-<name>/feat/my-feature
git push -u origin feat/my-feature
gh pr create
Parallel tasks
A single clone-mode sandbox can hold several branches and worktrees. The --clone flag creates the clone, but it does not separate one task from another. That part is up to the agent tool. Start the sandbox the same way, open the agents view in Claude Code, and dispatch each task to its own background session. To make isolation explicit, the guide suggests a project instruction along these lines:
For each simultaneous task, create a separate Git worktree with its own branch
and make all changes for that task in that worktree.
When the agents finish, fetch everything and inspect each branch:
git fetch sandbox-<name>
git log sandbox-<name>/feat/task-a
git log sandbox-<name>/feat/task-b
Then check out the branches you want to keep and open pull requests as normal.
Host worktree: visible edits, no agent Git
You can also create a Git worktree on the host and point the sandbox at it. The agent edits files in that directory and you see the changes right away. The catch is that the sandbox mounts only the worktree directory, not the parent repository. A worktree’s .git entry is a pointer file to the parent, which the sandbox cannot resolve, so the agent cannot commit, branch or even check status. You handle all Git operations yourself.
git worktree add -b feat/my-feature ../my-feature-work
sbx run claude ../my-feature-work
When the agent is done, commit and push from the host:
cd ../my-feature-work
git diff
git add -p && git commit
git push -u origin feat/my-feature
gh pr create
Use this when you want each task in its own host directory and prefer to keep Git in your own hands. If the agent needs Git in each working directory, use worktrees inside a clone-mode or mountless sandbox instead.
Mountless sandbox: let the agent own the checkout
A mountless sandbox has no host workspace at all. The agent clones repositories inside the sandbox, installs its tools there, and creates worktrees as needed. Files persist across stops and restarts, but removing the sandbox deletes them, so push anything you want to keep first. The guide recommends this option as you hand the agent more responsibility, because it can manage branches and push results for review without coordinating with your host checkout.
sbx create --name my-project claude
sbx run --name my-project
Note the subtle difference: leaving the path off sbx create produces a mountless sandbox, but leaving it off sbx run claude mounts your current directory. You can keep one mountless sandbox per project and reuse it across tasks. A mountless setup can also be declared in an sbxenv.yaml environment file by omitting workspace and any additionalWorkspaces mounts, then running sbx env run.
Signing commits from inside a sandbox
SSH agent forwarding is on by default. When SSH_AUTH_SOCK is set, the sandbox can use your host SSH agent to sign commits, and the private key never leaves the host. Load the key on the host and confirm it is listed:
ssh-add ~/.ssh/id_ed25519
ssh-add -L
Inside the sandbox, configure Git to sign with SSH using the forwarded key directly, since host file paths do not exist in the sandbox:
git config --global gpg.format ssh
git config --global user.signingkey "key::$(ssh-add -L | head -n 1)"
Then sign commits as usual:
git commit -S -m "feat: my change"
To apply this setup to every sandbox automatically, the docs point to the community git-ssh-sign kit.
Local sandboxes vs Cloud Sandboxes
Everything above about direct mode, clone mode, host worktrees and Git ignore snapshots is specific to local sandboxes. Cloud sandboxes have no host mount, so the guide sends you to two options instead: transfer files, or clone a remote repository inside the sandbox and push changes back. File transfer uses the cloud mode of the cp command with absolute sandbox paths:
sbx --cloud cp ./src cloud-project:/home/agent/workspace/src
This is a point-in-time copy. It does not mount or sync the local path, so later edits on either side are not reflected. For source control, the mountless pattern carries over well: clone inside the cloud sandbox and push branches to your remote. Configure cloud credentials before creating a sandbox that needs a private repository. If you move a sandbox between environments, the docs note that host mounts and clone-mode volumes are not part of that snapshot.
Troubleshooting tips from the docs
- Fetch from the sandbox remote fails. The in-sandbox Git daemon only runs while the sandbox runs. Start the sandbox again, and the CLI updates the
sandbox-<name>remote URL for the new port. - Clone mode says the path is not a Git repository on WSL. On Windows, a repository on a
\\wsl.localhostpath can fail Git’s dubious ownership check. Add the repository to Git’ssafe.directorylist as described in the troubleshooting page, then retry. - Commits are not signed. Check forwarding and socket selection with
sbx settings get ssh.agentForwardingEnabledandsbx settings get ssh.agentSocketPath. After changing either, runsbx daemon restart. Ifssh-add -Lreports that the agent has no identities, the sandbox reached the agent but no key is loaded on the host. - Ignored files behave unexpectedly. The sandbox receives a snapshot of host-specific ignored paths at creation time, not the patterns. Repository
.gitignorefiles keep working, and ignore rules never limit what the agent can read.
Key takeaways
- Direct mode is the default and the least isolated. Agree on who owns Git before you start.
--clonegives the agent a private checkout and asandbox-<name>remote you fetch from. It is fixed at creation time.- Branches do not isolate parallel tasks. Use one worktree or clone per task, or separate sandboxes.
- A host worktree keeps edits visible on the host but leaves the agent without Git.
- Mountless sandboxes let the agent own the full Git workflow, and the same clone-and-push pattern is how cloud sandboxes handle source control.
- Commit signing works through SSH agent forwarding, so private keys stay on the host.
References
Source guide: Use Git with sandboxes. Related pages: sbx run CLI reference, sbx create CLI reference, Docker Sandboxes usage, Cloud Sandboxes usage, sandbox environment files and Docker Sandboxes troubleshooting.