Skip to content

Replace bubblewrap with unshare + chroot - #2

Merged
kernc merged 62 commits into
masterfrom
unshare
Jul 21, 2026
Merged

Replace bubblewrap with unshare + chroot#2
kernc merged 62 commits into
masterfrom
unshare

Conversation

@kernc

@kernc kernc commented Mar 9, 2026

Copy link
Copy Markdown
Member

Reimplementation based on unshare from util-linux package. Drops bwrap as a dependency.

@kernc
kernc force-pushed the unshare branch 14 times, most recently from 2523e48 to 281d5c3 Compare March 9, 2026 17:17
@keturn

keturn commented Mar 10, 2026

Copy link
Copy Markdown

I just stumbled across sandbox-run and it looks quite useful!

Of course, running random scripts off GitHub can be as much a problem as running scary-binary itself, so I was happy to find the source is short and straightforward use of bwrap.

The implementation in this PR makes for a different first impression.

It's still very good for shell code, backed by rigorous application of shellcheck and a test suite. I just can't help but ask: what did bubblewrap do wrong that made you decide you'd rather maintain hundreds of lines of shell script?

@kernc
kernc force-pushed the unshare branch 3 times, most recently from 8923c51 to ad9c6a9 Compare March 10, 2026 21:24
@kernc

kernc commented Mar 10, 2026

Copy link
Copy Markdown
Member Author

@keturn Hey! Thanks for the kind words. Indeed, the recent proliferation of installation steps comprising curl ... | bash has led me to figuring this out. Bubblewrap works and I'm happy with it so far.

Then somebody hinted at unshare. I figured I would only need a few more lines to achieve filesystem isolation, and I'd be all set! Well, this is what came out. 😅 It's now hefty 500-ish lines (~100 lines went for seccomp syscalls enumeration), but consider these are mere 500 lines of POSIX Linux Shell that replicate now nearly the whole of Bubblewrap (and, with support for its config profiles*, Firejail as well). That is with no extra dependencies (util-linux and mount are preassumed) and without a build step or the associated machinery. 🤷

Considering the two versions functionally equivalent (a huge assumption as I'm a real kernel noob), I now like this one somewhat better. But you too are right, as the length and ordering of the commit log in this PR confirms, shell certainly is full of biting gremlins.

I thought of putting the old version in a branch/tag, but your unexpected comment raises legitimate questions whether the two versions can be maintained side by side ...

The implementation in this PR makes for a different first impression.

Would appreciate a more thorough review! 😝


* New additional features in this PR:

  • support for Firejail profiles,
  • non-shared network namespace,
  • seccomp filtering active by default.

@kernc
kernc force-pushed the unshare branch 3 times, most recently from 395b1e6 to 247c5de Compare July 21, 2026 19:44
kernc added 9 commits July 21, 2026 21:57
* Use ready/exit fd-s
* Keep API socket _outside_ the sandbox
…t dupe on rbind"

This reverts commit edc74c7.
The reason is it broke tests/test_symlinks.sh. 🤷
... so its sub-mounts (e.g. $ROOT/dev) don't dupe on rbind

Refs: edc74c7
(and its reversal ...)
Refs: 28a961544088201336d4a5550ad0ad6b648e92a2
The spec on `set -e` reads:

> When this option is on, when any command fails ...,
> the shell immediately shall exit ..., with the following exceptions:
> 1. ...
> 2. The **-e setting shall be ignored** when executing the compound
>    list following the while, ..., a pipeline **beginning with the
>    ! reserved word**, or any command of an AND-OR list
>    other than the last.
> 3. If the exit status of a compound command
>    other than a subshell command was the result of a failure while
>    -e was being ignored, then -e shall not apply to this command.
It can be a security issue.

Also not permitted on CI.
@kernc

kernc commented Jul 21, 2026

Copy link
Copy Markdown
Member Author

@keturn
Agreed, a small wrapper is easy to parse in a minute, but mere 3.5-times as many lines still isn't too long for my taste, and let me assure you, while I do take help of AI, none of this is vibe-coded. And severe feature creep is not expected. Above all, it's still only ~500 lines of simple shell that completely avoids Bubblewrap and, for what that's worth, the whole pervasive "IBM crowd" (other than through Linux mainline).

Many software packages, aforementioned included, spend that much on build configuration alone. Whereas this one is supposed to work out of the box.

Again sincere thanks for the early feedback. Obviously, you're free to use any sandboxing tool that you grasp and trust.

@kernc
kernc merged commit 2810621 into master Jul 21, 2026
2 checks passed
@kernc
kernc deleted the unshare branch September 2, 2026 09:25
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