8000 crates/sandbox2: support MINIMAL_INTERNAL_PATCH_STRIP setting by twitchyliquid64 · Pull Request #166 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content

crates/sandbox2: support MINIMAL_INTERNAL_PATCH_STRIP setting - #166

Merged
twitchyliquid64 merged 1 commit into
mainfrom
tom/fix-upstream
Apr 27, 2026
Merged

twitchyliquid64 merged 1 commit into
mainfrom
tom/fix-upstream

Conversation

@twitchyliquid64
@twitchyliquid64 twitchyliquid64 commented Apr 27, 2026 •
Copy link
Copy Markdown
Contributor

Adds internal env-var MINIMAL_INTERNAL_PATCH_STRIP, so minimal-entry in the mac orchestration code can set MINIMAL_INTERNAL_PATCH_STRIP=/host and end up with identical paths in the minimal sandbox.

Summary by CodeRabbit

  • Bug Fixes
    • Improved sandbox path handling with conditional prefix transformations based on environment configuration
    • Enhanced working directory and bind-mount management in sandboxed environments for proper path resolution

@twitchyliquid64
twitchyliquid64 requested a review from msample April 27, 2026 20:08
@coderabbitai
coderabbitai Bot commented Apr 27, 2026 •
Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes introduce a conditional path transformation mechanism using the MINIMAL_INTERNAL_PATCH_STRIP environment variable. A new helper method computes sandbox-relative working directory paths, and sandbox initialization and mounting logic now consistently use this helper instead of raw path values.

Changes

Cohort / File(s) Summary
Path Transformation & Working Directory Helper
crates/common/src/lib.rs, crates/sandbox2/src/config.rs
Adds conditional prefix stripping in path_in_sandbox based on MINIMAL_INTERNAL_PATCH_STRIP environment variable, and introduces bound_dir_sandbox_cwd() helper method to compute normalized sandbox-relative cwd paths with prefix stripping and / normalization.
Sandbox Initialization & Mount Configuration
crates/sandbox2/src/lib.rs
Updates WdSetup::BoundDir handling in sandbox initialization and mounting to use the new bound_dir_sandbox_cwd() helper for rootfs directory creation, filesystem mapping targets, container cwd configuration, and bindmount destinations.

Sequence Diagram

sequenceDiagram
    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
Loading

Estimated Code Review Effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested Reviewers

  • msample
  • bryan-minimal

Poem

🐰 A path stripped bare, a cwd made clean,
Environment whispers what paths should mean,
From common to config, to init it flows,
Sandbox-bound directories in orderly rows! 🏠

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: adding support for the MINIMAL_INTERNAL_PATCH_STRIP environment variable in the sandbox2 crate, which is the primary objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tom/fix-upstream

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

🧹 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 for unsafe code invariants. For documenting panic conditions in safe Rust, the idiomatic convention is # Panics in doc comments.

Also, the panic message says "sandbox_cwd called..." but the function is named bound_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

📥 Commits

Reviewing files that changed from the base of the PR and between 00660fb and 3204901.

📒 Files selected for processing (3)
  • crates/common/src/lib.rs
  • crates/sandbox2/src/config.rs
  • crates/sandbox2/src/lib.rs

@msample msample left a comment
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@twitchyliquid64
twitchyliquid64 merged commit 30572f7 into main Apr 27, 2026
8 checks passed
@twitchyliquid64
twitchyliquid64 deleted the tom/fix-upstream branch April 27, 2026 20:20
agent-137 pushed a commit that referenced this pull request Nov 9, 2026
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
yermakoffivan pushed a commit to yermakoffivan 8000 /minimal that referenced this pull request Nov 10, 2026
…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>
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.

2 participants

0