Skip to content

Add Linux Bubblewrap sandbox#22240

Merged
MikeMcQuaid merged 1 commit into
mainfrom
linux-bubblewrap-sandbox
May 16, 2026
Merged

Add Linux Bubblewrap sandbox#22240
MikeMcQuaid merged 1 commit into
mainfrom
linux-bubblewrap-sandbox

Conversation

@MikeMcQuaid

Copy link
Copy Markdown
Member
  • Use bwrap to translate shared sandbox rules into rootless namespace execution.
  • Gate the backend behind HOMEBREW_SANDBOX_LINUX while the Linux policy is still experimental.
  • Reuse preinstall diagnostics to tell opt-in users when bubblewrap is missing.
  • Install bubblewrap in Linux CI and Docker images so test-bot exercises the sandbox path.

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them? Performance claims (e.g. "this is faster") must include Hyperfine benchmarks.
  • Have you written new tests (excluding integration tests) for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

  • AI was used to generate or assist with generating this PR. Please specify below how you used AI to help you, and what steps you have taken to manually verify the changes. Non-maintainers may only have one AI-assisted/generated PR open at a time.

OpenAI Codex 5.5 xhigh with manual review, (unit not Linux) testing and tweaking.


Base automatically changed from move-macos-sandbox-logic to main May 12, 2026 10:28
@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch from 3737dfa to dfdf12d Compare May 12, 2026 15:04

@p-linnane p-linnane 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.

Love it!!!

@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch from dfdf12d to ca8620d Compare May 12, 2026 16:18
Copilot AI review requested due to automatic review settings May 12, 2026 16:18

Copilot AI 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.

Pull request overview

This PR introduces an experimental Linux sandbox backend for Homebrew’s Sandbox using Bubblewrap (bwrap), gated behind HOMEBREW_SANDBOX_LINUX so Linux sandboxing can be exercised in CI without becoming the default.

Changes:

  • Add a Linux Sandbox implementation backed by Bubblewrap with an availability probe and rule translation to bind/ro-bind mounts.
  • Add HOMEBREW_SANDBOX_LINUX env config (and Sorbet RBI) to opt into the Linux sandbox path.
  • Enable/install Bubblewrap in Linux CI and Docker images, and add Linux-focused sandbox unit tests.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Library/Homebrew/extend/os/linux/sandbox.rb Implements Bubblewrap-backed Linux sandboxing and availability checks.
Library/Homebrew/extend/os/sandbox.rb Loads the Linux sandbox extension on Linux.
Library/Homebrew/env_config.rb Adds HOMEBREW_SANDBOX_LINUX boolean env configuration.
Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi Adds Sorbet signature for sandbox_linux?.
Library/Homebrew/test/sandbox_linux_spec.rb Adds unit tests for Linux sandbox availability and bwrap arg generation (plus basic run behavior).
Dockerfile Installs bubblewrap in the Homebrew Docker image.
.github/workflows/tests.yml Enables Linux sandboxing in CI and ensures bubblewrap is installed where needed.
Files not reviewed (1)
  • Library/Homebrew/sorbet/rbi/dsl/homebrew/env_config.rbi: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread Library/Homebrew/extend/os/linux/sandbox.rb Outdated
@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch 19 times, most recently from 5badcf8 to 4da60dc Compare May 14, 2026 16:12
@p-linnane p-linnane force-pushed the linux-bubblewrap-sandbox branch from 4da60dc to 00ee4c6 Compare May 14, 2026 23:27
@alebcay

alebcay commented May 15, 2026

Copy link
Copy Markdown
Member

Just wanted to say I'm stoked to see this. I've tried making a similar change/feature several times now but never got it workable enough to ship.

@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch 2 times, most recently from 4359a34 to 6236de9 Compare May 15, 2026 15:09
@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch 9 times, most recently from 41a5a05 to 33df5d7 Compare May 16, 2026 12:54

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

This is great, thank you!

@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch 2 times, most recently from 8cf9c3b to 0e08bc1 Compare May 16, 2026 14:48
- Use `bwrap` to translate shared sandbox rules into rootless
  namespace execution.
- Gate the backend behind `HOMEBREW_SANDBOX_LINUX` while the Linux
  policy is still experimental.
- Keep macOS on its existing `sandbox-exec` path while Linux uses shared
  executable lookup for `bwrap`.
- Auto-install `bubblewrap` from `homebrew/core` when the sandbox is
  enabled and no system or usable brewed binary is found.
- Prefer a usable system `bwrap` from `ORIGINAL_PATHS` over a brewed
  one so distribution-provided binaries are used when available.
- Find brewed `bwrap` from `HOMEBREW_ORIGINAL_BREW_FILE` so integration
  subprocesses still use the Linux sandbox.
- Preserve `Sandbox#run`'s tmpdir cwd inside the `bwrap` namespace and
  suppress Linux PTY thread warnings after sandboxed children exit.
- Expose formula, Homebrew library and Linux runtime paths as read-only
  binds so sandboxed source builds can run with vendored Ruby.
- Keep synthetic test formula installs off the API so sandbox CI does
  not require network during local formula setup.
- Avoid creating optional prefix `var` directories just to configure a
  test sandbox and remove empty Linux bind placeholders after runs.
- Require a working rootless `bwrap` on GitHub Actions and install the
  system `bubblewrap` package before Linux tests run.
@MikeMcQuaid MikeMcQuaid force-pushed the linux-bubblewrap-sandbox branch from 0e08bc1 to 936f0b2 Compare May 16, 2026 15:27
@MikeMcQuaid MikeMcQuaid enabled auto-merge May 16, 2026 15:46
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue May 16, 2026
Merged via the queue into main with commit e8c9c18 May 16, 2026
38 of 39 checks passed
@MikeMcQuaid MikeMcQuaid deleted the linux-bubblewrap-sandbox branch May 16, 2026 16:13
Comment thread Library/Homebrew/build.rb
Comment on lines +263 to +266
formula_path = ARGV.first
# `build.rb` is handed a concrete formula file; keep reparsing from falling
# back to the API inside the Linux sandbox.
ENV["HOMEBREW_NO_INSTALL_FROM_API"] = "1" if formula_path&.end_with?(".rb")

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.

This might be causing #22306.

@lina-bh

lina-bh commented Jun 11, 2026

Copy link
Copy Markdown

This is great news. Sorry I never got around to working on this one.

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.

7 participants