Skip to content

Injected host content unreadable to sandbox user on macOS (skills, settings, credentials silently invisible) #154

Closed

Description

@glageju

Summary

On macOS hosts, all content injected from ~/.claude/, ~/.codex/, ~/.gemini/, etc. into the guest rootfs ends up owned by the host UID with restrictive permissions (mode 0600/0700). The sandbox user (UID 1000) inside the VM cannot read these files, so injected skills, settings, instructions, and credentials are silently invisible to the agent.

The bug has been present for every macOS user since settings injection (#53) landed.

Symptoms

User-visible: /skills inside bbox claude-code reports "No skills found" even when ~/.claude/skills/<name>/SKILL.md exists on the host.

Other manifestations (all silent):

  • ~/.claude/settings.json injected but ignored by the agent.
  • ~/.claude/CLAUDE.md injected but not loaded as global instructions.
  • Seeded credentials (--seed-credentials) injected but unreadable, so OAuth login falls through to the forwarded ANTHROPIC_API_KEY or to a re-login flow.

Most users haven't noticed because either (a) ~/.claude/skills/ is empty (plugin-installed skills live under ~/.claude/plugins/ and aren't injected at all), or (b) the silent fallback to ANTHROPIC_API_KEY masks the credential issue.

Reproduction

# On macOS with a non-root host user.
mkdir -p ~/.claude/skills/probe
cat > ~/.claude/skills/probe/SKILL.md <<'SKILL'
---
name: probe
description: Use when the user asks to test skill injection.
---
# Probe
SKILL

cd /tmp/some-project
BBOX_KEEP_VM_DATA=1 bbox claude-code
# Inside: run /skills -> "No skills found"
# Exit, then:
latest=$(ls -td ~/.config/broodbox/vms/sandbox-claude-code-* | head -1)
stat -f '%u:%g %Lp %N' "$latest/data/rootfs-work/home/sandbox/.claude/skills/probe/SKILL.md"
# -> 501:20 600 ...   (host UID, mode 0600, unreadable to guest UID 1000)

Root cause

Two-layer issue:

  1. Host-side injector silently swallows EPERM. internal/infra/settings/injector.go's bestEffortChown (and the parallel bestEffortChown in internal/infra/credential/store.go) calls os.Lchown(path, 1000, 1000) and ignores EPERM. macOS does not allow a non-root user to chown to a different UID, so this always fails on macOS. Files are written with dirPerm = 0o700 / filePerm = 0o600, leaving them owned by the host UID with no group/other access. The injector relies on the guest-side init to fix ownership at boot. See the comment in internal/infra/vm/mcpconfig.go:

    "On macOS non-root users cannot chown to a different UID; the guest init will fix ownership at boot time."

  2. Guest-side fixup short-circuits. go-microvm's boot.fixHomeOwnership (called at guest/boot/boot.go:84) does a recursive chown only when /home/sandbox itself is misowned. The OCI base image creates /home/sandbox already owned 1000:1000 (via adduser in images/base/Dockerfile), so homeAlreadyOwned returns true and the fast path runs — fixing only .ssh/ and skipping all injected content.

    Observed in the boot log:

    time=... level=INFO msg="home directory already owned correctly, fixing .ssh only"
    

The host injector's stated assumption ("the guest init will fix ownership at boot time") was never true for the common case.

homefs.MakeWritable also doesn't help: on macOS the home dir is already writable via virtio-fs (time=... msg="home directory is writable, skipping overlay"), so the overlayfs path with its own mount-point chown doesn't even run.

Why Linux users don't see it

When bbox runs on Linux as root (or with a user namespace mapping host UID to guest UID 1000), Lchown to UID 1000 succeeds host-side and files land with correct ownership. The guest fast path is harmless because the host already did the right thing.

Fix

Add an unconditional recursive chown of /home/sandbox in bbox-init after homefs.MakeWritable returns. This runs as PID 1 inside the guest where chown always succeeds, and is independent of whether the home dir itself was already correctly owned.

// cmd/bbox-init/main.go
homefs.MakeWritable(logger, homefs.SandboxHome, homefs.SandboxUID, homefs.SandboxGID)
homefs.FixInjectedOwnership(logger, homefs.SandboxHome, homefs.SandboxUID, homefs.SandboxGID)

FixInjectedOwnership calls chownRecursive (already in internal/guest/homefs/, used today by the tmpfs fallback). Cost: one extra WalkDir over /home/sandbox at boot, bounded by injected content size (typically <1 MiB / <100 files for skills + settings).

The fix is guest-side only — no changes to the host injector, rootfs hooks, file modes, or staging layout. The rootfs-work staging dir on the host still has files owned by host UID with mode 600 (correct: those files may contain credentials and shouldn't be world-readable on disk). Reconciliation happens inside the guest where bbox-init runs as root and can chown anything to anything.

Defense-in-depth alternative considered: bumping host-side injector modes to 0o755/0o644 so the sandbox user can read even when chown fails. Rejected — keeping injected content owner-only in the rootfs-work staging dir is the right call on the host; the guest is the appropriate layer to reconcile UIDs.

Verification

After the fix, with the same reproduction:

stat -f '%u:%g %Lp %N' "$latest/data/rootfs-work/home/sandbox/.claude/skills/probe/SKILL.md"
# -> 501:20 600 ...   (host side, unchanged)
# But inside the VM: /skills lists "probe"

Same fix restores ~/.claude/settings.json, ~/.claude/CLAUDE.md, and seeded credentials to working order on macOS.

Follow-ups (separate issues)

  • Plugin injection (~/.claude/plugins/) is not implemented for Claude Code today — the empty plugins directory in the rootfs is created by Claude Code itself at startup, not by bbox.
  • The host-side injector silently swallowing chown errors is the invariant the guest fixup restores. Worth a follow-up to add a warn-once log on host-side EPERM so future regressions in the guest fixup don't go invisible again.

Activity

  1. added
    bug
    on May 18, 2026
  2. self-assigned this
    on May 18, 2026
  3. added a commit that references this issue on May 22, 2026
    bf997e4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions