macOS 上用 sandbox-exec 隔離

上上禮拜看到「sandbox-exec: macOS's Little-Known Command-Line Sandboxing Tool (via)」這個感到興趣,主要是因為有跑 coding agent 的需求,在 Linux 上可以透過 bubblewrap 隔離 (參考「Linux 下用 bubblewrap (bwrap) 跑 Claude Code」),但 macOS 上沒有 bubblewrap,所以需要另外找工具,看起來就是這個了。 Hacker News 上有人提到 deprecated 的問題,從 2017 年就已經是 deprecated 了...

Gea-Suan Lin's BLOG
Linux 下用 bubblewrap (bwrap) 跑 Claude Code

避免 Claude Code 在全自動模式下 (--dangerously-skip-permissions) 爆炸的時候把一堆東西給弄炸,一般會用 container 環境包起來,不過在 Linux 下可以用 bubblewrap 這樣更清量的工具限制,調整了一陣子,算是穩下來了,我會包一個 ~/bin/claude...

Gea-Suan Lin's BLOG

Hardening with Firejail, Landlock, and bubblewrap

Recently I've been looking into securing my laptop a bit. By default, every single program has access to everything: filesystem, network, other programs.

First, I started looking into Firejail. It allows specifying paths the program can access, as well as the network and other special things. It's not bad and I used it for a while.

What I don't like about Firejail is that it's setuid: it runs as root, sets up the sandbox, then starts the program that is passed as an argument. If there is a problem in Firejail then it can even extend the blast radius.

Then I learned about Landlock. It is unprivileged and also allows restricting the network. At some point I found a [CLI](https://github.com/Zouuup/landrun) that makes it easy to run. Landlock solves the privilege problem: it restricts the process without having more permissions to do so.

The problem with Landlock is its fs restrictions are a bit too coarse: if a directory is allowed then everything below it is also allowed. For example, giving read access to $HOME also gives read access to the chromium profile.

Now I'm looking into bubblewrap. It promises to combine Firejail and Landlock in the best way: unprivileged and also allows layering filesystem access.

I'm still working on moving my dotfiles to bubblewrap and it takes some mental energy to do that. But is seems like it's going to be a good next step.

#security #linux #bwrap #landlock #firejail

Originally published [on my blog](https://advancedweb.hu/shorts/hardening-with-firejail-landlock-and-bubblewrap/)

GitHub - Zouuup/landrun: Run any Linux process in a secure, unprivileged sandbox using Landlock. Think firejail, but lightweight, user-friendly, and baked into the kernel.

Run any Linux process in a secure, unprivileged sandbox using Landlock. Think firejail, but lightweight, user-friendly, and baked into the kernel. - Zouuup/landrun

GitHub

用 bubblewrap (bwrap) 針對特定程式抽換 /etc/resolv.conf

我家裡的桌機有兩個有線網路,一個是 HiNet 光世代,另外一個是社區網路 (其實出去也是光世代),像是這篇提到的架構 (只是當時還住在後山埤,另外那條是北都的第四台網路):「Ubuntu 下面搞 Multi-home 架構」。

我在上面那篇提到要怎麼以 source ip addre

https://blog.gslin.org/archives/2023/11/27/11482/%e7%94%a8-bubblewrap-bwrap-%e9%87%9d%e5%b0%8d%e7%89%b9%e5%ae%9a%e7%a8%8b%e5%bc%8f%e6%8a%bd%e6%8f%9b-etc-resolv-conf/

#Computer #DNS #Murmuring #Network #Service #Software #bubblewrap #bwrap #dns #microsocks #proxy #resolvconf

用 bubblewrap (bwrap) 針對特定程式抽換 /etc/resolv.conf

我家裡的桌機有兩個有線網路,一個是 HiNet 光世代,另外一個是社區網路 (其實出去也是光世代),像是這篇提到的架構 (只是當時還住在後山埤,另外那條是北都的第四台網路):「Ubuntu 下面搞 Multi-home 架構」。 我在上面那篇提...

Gea-Suan Lin's BLOG
Slight evening tuning. Configuring Session App Desktop AppImage to run with Bwrap (bubblewrap) containment. So much joy. Now it works. #session_app #bwrap #appimage
Akkoma

Here is the zip file trick combined with `bwrap`.

This single-file script allows you to run a command within a mutable/auto-updating mount namespace.

A filesystem in a script.

Code: https://gist.github.com/dutc/759816c8ceb7ab840572f1084c2d7356

#programming #zsh #bwrap #shell #scripting

Combining `bwrap` and the `.zip` trick for auto-concatenating single-file distributables

Combining `bwrap` and the `.zip` trick for auto-concatenating single-file distributables - git-vault.zsh

Gist

@technoprenerd Thanks for the read!

It'll be interesting to see how this ties into the ecosystem overall. The strongest component of the project seems to be the hardened/trimmed #kernel.

Perhaps #GPT could even aid in development of #bwrap / #apparmor profiling.

I did need to make the real-bwrap call an exec, otherwise the seccomp filehandle isn't inherited.

#linux #debian #bwrap #thumbnail

Fuffing around with this #bwrap wrapper just to get my #Nautilus thumbnail helpers working again on #Debian. It seems to work! http://www.bernaerts-nicolas.fr/linux/74-ubuntu/360-ubuntu-nautilus-external-thumbnailer-failure