Skip to content

Skip recursive home chown when ownership is correct#62

Merged
JAORMX merged 1 commit intomainfrom
jaosorior/skip-home-chown
Apr 7, 2026
Merged

Skip recursive home chown when ownership is correct#62
JAORMX merged 1 commit intomainfrom
jaosorior/skip-home-chown

Conversation

@JAORMX
Copy link
Copy Markdown
Contributor

@JAORMX JAORMX commented Apr 7, 2026

Summary

  • Skip the full recursive chown of /home/sandbox when the directory is already owned by the correct uid/gid (the common case on Linux with user-namespace-backed virtiofs)
  • Only walk .ssh/ to enforce strict SSH permissions (0700 dirs, 0600 files)
  • Preserve the full recursive chown as fallback for platforms without user namespaces (e.g. macOS)

Problem

fixHomeOwnership was doing a filepath.WalkDir + Lchown on every file under /home/sandbox. For the claude-code guest image this is ~120K files / ~5GB, taking ~14 seconds of guest boot time. This was the single largest contributor to slow VM startup.

Since we now use user namespaces (WithUserNamespaceUID), libkrun's virtiofs passthrough has CAP_SETGID within the namespace, and xattr.SetOverrideStat on the rootfs already gives the guest correct ownership. The recursive chown was redundant on Linux.

Result

Measured with OTel tracing (--trace) on the brood-box CLI:

Metric Before After
microvm.SSHWaitReady 16.0s (8 probes) 2.1s (1 probe)
Guest boot → SSH ready ~16s ~2s
Total "Sandbox ready" 21.5s 7.5s

Test plan

  • go test ./... — all tests pass
  • Verified agent can read workspace files correctly after the change
  • Tested with brood-box end-to-end: bbox claude-code --trace --timings shows 7.4s Sandbox ready

🤖 Generated with Claude Code

With user-namespace-backed virtiofs (the default on Linux since the
CAP_SETGID fix), the rootfs already has correct uid/gid ownership
via xattr.SetOverrideStat. The previous code walked the entire home
directory tree (~120K files, ~5GB for claude-code images) doing
Lchown on every entry, adding ~14 seconds to guest boot.

Now check whether the home dir is already owned by the sandbox user
and, if so, only walk the .ssh/ subtree to enforce strict SSH
permissions. The full recursive chown is preserved as a fallback for
platforms without user namespaces (e.g. macOS).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@JAORMX JAORMX merged commit bef1230 into main Apr 7, 2026
7 checks passed
@JAORMX JAORMX deleted the jaosorior/skip-home-chown branch April 7, 2026 06:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant