fix(sandbox): run containers as host user instead of root#355
Merged
asheshgoplani merged 4 commits intoasheshgoplani:mainfrom Mar 18, 2026
Merged
Conversation
--cap-drop=ALL drops DAC_OVERRIDE, preventing root from reading bind-mounted files owned by the host user. Run as --user uid:gid so the container process owns the files naturally.
The host UID has no /etc/passwd entry inside the container, so HOME defaults to /. Explicitly set HOME to containerHome so tools find their config directories.
The container now runs as the host user instead of root. /root must be traversable (execute bit) so the non-root user can reach installed binaries at /root/.local/bin/ and /root/.opencode/bin/.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--user <uid>:<gid>todocker createso sandbox containers run as the host user instead of rootHOME=/rootexplicitly since the host UID has no/etc/passwdentry in the containerchmod 755 /rootin the Dockerfile so the non-root user can traverse to installed binariesProblem
--cap-drop=ALLdropsDAC_OVERRIDE, which prevents root from reading files it doesn't own. Sandbox file sync (sandbox.go) creates files owned by the host user (UID 1000, mode 0600). The container runs as root (UID 0), so root can't read.credentials.json,settings.json, etc. — causing Claude to hang on startup.Fix
Run the container as the host user (
--user uid:gid) instead of root. This is cleaner than re-addingDAC_OVERRIDEbecause:--cap-drop=ALLhardening--dangerously-skip-permissionscontinues to work because Claude Code gates it viaIS_SANDBOX=1env var, not a UID check.Test plan
internal/dockerunit tests pass (3 new tests forHOMEenv var)--cap-drop=ALLclaude --versionworks inside container as non-root user