Skip to content

fix(sandbox): fall back to gateway UID:GID when no user is configured (#20979) - #20991

Closed
cluster2600 wants to merge 3 commits into
openclaw:mainfrom
cluster2600:fix/sandbox-default-user-non-root-gateway-20979
Closed

cluster2600 wants to merge 3 commits into
openclaw:mainfrom
cluster2600:fix/sandbox-default-user-non-root-gateway-20979

Conversation

@cluster2600

@cluster2600 cluster2600 commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #20979

When agents.defaults.sandbox.docker.user is not set, the container runs as root (UID 0) with --cap-drop ALL which strips DAC_OVERRIDE. Without DAC_OVERRIDE, root inside the container cannot write to workspace directories owned by the non-root gateway user — the recommended git-based install pattern. This silently breaks the Read, Write, Edit, and apply_patch file tools for all sandboxed sessions.

Root Cause

Three default values combine to create a UID mismatch (as detailed in #20979):

  1. No default user — resolveSandboxDockerConfig() resolves user from agent or global config with no fallback, so container runs as root (UID 0) when unset.
  2. capDrop: ["ALL"] — strips DAC_OVERRIDE from root.
  3. --user conditionally omitted — buildSandboxCreateArgs() only passes --user when cfg.user is truthy.

Fix

In buildSandboxCreateArgs() in src/agents/sandbox/docker.ts, when cfg.user is not explicitly set, fall back to process.getuid():process.getgid() on POSIX platforms so the container's effective user matches the gateway's file ownership:

const effectiveUser =
  params.cfg.user ||
  (typeof process.getuid === "function"
    ? `${process.getuid()}:${typeof process.getgid === "function" ? process.getgid() : process.getuid()}`
    : null);
if (effectiveUser) {
  args.push("--user", effectiveUser);
}

Behavior:

  • ✅ Explicit user config: unchanged (always takes precedence)
  • ✅ Non-root gateway (UID 1003): container gets --user 1003:1003
  • ✅ Root gateway (UID 0): container gets --user 0:0 (same as before — no regression)
  • ✅ Windows (no process.getuid): no --user flag passed (same as before)

Tests

Added src/agents/sandbox/docker.sandbox-create-args.test.ts covering:

  • Explicit user config takes precedence
  • Non-root gateway falls back to UID:GID
  • Root gateway falls back to 0:0

Workaround (no longer needed)

Users on affected setups can still manually configure:

openclaw config set agents.defaults.sandbox.docker.user "$(id -u):$(id -g)"
openclaw sandbox recreate --all

Greptile Summary

Fixes file tool access issues for non-root gateway users by falling back to the gateway process UID:GID when agents.defaults.sandbox.docker.user is not configured. The root cause was that containers ran as root with --cap-drop ALL, which stripped DAC_OVERRIDE capability, preventing write access to workspace directories owned by non-root gateway users.

  • Implemented automatic fallback to process.getuid():process.getgid() on POSIX platforms in buildSandboxCreateArgs()
  • Added comprehensive tests covering explicit config, non-root fallback, and root fallback scenarios
  • Updated CHANGELOG.md with fix details
  • Test coverage is thorough but missing Windows/non-POSIX platform test case

Confidence Score: 4/5

  • This PR is safe to merge with minimal risk - it fixes a legitimate bug without introducing breaking changes
  • The fix is well-designed and follows existing codebase patterns for POSIX detection. Tests cover the main scenarios. Score of 4 (not 5) due to missing Windows test coverage, though the implementation itself handles Windows correctly by design.
  • No files require special attention - the implementation is straightforward and safe

Last reviewed commit: 2451865

(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Feb 19, 2026

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

When `agents.defaults.sandbox.docker.user` is not set, the container
runs as root (UID 0) with `--cap-drop ALL` which strips DAC_OVERRIDE.
Without DAC_OVERRIDE, root inside the container cannot write to workspace
directories owned by the non-root gateway user — the recommended git-based
install pattern. This silently breaks Read, Write, Edit and apply_patch
file tools for all sandboxed sessions.

Fix: in `buildSandboxCreateArgs()`, when `cfg.user` is not explicitly
set, fall back to `process.getuid():process.getgid()` on POSIX platforms
so the container's effective user always matches the gateway's file
ownership. On non-POSIX platforms (Windows, where `process.getuid` is
undefined), the behavior is unchanged.

Existing behavior is fully preserved when `user` is explicitly configured
— the explicit value always takes precedence.

Fixes openclaw#20979
@cluster2600
cluster2600 force-pushed the fix/sandbox-default-user-non-root-gateway-20979 branch from bfd500d to edc7f52 Compare February 19, 2026 14:55
@cluster2600

Copy link
Copy Markdown
Contributor Author

Checking failing job. I will investigate.

@steipete

Copy link
Copy Markdown
Contributor

Closing as AI-assisted stale-fix triage.

Linked issue #20979 ("[Bug] Default sandbox config breaks file tools for non-root gateway users (post-#4026)") is currently CLOSED and was closed on 2026-02-22T22:34:02Z with state reason COMPLETED.
Given that issue state, this fix PR is no longer needed in the active queue and is being closed as stale.

If the underlying bug is still reproducible on current main, please reopen this PR (or open a new focused fix PR) and reference both #20979 and #20991 for fast re-triage.

@steipete

Copy link
Copy Markdown
Contributor

Closed after AI-assisted stale-fix triage (closed issue duplicate/stale fix).

@steipete steipete closed this Feb 24, 2026
@cluster2600
cluster2600 deleted the fix/sandbox-default-user-non-root-gateway-20979 branch October 19, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Default sandbox config breaks file tools for non-root gateway users (post-#4026)

2 participants