DockerJin KimExplainer
Where should your code live in a Docker Sandbox?
Summary
The post examines where to place code files when using a Docker sandbox for agent-based development. It describes four arrangements: mounting the host checkout directly, using Git worktrees (though the agent cannot run Git on a linked worktree), employing clone mode for an independent checkout with branch handoff via a remote, and keeping the project entirely inside the sandbox without a host mount. Each setup affects how the human collaborates, from seeing live diffs to managing multiple tasks with separate branches. The post also covers handling native binary dependencies that may break across host and sandbox, previewing web apps by publishing ports, and combining multiple repositories in one sandbox. The choice depends on the desired collaboration level and whether the agent manages its own Git operations.
Context
The post is a guide for developers using Docker sandboxes with AI agents, explaining how to organize code files for collaboration. It covers four main arrangements: mounting the host checkout, using Git worktrees, clone mode, and keeping the project entirely inside the sandbox. Each arrangement has trade-offs for live collaboration, Git access, and dependency management.
Takeaways
Mounting a host checkout allows live collaboration but shares dependencies that may break across host and sandbox.
Git worktrees give each task a separate directory, but a linked worktree lacks .git metadata so the agent cannot run Git commands.
Clone mode gives the agent an independent checkout with full Git access, and branches can be handed off via a remote.
FAQ
How do I preview a web app inside a mountless sandbox?
Ask the agent to start the development server on port 8080 bound to 0.0.0.0, then publish the port from the host using `sbx ports my-sandbox --publish 8080:8080` and open http://localhost:8080 in your browser.
What happens to native dependencies when sharing a checkout?
Packages with native binaries, such as esbuild, may work in the Linux sandbox and fail on a macOS or Windows host. Reinstalling on the host can reverse the problem, so keep separate dependency installations or run the app consistently in one environment.
Can the agent make Git commits on a linked worktree?
No, because a linked worktree's .git file points to metadata outside the mount, which the agent cannot reach. The agent can edit files, but checking status, branching, and committing must happen on the host.
Source and freshness
- Source
- docker.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.