A minimal sandbox for running the opencode AI agent inside a Docker container with a read-only mount of your host repo and a writable workspace inside the container. The run-agent.sh helper wraps Docker Compose to start/stop the container, open a shell, sync changes back to the host, and run opencode inside the container.
- Docker with Compose v2 available as
docker compose - Optional network access: choose
--network bridgewhen starting if you need outbound internet (default isnone)
run-agent.sh— CLI to manage the agent lifecycle (start, shell, diff, sync, opencode, stop, reset, list)docker-compose.yml— base compose file for the agent container and volumesdocker-compose.sync.yml— temporary override to remount the host repo read-write during syncagent/Dockerfile— dockerd-in-docker image plus opencode installagent/entrypoint.sh— starts dockerd, initializes/workspacefrom/src, installs opencode config/auth if presentopencode/opencode.json— sample opencode permission defaults
- Start the agent container (read-only host mount by default):
./run-agent.sh start <project-name> <project-dir> [--network none|bridge]
- Open a shell inside the running agent:
./run-agent.sh shell <project-name>
- Install opencode inside the container (once per agent) and run it:
./run-agent.sh install-opencode <project-name> ./run-agent.sh opencode <project-name> [args]
- Host repo is mounted read-only at
/src; your writable workspace is/workspace. - On first start,
/workspaceis initialized from/src. - Changes in
/workspacepersist across container restarts via theagent-workspacevolume. - Check status/diffs inside the container:
./run-agent.sh diff <project-name>
- Use sync to copy tracked/untracked (non-ignored) files from
/workspaceback to the host repo:./run-agent.sh sync <project-name>
- The sync command confirms with the project name and respects
.gitignoreby usinggit ls-files. - After syncing, commit on the host as usual.
- Stop container (keeps volumes):
./run-agent.sh stop <project-name>
- Reset (deletes container and volumes; requires confirmation):
./run-agent.sh reset <project-name>
- List known projects and status:
./run-agent.sh list
./run-agent.sh start myproj /path/to/repo --network bridge./run-agent.sh shell myprojand work under/workspace- Run
./run-agent.sh opencode myproj [args]for in-container opencode - Inspect changes:
./run-agent.sh diff myproj - Sync to host:
./run-agent.sh sync myproj - On host, review and commit
- Ensure
docker composev2 is installed and accessible. - If dockerd inside the container is slow to start, rerun
./run-agent.sh shell <project-name>and check/tmp/dockerd.loginside the container. - Need internet inside the container? Start with
--network bridge.