An untrusted Claude Code session in Docker: limits, monitoring and a separate user
Introduction
The container setup keeps
Claude Code inside one mounted project.
That is a real boundary: the host home,
other checkouts, the
Docker socket and the installed host tools
are not in the container. But the mounted project is still a host
directory, and the host can execute what is written there.
This page is about the case where the session itself is not trusted: a
repository with third-party content, a prompt that may be injected, an
agent that fetched a web page, a long autonomous run, or simply a task
whose result you want to review before any of it runs on your machine.
It shows what the container still can and cannot do, how to watch it,
how to give it a separate Unix identity, and what happens to the work
when the session ends.
What untrusted means
A session is trusted when you would run any script it writes, on the host, as yourself, without reading the script first. That is a high bar, and most sessions do not meet it. A session is untrusted when at least one of these is true:
- The repository contains code, tests, hooks or configuration you did not write.
- The session reads web pages, issues, pull requests or third-party documentation.
- It uses an MCP server or another tool that returns text you do not control.
- It installs dependencies or runs a package manager.
- It works on a shared machine, or on a checkout that other people can write.
- It runs unattended for a long time, so a mistake has time to spread.
- You did not write the brief, or you cannot inspect every command it ran.
Trust belongs to the task, not to the model. A model you trust can still
be prompt-injected by a file in the repository, and a model you do not
trust can still produce a useful patch. The container does not make a
session trusted, and --delegate does not make it
trusted either: delegation is a capability, not a trust label.
Ask two questions before the run: what can this process reach?
and what will I run after it? The first is answered by the mount,
the network and the credentials. The second is answered by your review
workflow, and it is the question that decides whether the work is safe
to keep.
What the container cannot do
The launcher starts the container with one bind mount, one named volume and a tmpfs:
host container ┌──────────────────────────────┐ ┌──────────────────────────────┐ │ $PWD ──── rw mount ──────────┼─────────►│ /work │ │ │ │ the project, read-write │ │ ~/.ssh ──── X ──────┼─── X ───►│ no host home │ │ ~/.config ──── X ──────┤ │ no host ~/.claude │ │ other checkouts ──── X ──────┤ │ no other checkout │ │ docker.sock ──── X ──────┤ │ no Docker socket │ │ installed tools ──── X ──────┤ │ no installed host tools │ └──────────────────────────────┘ │ │ │ /home/claude │ │ named volume: login, │ │ settings, history │ │ /tmp │ │ tmpfs: gone on exit │ └─────────────┬────────────────┘ │ network ▼ API, mirrors, other hosts
Directly, the container cannot:
- Read ~/.ssh, ~/.config, browser profiles, cloud credentials or the host ~/.claude.
- See another checkout, another worktree or a host directory outside the mounted project.
- Talk to /var/run/docker.sock, start containers, inspect them or mount their filesystems.
- Change ~/.local/share/start-claude/tools, ~/.local/bin or the installed launcher.
- Become root on the host: the root filesystem is read-only, all capabilities are dropped, no-new-privileges is set and the image has no sudo.
- Write outside /work, the home volume and /tmp.
- Keep a process alive after the container exits.
These are limits of the mount and the container configuration, not promises about the kernel. Docker shares the host kernel. A kernel vulnerability, a Docker daemon vulnerability or a misconfigured --privileged flag can break every line above. For code you consider hostile rather than merely untrusted, use a virtual machine with its own kernel; the last section says more.
What it can still do
Inside the mount, the session is powerful. It can read and write every file in the project, including the files that decide what the host runs later:
| It can | Why it matters |
|---|---|
| Read and write every file under /work | The project is the boundary. Everything committed or untracked in it is visible. |
| Change .git: hooks, config, refs, branches, tags | The next host git command can execute a hook, a filter or a filesystem monitor from the checkout. |
| Write PHP, templates, JavaScript and configuration served by a local web server | A request to the served checkout executes the new code in the web server container. |
| Change tests, linters, Makefile, package.json scripts, conftest.py | Running the project checks on the host runs the changed code. |
| Change container/tools and container/containerfiles | --install-tools copies the tools to the host; the worker image is built from the containerfiles. |
| Write a queue request with --delegate | The host starts an OpenCode worker with network access and the agent credentials. |
| Read its own environment | If ANTHROPIC_API_KEY is exported, the process can read it. A key it can use is a key it can leak. |
| Read and change its home volume | Settings, hooks, history and the login survive between runs, so a change can persist after the session. |
| Use the network | It can reach the model API, package mirrors and any host the network allows. It can upload what it can read. |
| Consume CPU, memory and disk in /work | The launcher sets no quotas. A runaway build can fill the disk. |
| Create symlinks | A link that points outside the container is harmless inside it, but the host may follow it later. |
The important sentence is the first one: the project is the boundary. The container is not a vault that makes the project safe to execute. It is a fence that keeps the rest of the host out of the session.
How sandbox files reach the host
Every path below starts with a file the session can write and ends with code the host runs. None of them needs a container escape.
sandbox writes in /work host executes ┌──────────────────────────────┐ ┌──────────────────────────────┐ │ .git/hooks/* │─ git ──►│ your shell (git commit) │ │ .git/config: fsmonitor, │ │ │ │ hooksPath, filters │ │ │ │ container/src/*.php │─ HTTP ─►│ Apache/PHP on :8080 │ │ container/tools/*.sh │─ run ──►│ your shell (tests, install) │ │ container/containerfiles/* │─ build ►│ Docker daemon │ │ package.json, Makefile, │─ test ─►│ npm, make, pytest │ │ conftest.py │ │ │ │ reports/delegate/.queue/* │─ queue ►│ OpenCode worker │ │ symlink to /home/andrei/... │─ copy ─►│ tar, rsync, Apache follow it │ └──────────────────────────────┘ └──────────────────────────────┘
| Sandbox writes | Host action that runs it | Control |
|---|---|---|
| .git/hooks/*, .git/config | git commit, git status, git diff | Use a separate clone, not a worktree; run host git with an empty core.hooksPath and core.fsmonitor=false. |
| container/src/**/*.php | A request to the local Apache/PHP server | Never serve a sandbox-writable checkout. Serve a separate deploy checkout, or stop the server during the run. |
| container/tools/** | --install-tools, a test script, a manual command | Run installed tools, not checkout tools. Review before reinstalling. |
| container/containerfiles/** | docker build for the worker image | Build from a trusted checkout; review the Dockerfile before the build. |
| package.json, Makefile, conftest.py | npm test, make, pytest | Run tests in a disposable container without secrets or host mounts. |
| .envrc, .env, shell startup files | direnv allow, a new shell, a sourced script | Never source files from an untrusted checkout; read them first. |
| reports/delegate/.queue/** | The host watcher and delegate.py | Do not pass --delegate for an untrusted session. |
| A symlink to a host path | cp -r, tar, rsync, Apache with FollowSymLinks | List links with find -type l; use rsync --safe-links; disable symlink following in the server. |
Git deserves its own warning. A worktree shares the main
repository's .git directory: hooks, config,
refs and objects are common. A session in a worktree can add a
pre-commit hook, set
core.fsmonitor to a command, or add a filter
that runs on checkout. The next host git
command in the main checkout can then execute it. A separate
git clone has its own .git
and does not touch the main repository.
The same logic applies to a checkout served by Apache: the server does
not know which files you trust. If the docroot is the same directory the
sandbox can write, a PHP file becomes a web endpoint. Keep the served
checkout separate from the sandbox checkout, or stop the server while
the untrusted session runs.
Working with an untrusted session
There are three levels of separation. Pick the weakest one that matches the risk, and do not pretend it is stronger than it is:
| Level | Setup | Protects against | Does not protect against |
|---|---|---|---|
| A. Separate clone, same user | The container runs as you, but mounts a clone instead of the main checkout. | Changes to the main repository, its hooks and its other files; accidental edits. | A container escape that lands as your UID; host files your UID can read; a served clone. |
| B. Separate clone, separate UID | A dedicated host user owns the clone; the container runs with that UID; no Docker group. | Your home, main checkout and credentials, even after a process escapes the container namespace. | A kernel exploit that gains root; a root-owned Docker daemon the user can reach; a served clone. |
| C. Separate machine or VM | The session runs in a VM with its own kernel and disk. | Kernel and container-runtime exploits; most side channels. | Data you deliberately copy into the VM; a shared clipboard or shared folder. |
Level A is a good default for a repository you mostly trust but want to review. Level B is the practical choice for a genuinely untrusted session on your own workstation. Level C is for code you believe may be hostile, or for a machine that holds secrets you cannot move.
Step 1: freeze the base commit
Start from a commit you have reviewed, not from the current working tree. The clone must not contain your uncommitted experiments, local configuration or untracked secrets.
git -C ~/github/aredel log --oneline -1
git -C ~/github/aredel status --short
Write the commit hash down. Every later step uses it.
Step 2: make a separate clone, not a worktree
A bundle is the cleanest way to hand over one commit without giving the sandbox user read access to your checkout:
git -C ~/github/aredel bundle create /tmp/base.bundle <commit> sudo install -d -m 700 -o claude-sandbox -g claude-sandbox /srv/claude-sandbox sudo -u claude-sandbox -H git clone /tmp/base.bundle /srv/claude-sandbox/task-1 sudo -u claude-sandbox -H git -C /srv/claude-sandbox/task-1 switch -c sandbox/task-1 rm /tmp/base.bundle
The clone has its own .git. It does not share hooks, config or refs with the main checkout. If you use a worktree anyway, read the git warning in the previous section first and disable hooks and filesystem monitors for every host command you run in it.
Step 3: remove what the session does not need
Check what the clone contains before the first run:
git -C /srv/claude-sandbox/task-1 grep -n -i -E 'password|secret|token|api[_-]?key' -- .
git -C /srv/claude-sandbox/task-1 ls-files | grep -E '^\.env|\.pem$|\.key$'
A committed secret is already in the history; removing it from the working tree does not help. If the repository has one, rotate it before the run, or use a clone with the history rewritten. Do not pass a host key file, a cloud credential or a personal access token into the sandbox. If the task needs a credential, give it a scoped, short-lived one that you can revoke.
Step 4: start with no delegation
Run the installed launcher from the clone, with --no-delegate stated explicitly. The checkout copy of the launcher is not trusted for this run; use the installed copy, or install the tools as the sandbox user from the frozen commit.
~/.local/share/start-claude/start_claude.sh --no-delegate
Do not add the Docker socket, the host home, another checkout or --privileged to make a task easier. Each of those removes the boundary this page is about. If the task needs a reference directory, copy it into the clone or mount it read-only as a separate directory; do not mount your home.
Step 5: watch from outside
Start the monitors before the session does real work. The next section has the commands. At minimum, keep a terminal with docker events and a filesystem watcher on the clone; a session that starts a build or writes outside the expected paths is easier to stop early.
Step 6: never run the checkout on the host
While the session runs, do not run its tests, its installer, its formatter, its git hooks or its PHP on the host. If you need to inspect a file, read it. If you need to run it, run it in a disposable container with no host mounts except a read-only copy of the file.
Step 7: extract a patch or a bundle
When the session is done, export the change as data. Do not ask the host to fetch directly from the sandbox repository path: a local git fetch starts upload-pack in that repository, and its config can run commands. A patch or a bundle file is parsed as data.
cd /srv/claude-sandbox/task-1 git add -A git diff --cached --binary > /srv/claude-sandbox/task-1.patch git bundle create /srv/claude-sandbox/task-1.bundle --all
The patch is the review artifact. The bundle keeps the commits, author information and binary files. Copy both out of the sandbox directory before you remove it.
Getting the work out
Review the patch as text before it touches the main checkout:
git apply --stat /srv/claude-sandbox/task-1.patch git apply --check /srv/claude-sandbox/task-1.patch git apply --numstat /srv/claude-sandbox/task-1.patch
Read the diff. Look for new hooks, new scripts, changes to .gitattributes, changes to CI, new dependencies, encoded blobs and files outside the expected paths. Then apply it on a fresh branch:
git -C ~/github/aredel switch -c review/task-1 <commit> git -C ~/github/aredel apply --index /srv/claude-sandbox/task-1.patch git -C ~/github/aredel diff --cached --check git -C ~/github/aredel status --short
git apply does not run hooks. Do not use git am for an untrusted patch: it applies the patch and creates a commit, and the apply-patch hooks can run. If you want the original commits, verify and fetch the bundle:
git bundle verify /srv/claude-sandbox/task-1.bundle git -C ~/github/aredel fetch /srv/claude-sandbox/task-1.bundle 'refs/heads/sandbox/task-1:refs/heads/sandbox/task-1' git -C ~/github/aredel log --oneline <commit>..sandbox/task-1 git -C ~/github/aredel diff --stat <commit>..sandbox/task-1
Fetching from a bundle reads a pack file; it does not run the sandbox repository's config. Check out the branch only after the diff looks right, and disable hooks for that checkout:
git -C ~/github/aredel -c core.hooksPath=/home/andrei/.config/git/no-hooks -c core.fsmonitor=false switch sandbox/task-1
Create /home/andrei/.config/git/no-hooks as an empty directory first. The flags override repository settings for that one command. They do not make an untrusted checkout safe to build; they only stop git from running a hook or a filesystem monitor while you look at it.
Monitoring its activity
Monitoring answers what happened. It is not a boundary, and a log the session can edit is evidence, not proof. The useful rule is: send each event to a place the session cannot write. Docker logs, the host journal, an eBPF ring buffer and a proxy log are outside the mount. A JSONL file under /work is inside it.
what you watch where it goes ┌──────────────────────────────┐ ┌──────────────────────────────┐ │ docker events, logs, stats │───────►│ host journal / terminal │ │ eBPF: execve, openat, connect│───────►│ host ring buffer │ │ auditd, fanotify, inotify │───────►│ host audit log │ │ network: proxy, tcpdump, DNS │───────►│ host capture │ │ Claude hooks (cooperative) │───────►│ container stderr → docker log│ └──────────────────────────────┘ └──────────────────────────────┘
| Tool | What it shows | What it misses |
|---|---|---|
| docker events --filter container=<name> | Start, stop, exec, health and image events. | Commands inside the container, file contents. |
| docker logs -f <name> | The process output. With claude -p or hooks that copy JSON to stderr, this is a usable transcript. | The interactive TUI does not print every tool call by default. |
| docker stats, docker top | CPU, memory, PIDs and the process list. | What the processes read or write. |
| docker diff <name> | Changes in the container writable layer. | Bind mounts and named volumes, including the project and the home volume. |
| fatrace, inotifywait | File writes, creates, deletes and renames in the clone. | Reads, network, processes that never touch the watched tree. |
| auditd | Host audit records for a watched path or syscall. | Container path names can differ from host paths; needs rules and a daemon. |
| execsnoop, opensnoop, tcpconnect | Every execve, file open and outbound connection, with host PIDs. | Needs root and a kernel with eBPF; high volume on a busy host. |
| Falco, Tetragon, Tracee | Container-aware rules and alerts: shell in container, write to a sensitive path, unexpected connection. | Rule tuning; a kernel-level attacker can still evade. |
| Proxy or DNS log | Destinations and bytes, even when TLS hides the payload. | Direct IP connections that bypass the proxy; encrypted content. |
| Claude Code hooks | Tool name, input and response, if the session keeps the hook. | A session that can edit its settings can remove the hook. |
Start with the container name. The launcher prints it and puts the project name in it; it is also in docker ps --format '{{.Names}}'.
docker events --filter container=<name> --filter type=container docker logs -f <name> docker stats <name> docker top <name> aux
For filesystem changes, watch the clone on the host. fatrace reports every write on the filesystem; filter the output by the clone path. inotifywait is enough for one directory tree and is easier to read.
sudo fatrace -f W -t -o /tmp/claude-fs.log inotifywait -m -r -e modify,create,delete,move /srv/claude-sandbox/task-1
For process and network activity, the BCC tools give one line per event. They see container processes as host PIDs, so the container name is not in the output; correlate by PID with docker top or start the tools after the container.
sudo execsnoop-bpfcc -t sudo opensnoop-bpfcc -t sudo tcpconnect-bpfcc -t
On the host, auditd can watch the clone and the home volume path:
sudo auditctl -w /srv/claude-sandbox/task-1 -p wa -k claude-sandbox sudo ausearch -k claude-sandbox -i
A proxy is both a monitor and a restriction. Point the container at an HTTP proxy that allows only the model API and the package mirrors, and read its access log. The proxy sees destinations even when TLS hides the content. If the container can reach the internet directly, it can bypass the proxy.
Claude Code hooks are the cooperative layer. They are useful when the session is not trying to hide, and they are easy to remove when it is. The image has cat, so a minimal hook can copy the JSON event to stderr, where Docker captures it:
{ "hooks": { "PreToolUse": [ { "hooks": [ { "type": "command", "command": "cat >&2" } ] } ], "PostToolUse": [ { "hooks": [ { "type": "command", "command": "cat >&2" } ] } ] } }
Put this in the sandbox home volume, or better, bake it into a managed settings file in the image and make it read-only. A hook in a writable settings.json is a request, not a guarantee. The same applies to the transcript in the home volume: it is useful after a crash, but the session can edit it.
Ownership and UID models
Linux checks numeric user IDs, not user names. A process with UID 1000 inside the container is the same principal as your UID 1000 on the host when it writes through a bind mount. Calling the container user claude changes nothing if the number is 1000. This is why the launcher builds the image with your UID: files it creates belong to you, and the checkout stays usable. It is also why the same setup gives you no protection from a process that escapes the container namespace: it escapes as you.
| Model | Container UID | Can write | Use when |
|---|---|---|---|
| Same UID, one mount | Your UID | The mounted checkout and its home volume | The session is trusted; you want convenience and protection from accidents. |
| Same UID, separate clone | Your UID | The clone and its home volume | You want to review before the main checkout changes; the session is not fully trusted. |
| Separate UID, separate clone | Sandbox UID | Only the clone and the sandbox home | The session is untrusted; you want host-level separation without a VM. |
| Separate UID, rootless Docker | Subuid range | Only the clone and the sandbox home | The session is untrusted and you can spend time on the rootless setup. |
| Dedicated VM | VM user | The VM disk | The code may be hostile, or the host holds secrets you cannot move. |
A separate UID is the useful middle ground. It does not need a second machine, and it survives a process that leaves the container namespace: the process is still the sandbox UID, so your 0600 files stay unreadable and your checkout stays unwritable. It does not survive a kernel exploit that gains root, and it does not help if the sandbox user is in the docker group: that group is equivalent to root on the host.
your user, UID 1000 sandbox user, UID 1501 ┌──────────────────────────┐ ┌──────────────────────────┐ │ ~/.ssh, ~/.config │ │ /srv/claude-sandbox │ │ ~/github/aredel │ │ task-1 (clone, rw) │ │ main checkout │ │ home volume (rw) │ │ not writable by 1501 │ │ │ └────────────┬─────────────┘ └────────────┬─────────────┘ │ read-only reference │ read-write └──────────────► container UID 1501 ◄─┘
There are two ways to give the container the sandbox UID:
- Run the launcher as the sandbox user under rootless Docker. The user owns its own Docker daemon; the container root maps to a subuid, and the host root is not reachable. This is the cleanest single-host setup.
- Run the launcher as yourself and pass --user <uid>:<gid> to docker run. You keep the Docker daemon; the container process runs as the sandbox UID. The installed launcher does not expose this flag, so this needs a small private wrapper or a change to the launcher. Do not add the sandbox user to the docker group to avoid the wrapper.
If you cannot create a user, ACLs can give an existing UID access to one directory without changing the rest of the host:
sudo setfacl -R -m u:claude-sandbox:rwX /srv/claude-sandbox/task-1 sudo setfacl -R -d -m u:claude-sandbox:rwX /srv/claude-sandbox/task-1 getfacl -R /srv/claude-sandbox/task-1 | head
Use ACLs for the clone, not for your home. A recursive ACL on the home directory is easy to get wrong and hard to audit. A read-only reference directory can get rX instead of rwX, or a read-only bind mount.
A separate user, step by step
This is level B from the workflow table. It assumes Ubuntu, a Docker installation for your own user and sudo. The sandbox user gets no shell password, no Docker group membership and no host home mount.
1. Create the user and its directory
sudo adduser --disabled-password --gecos '' claude-sandbox sudo passwd -l claude-sandbox sudo install -d -m 700 -o claude-sandbox -g claude-sandbox /srv/claude-sandbox id claude-sandbox
The account is locked for password login. It can still own files and run processes through sudo -u or a rootless Docker daemon.
2. Clone the frozen commit as that user
git -C ~/github/aredel bundle create /tmp/base.bundle <commit> sudo -u claude-sandbox -H git clone /tmp/base.bundle /srv/claude-sandbox/task-1 sudo -u claude-sandbox -H git -C /srv/claude-sandbox/task-1 switch -c sandbox/task-1 rm /tmp/base.bundle
The clone is owned by claude-sandbox. Your main checkout is not in the clone and is not writable by that user.
3. Verify the separation before the run
sudo -u claude-sandbox -H test -w /home/andrei/github/aredel && echo BAD || echo 'main checkout not writable' sudo -u claude-sandbox -H test -r /home/andrei/.ssh/id_ed25519 && echo BAD || echo 'ssh key not readable' sudo -u claude-sandbox -H test -w /srv/claude-sandbox/task-1 && echo 'clone writable' namei -l /home/andrei/.ssh/id_ed25519
The first two commands must not print BAD. If they do, fix the ownership or permissions before starting the session. namei shows which directory in the path is letting the sandbox user through.
4. Give the sandbox user its own Docker daemon
Rootless Docker is the part that keeps the sandbox user out of the root-owned daemon. Install the rootless extras and the UID mapping tools, add a subuid and subgid range, then run the setup as the sandbox user:
sudo apt-get install -y uidmap dbus-user-session docker-ce-rootless-extras sudo usermod --add-subuids 100000-165535 --add-subgids 100000-165535 claude-sandbox sudo loginctl enable-linger claude-sandbox sudo -u claude-sandbox -H dockerd-rootless-setuptool.sh install
The setup script prints the environment and the systemctl --user commands for that user. Follow its output; the exact unit name depends on the Docker version. Check that the sandbox user talks to the rootless daemon, not the system one:
sudo -u claude-sandbox -H env XDG_RUNTIME_DIR=/run/user/$(id -u claude-sandbox) docker info --format '{{.SecurityOptions}}'
The output should mention rootless. If it does not, stop here: a sandbox user in the docker group is root-equivalent, and the rest of this recipe gives a false sense of separation.
5. Install the launcher and start a fresh session
Install the host tools as the sandbox user from the frozen clone. The installer copies the launcher and the host tools into that user's ~/.local/share/start-claude, outside the mounted checkout.
sudo -u claude-sandbox -H bash -lc 'cd /srv/claude-sandbox/task-1 && ./container/tools/ai/start_claude.sh --install-tools' sudo -u claude-sandbox -H bash -lc 'cd /srv/claude-sandbox/task-1 && ~/.local/share/start-claude/start_claude.sh --no-delegate'
The second command starts the container from the clone, as UID 1501, with no delegation. If the task needs a model key, give it a scoped key through --api-key-file; remember that the process can read any key it can use. A separate login in the sandbox home volume is easier to revoke than your personal subscription.
6. Use a fresh home volume for each untrusted run
The launcher names the home volume aredel-claude-home-<uid> and reuses it. That is convenient for a trusted session and wrong for an untrusted one: settings, hooks and history persist, and the session can leave a hook for the next run. Remove the volume when the run ends:
sudo -u claude-sandbox -H env XDG_RUNTIME_DIR=/run/user/$(id -u claude-sandbox) docker volume rm aredel-claude-home-$(id -u claude-sandbox)
This also removes the login, so the next run asks for a new one. For a truly untrusted session, that is the point. If you need to keep a transcript, copy it out before removing the volume; the next section shows how.
After /exit: what survives
When you type /exit in Claude Code, the claude process exits. The launcher started the container with docker run --rm, so Docker stops the container and removes it. The container does not stay around as a stopped entry and does not keep a writable layer on disk.
| What | After /exit | Where it lives | How to clean it |
|---|---|---|---|
| The container | Removed | Nowhere; docker ps -a should not list it | Nothing to do; if it is still running, docker stop |
| The project work | Kept | The host directory mounted at /work | git status, commit or delete; remove the clone when done |
| Home volume | Kept | aredel-claude-home-<uid> | docker volume rm; back it up first if needed |
| /tmp | Lost | tmpfs inside the container | Nothing; copy anything useful before exit |
| Container writable layer | Lost | Removed with the container | Nothing; the root filesystem is read-only anyway |
| The image | Kept | aredel-claude | docker image rm aredel-claude |
| Build cache | Kept | The Docker builder cache | docker builder prune |
| Docker logs | Removed with the container | The container log | Export before exit if you need them; use a log driver for retention |
The project work is the easy case: it was never inside the container. /work is a bind mount of a host directory, so every file the session wrote is already on your disk. After /exit, go to that directory and run git status. The container is gone; the files are not.
cd /srv/claude-sandbox/task-1 git status --short git diff --stat git diff --cached --stat
The home volume is the case people forget. It holds the login, the settings, the session history and anything the session wrote under /home/claude. It survives /exit and is not visible in the project. List it and mount it in a helper container to look inside:
docker volume ls | grep aredel-claude-home docker run --rm -it -v aredel-claude-home-1000:/home/claude aredel-claude bash ls -la /home/claude
Replace 1000 with the UID that started the container, or with the sandbox UID in the separate-user setup. If you find notes, a transcript or a file worth keeping, copy it out before removing the volume:
docker run --rm -v aredel-claude-home-1000:/home/claude -v "$PWD:/backup" aredel-claude tar czf /backup/claude-home.tgz -C /home claude
If the container is still running because the terminal disconnected instead of exiting, do not remove it. Copy the home volume and the /tmp files while it is alive, then stop it:
docker ps --filter label=start-claude.project docker cp <name>:/home/claude ./claude-home-backup docker cp <name>:/tmp ./claude-tmp-backup docker stop <name>
A stopped container without --rm would still hold its writable layer, but the launcher always passes --rm. If you copied the launcher and removed that flag, inspect it with docker diff and docker cp before docker rm.
Cleaning up without losing valid work
The order matters: preserve first, then delete. A safe sequence for a finished untrusted run is:
- Export the patch or bundle from the clone.
- Review the patch and apply it to a review branch in the main checkout.
- Run the project checks in a disposable container, not on the host.
- Commit or discard the reviewed change.
- Remove the clone, the home volume, the image if you no longer need it, and the build cache.
git -C /srv/claude-sandbox/task-1 status --short git -C /srv/claude-sandbox/task-1 clean -nd sudo rm -rf /srv/claude-sandbox/task-1 docker volume rm aredel-claude-home-1000 docker image rm aredel-claude docker builder prune
git clean -nd lists what would be removed and
removes nothing. Read the list before you drop the -n.
If the clone has a branch you have not exported, remove the directory
only after the bundle is on the host and verified.
Disk usage is worth a look before and after:
docker system df docker system df -v du -sh /srv/claude-sandbox/task-1 du -sh ~/.local/share/start-claude
The container itself is not the disk problem after /exit: it is gone. The image, the build cache, the home volume and the project build artifacts are what remain. The image is shared by every run and is usually worth keeping; the build cache and the volume are the parts to clean when a run is over.
Checklist
- [ ] The session is untrusted, and the workflow matches the risk level.
- [ ] The base is a reviewed commit, not the working tree.
- [ ] The sandbox uses a separate clone, not a worktree that shares the main .git.
- [ ] The clone is owned by a different UID, or at least not writable by the main checkout.
- [ ] The sandbox user is not in the docker group.
- [ ] The container has no host home, no Docker socket, no other checkout and no --privileged.
- [ ] --delegate is off.
- [ ] The checkout is not served by Apache/PHP or any other host web server.
- [ ] No host key, token or personal credential is passed in; any key is scoped and revocable.
- [ ] The home volume is fresh, or its persistence is understood and accepted.
- [ ] Docker events, logs and a filesystem watcher run outside the container.
- [ ] The patch or bundle is exported and reviewed before anything is applied.
- [ ] Tests run in a disposable container, not on the host.
- [ ] Hooks and filesystem monitors are disabled for host git commands on the untrusted tree.
- [ ] The clone, volume, image and build cache are cleaned up after the work is preserved.
Limits of Docker isolation
Docker is a process isolation tool built on Linux namespaces, cgroups, capabilities and a shared kernel. It is good at keeping one process tree from seeing another. It is not a virtual machine, and it is not a security boundary against a kernel exploit.
- The kernel is shared. A kernel vulnerability can turn a container process into a host process. Rootless Docker and user namespaces reduce the impact, but they do not replace a separate kernel.
- The daemon is root. Access to the Docker socket is root access. A user in the docker group can start a privileged container and mount the host filesystem.
- The network is open unless you close it. The mount stops file reads, not uploads. A session that can read the project can send it anywhere the network allows.
- Monitoring is not prevention. A log tells you what happened after it happened. If the session can edit the log, it is not even evidence.
- Review is the last boundary. The patch you apply is the code you chose to trust. Read it before it runs.
For code that may be actively hostile, use a virtual machine with its own kernel: QEMU/KVM, a cloud instance, or a disposable desktop VM. Pass the repository in as a read-only disk or a copy, export the patch the same way, and destroy the VM afterward. That is more work than a container, and it is the correct tool when the threat is a kernel or Docker escape rather than a bad edit.
Troubleshooting
- The container is still listed after /exit. Check docker ps -a --filter label=start-claude.project. If it is running, the terminal disconnected instead of exiting; copy what you need with docker cp, then docker stop. If it is stopped and has no --rm, inspect it before docker rm.
- The home volume has the wrong owner. A volume created for UID 1000 is not writable by UID 1501. Remove it and let the new UID create a fresh one, or chown it in a helper container.
- Git says the repository is dubious. The clone is owned by another UID. Do not add safe.directory=*; add the exact path, or review the patch in the main checkout instead of running git in the clone.
- A hook still runs on the host. The checkout shares .git with the main repository, or core.hooksPath points into it. Use a separate clone and run host git with an empty core.hooksPath.
- A PHP file is reachable on the local server. The served docroot is the sandbox checkout. Stop the server or point it at a separate deploy checkout; do not request the file to see whether it works.
- The patch does not apply. The base commit moved, or the patch contains binary files. Use the bundle, or apply with --3way on a review branch and resolve by hand.
- A symlink points outside the project. find /srv/claude-sandbox/task-1 -type l -ls lists it. Remove it before copying the tree; use rsync --safe-links or tar --no-recursion where appropriate.
- The disk is full. docker system df -v shows images, containers, volumes and build cache. The container is gone after /exit; the image, cache, volume and project artifacts are the likely users.
- Rootless Docker does not start. Check /etc/subuid and /etc/subgid, the dbus-user-session package, lingering for the user and the setup script output. A rootless daemon needs a user session, not just a login shell.
- Delegation was on by mistake. Stop the container and the watcher, remove the queue folder if you do not need it, and rerun with --no-delegate. Review the worker worktree and the watcher log before deleting anything.
Article author: Arthur Isaev