Repository navigation
crates/sandbox2: support MINIMAL_INTERNAL_PATCH_STRIP setting - #166
Conversation
📝 WalkthroughWalkthroughThe changes introduce a conditional path transformation mechanism using the Changes
Sequence DiagramsequenceDiagram
participant Env as Environment<br/>(MINIMAL_INTERNAL_PATCH_STRIP)
participant FsMap as FsMapping<br/>(path_in_sandbox)
participant Config as WdSetup<br/>(config.rs)
participant Init as Sandbox Init<br/>(lib.rs)
Init->>Config: bound_dir_sandbox_cwd()
Config->>Env: Check env variable
Config->>FsMap: Conditional prefix strip
FsMap->>Config: Transformed/original path
Config->>Config: Normalize (remove /)
Config->>Init: Sandbox-relative cwd
Init->>Init: Create rootfs dir
Init->>Init: Update mount destinations
Init->>Init: Configure container cwd
Estimated Code Review Effort🎯 3 (Moderate) | ⏱️ ~20 minutes 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
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/sandbox2/src/config.rs (1)
63-85: Consider using standard Rust doc conventions for the panic condition.The
SAFETY:annotation is conventionally used forunsafecode invariants. For documenting panic conditions in safe Rust, the idiomatic convention is# Panicsin doc comments.Also, the panic message says
"sandbox_cwd called..."but the function is namedbound_dir_sandbox_cwd– minor inconsistency.📝 Suggested doc improvement
impl WdSetup { - /// Returns the path within the sandbox of the cwd. The returned path - /// is always relative. - /// - /// SAFETY: - /// * This function will panic if the variant is not `BoundDir`. + /// Returns the path within the sandbox of the cwd. The returned path + /// is always relative. + /// + /// # Panics + /// + /// Panics if `self` is not the `BoundDir` variant. pub(crate) fn bound_dir_sandbox_cwd(&self) -> &Path { let p = match self { Self::BoundDir { path, .. } => match std::env::var("MINIMAL_INTERNAL_PATCH_STRIP") { Err(_) => path, Ok(prefix) => match path.strip_prefix(&prefix) { Err(_) => path, Ok(stripped) => stripped, }, }, - _ => panic!("sandbox_cwd called for non bound-dir variant {:?}", self), + _ => panic!("bound_dir_sandbox_cwd called for non-BoundDir variant {:?}", self), };🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/sandbox2/src/config.rs` around lines 63 - 85, Update the doc comment for WdSetup::bound_dir_sandbox_cwd to use Rust's standard "# Panics" section instead of the "SAFETY:" label and describe the panic condition there; also fix the panic message string inside bound_dir_sandbox_cwd (currently "sandbox_cwd called for non bound-dir variant ...") to reference the correct function name "bound_dir_sandbox_cwd" so the message matches the method. Ensure the doc comment remains /// style and clearly states that the function will panic if the enum variant is not BoundDir.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/sandbox2/src/config.rs`:
- Around line 63-85: Update the doc comment for WdSetup::bound_dir_sandbox_cwd
to use Rust's standard "# Panics" section instead of the "SAFETY:" label and
describe the panic condition there; also fix the panic message string inside
bound_dir_sandbox_cwd (currently "sandbox_cwd called for non bound-dir variant
...") to reference the correct function name "bound_dir_sandbox_cwd" so the
message matches the method. Ensure the doc comment remains /// style and clearly
states that the function will panic if the enum variant is not BoundDir.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 4f8425c8-8d0a-4057-ad8f-dcfb6f10fc53
📒 Files selected for processing (3)
crates/common/src/lib.rscrates/sandbox2/src/config.rscrates/sandbox2/src/lib.rs
gominimal/arch@9495216 (#166) gives the command-line override layer its own rules, which BOX-064's union-and-replace rule cannot give. An override changes only the [network] key it names. A list override adds, but allow_protocols replaces. Deny-all-egress empties allow_dns_hosts and allow_subnets, and no-hooks empties lifecycle_hooks. Add them as BOX-064 sub-bullets, and restate the T1 property to fold those rules in last. Refs #3200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA
…o spec 29 (gominimal#3177) * docs(specs): add restart and hook declarer to spec 29 Add BOX-176 to BOX-178: a client can restart a box whose spec sets lifetime = "until_stopped". The restart stops the box as a stop does, then starts it from its stored spec and retained filesystem under the same id and name. It takes a resume's refusals and hooks, and records the existing exited and started events. Owner decision on gominimal#2761. Add BOX-179: each lifecycle hook in the expanded spec carries a declared_by table (a loadout's name, or the project with no host path). Owner decision on gominimal#2877. Refs gominimal#2761, gominimal#2877. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): give BOX-064 the command-line layer's merge rule gominimal/arch@9495216 (gominimal#166) gives the command-line override layer its own rules, which BOX-064's union-and-replace rule cannot give. An override changes only the [network] key it names. A list override adds, but allow_protocols replaces. Deny-all-egress empties allow_dns_hosts and allow_subnets, and no-hooks empties lifecycle_hooks. Add them as BOX-064 sub-bullets, and restate the T1 property to fold those rules in last. Refs gominimal#3200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): return each live exec's argv and PTY flag in BOX-159 BCLI-067's min box show lists each live exec's id, argv and whether it holds a PTY. BOX-159 returned only the id. Return all three, the fields BOX-152's exec_started event records, so one read answers the show. Owner decision on gominimal#3205. Refs gominimal#3205. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): settle the review findings on the spec 29 amendments - BOX-176: a restart takes BOX-025's name, spec and volume refusals but never BOX-030's PTY check, which would refuse the non-PTY until_stopped box a restart exists for. - BOX-178: a restart also records exec_exited for each exec its stop ends (BOX-152). It records no event type of its own. - BOX-159: return each live exec's mode (tty, detached or attached) rather than a PTY flag, which cannot tell detached from attached. The reasoning says the argv shows no reader what the exec_started event does not. - BOX-064: deny-all-egress applies after the layer's other overrides. - BOX-179: every layer of the project's minimal.toml declares as the project, with one table per declaration. The reasoning says why [upstream] and built-in types declare no hooks. Refs gominimal#2761, gominimal#2877, gominimal#3200, gominimal#3205. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): deny-all-egress empties every allow list and refuses others The owner ruled that NET-140 is right: deny-all-egress empties every allow list in egress, allow_protocols included (gominimal/arch#173 corrects the architecture). With another egress allow or deny override in the same layer, the expansion is refused with exit 2, as NET-140 and min session activate --help say, rather than ordered after it. Refs gominimal#3200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): check a restart's refusals before it stops a running box BOX-176's refusals covered only a stopped or exited box. A restart of a running box stops it first, so a failed spec or volume check would leave it stopped. The refusals now apply to every restart, all before the restart stops any process, so a refused restart leaves a running box running. A running box's own name does not trip the name check. BOX-159's mode is the one mode the exec was started in. A PTY exec with no client attached now is still tty, and no exec has two modes. Refs gominimal#2761, gominimal#3205. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): let a restart pass a running box's own volume holds A running box holds its own volumes, so BVOL-013's volume-hold check would refuse the box's own restart before it stopped anything. As with the name check, the box's own holds do not trip it. Refs gominimal#2761. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): give egress.allow_protocols one command-line rule BOX-064's first command-line sub-bullet added an override's values to every list key, and the next replaced egress.allow_protocols. Both applied to that key. The add rule now excepts it, so the tests and the T1 property have one answer. Refs gominimal#3200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA * docs(specs): settle the last review round on the spec 29 amendments - BOX-064: every command-line override applies, each to the key it names, and a [network] key no override names keeps its expanded value. - BOX-064: the deny-all conflict refusal names both overrides and says to drop one. - BOX-176: a restart whose start fails after its stop leaves the box stopped with the stop's exited event (BOX-013), records no started event, and fails with the start's error. Refs gominimal#2761, gominimal#3200. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016CYvTvep9ZaSf5pJMB2hQA --------- Co-authored-by: Karl Godard <karl@minimal.dev> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Adds internal env-var
MINIMAL_INTERNAL_PATCH_STRIP, sominimal-entryin the mac orchestration code can setMINIMAL_INTERNAL_PATCH_STRIP=/hostand end up with identical paths in the minimal sandbox.Summary by CodeRabbit