Docker Sandboxes for Coding Agents: Where Should the Code Live?

Docker Sandboxes for Coding Agents: Where Should the Code Live?

Enterprise Developer Platforms

Mount a linked Git worktree into a sandbox and a coding agent can edit every file, but it can’t run git status, branch or commit, because the worktree’s metadata lives outside the mount. It’s one of several trade-offs in Docker’s guide to where an agent’s code should live. For platform teams putting agents in Docker Sandboxes, the choice decides how closely developers can work alongside the agent and how much cleanup each task leaves.

The Framework

Docker’s post covers how the sbx tool can give an agent a repository. Each option changes how the human takes part, and the Git workflows documentation covers the mechanics. There are four layouts.

1. Mount Your Own Checkout

Running sbx run from a project directory mounts it at the same path inside the sandbox. You see the agent’s edits live in your editor, Git works from either side, and a dev server on your host hot-reloads the changes. It suits close collaboration on one task. The cost is sharing: switching branches changes what the agent sees, your edits become part of its work, and starting something else needs another checkout. Dependencies are shared too, so packages with native binaries, such as esbuild, can work in the Linux sandbox and fail on a macOS or Windows host.

2. Give Each Task a Worktree

A Git worktree per task gives each its own directory and branch in its own sandbox, leaving your main checkout free. The limitation is the one above: a mounted linked worktree can’t reach its Git metadata, so status, branching and commits happen on the host.

3. Use Clone Mode

sbx’s clone mode mounts your source read-only and creates an independent clone for the agent, with Git working inside the sandbox. Its branches and dependency installs stay in its own checkout. Getting the work back becomes a handoff: fetch committed branches through a Git remote sbx adds on your host, or have the agent push to the repository’s remote.

4. Keep the Project Inside the Sandbox

A mountless sandbox holds its own clone and development environment, with no link to your host copy. It works like a remote dev machine: open a shell with sbx exec or connect an editor over SSH, and push branches to get work out. Docker suggests one sandbox per project, where the agent creates its own worktrees per feature, pushes branches and opens pull requests. Previewing a web app means binding the dev server to 0.0.0.0 and publishing the port with sbx ports. Removing the sandbox deletes anything held only there, so push first.

Where It Doesn’t Apply

Tasks sharing one sandbox also share its tools and running services, so parallel work still needs coordination. Branches alone don’t isolate simultaneous edits in one working directory. For cross-repository changes, several directories can be mounted, with reference repos read-only, or a workspace manager can assemble standard clones that keep their Git access. Stack Archive covered a read-only AI reviewer that invented a CVE, Docker’s case for enforcing limits in the environment rather than in config.

The So What

Platform teams should pick a default per use: mounted checkouts for pair-style work on one task, clone mode for agents that need Git but shouldn’t touch the developer’s working tree, and mountless project sandboxes for agents running several tasks unattended. Document how work comes back, by fetch or by push, and make “push before deleting the sandbox” part of the cleanup.

Source: Docker

Content created with AI assistance and reviewed for accuracy.

💬

Join the conversation

Stack Insiders is our free community for readers who want to go deeper — share resources, ask questions, and connect with others across every vertical we cover.

Join Stack Insiders →

Newsletter coming soon.

Curated digests across AI, biohacking, photography, travel, and more. Be the first to know when we launch.