Repository navigation
Fixed a bug where nested sandboxes would fail if we tried to mount a file with a flag locked by the outer sandbox but not the inner - #208
Conversation
📝 WalkthroughWalkthroughAdds the nix crate and a MountError variant, implements locked_mount_flags(path) using nix::statfs, centralizes bind-mount logic in Sandbox::bind_mount, refactors /state, /run, working-directory and filesystem mappings to use it, and maps the new error into mctx. ChangesSandbox Mount Flag Locking
Sequence Diagram(s)sequenceDiagram
participant Sandbox
participant locked_mount_flags
participant nix_statfs
participant MountOptions
Sandbox->>locked_mount_flags: locked_mount_flags(path)
locked_mount_flags->>nix_statfs: statfs(path)
alt statfs succeeds
nix_statfs-->>locked_mount_flags: stat result (ST_*)
locked_mount_flags->>MountOptions: map ST_* -> MountOptions
MountOptions-->>locked_mount_flags: options
else statfs fails
nix_statfs-->>locked_mount_flags: error
locked_mount_flags->>MountOptions: return empty options
MountOptions-->>locked_mount_flags: options
end
locked_mount_flags-->>Sandbox: MountOptions
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/sandbox2/src/lib.rs`:
- Line 392: The code currently calls build_path.to_str().unwrap() (and the other
to_str().unwrap() at the later occurrence), which can panic on non-UTF-8 paths;
change both sites to handle non-UTF-8 by returning an ExecutionError::MountError
(the same style used by bind_mount()) instead of unwrapping. Locate the
occurrences referencing build_path (and the second path variable) in
crates/sandbox2/src/lib.rs and replace the unwrap with a
to_str().ok_or_else(...) or equivalent that returns
Err(ExecutionError::MountError{ ... }) with the offending path and an
explanatory source message so the function returns an error rather than
panicking. Ensure the returned error shape and messaging match bind_mount's
MountError usage.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 468d382d-70a5-45b6-b0ee-dc03f25a63cf
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (5)
Cargo.tomlcrates/mctx/src/error.rscrates/sandbox2/Cargo.tomlcrates/sandbox2/src/error.rscrates/sandbox2/src/lib.rs
…file with a flag locked by the outer sandbox but not the inner
379fee3 to
0cb074f
Compare
If you try to do something like:
The second entry in the sandbox will fail with an error like:
This is because Linux requires that any locked mount flags are preserved in the new sandbox. We weren't preserving them so it fails. This PR changes the way we're mounting them to always preserve locked flags.
Note that
Runctl::Mountfallbackis not a good solution here because it just falls back to only specifying the flags that the file currently has and not the flags that we have specified.Summary by CodeRabbit
Bug Fixes
Chores
Tests