Reusable bubblewrap sandbox helpers for shell wrappers. Each function takes an array variable name and appends bwrap arguments to it via nameref.
gitpkg install bwrap-commonyay -S bwrap-common
make build
sudo make installmake install installs the seccomp helper and the architecture-specific default
filter built by make build, so gcc and the libseccomp headers are required
before installing.
sudo make uninstallSource with verify-lib to validate ownership and permissions before loading:
#!/usr/bin/env bash
set -euo pipefail
_src() { local p; p=$(verify-lib "$1" "$2") && . "$p" || exit 1; }
_src /usr/lib/bwrap-common/bwrap-common.sh /usr/lib/bwrap-common/Or source directly:
. /usr/lib/bwrap-common/bwrap-common.shTypical GUI wrapper using high-level composites:
A=()
bwrap_gui_setup A yes yes tmpfs # network, gpu, shm=tmpfs
bwrap_bind_dir A "${HOME}/.config/app" "${HOME}/Data"
bwrap_ro_bind_dir A "${MEDIA_DIR}"
bwrap_audio A
bwrap_gui_finish A wayland yes default filtered yes default # display, network, malloc, dbus, themes, seccomp
bwrap_exec "${A[@]}" -- /usr/bin/app "$@"Equivalent using low-level helpers:
A=()
bwrap_base A tmpfs # shm=tmpfs; use "bind" only if needed
bwrap_lib64 A
bwrap_gpu A
bwrap_resolv A
bwrap_runtime_dir A
bwrap_home_tmpfs A
bwrap_bind_dir A "${HOME}/.config/app" "${HOME}/Data"
bwrap_ro_bind_dir A "${MEDIA_DIR}"
bwrap_themes A
bwrap_wayland A
bwrap_audio A
bwrap_dbus_common A
bwrap_env_base A
bwrap_hardened_malloc A default
bwrap_seccomp A default
bwrap_sandbox A yes
bwrap_exec "${A[@]}" -- /usr/bin/app "$@"| Variable | Default |
|---|---|
BWRAP_SECCOMP_DIR |
/usr/lib/bwrap-common/seccomp |
BWRAP_SECCOMP_GEN |
/usr/lib/bwrap-common/bwrap-seccomp-gen |
BWRAP_SECCOMP_CACHE_DIR |
${XDG_CACHE_HOME:-$HOME/.cache}/bwrap-common/seccomp |
BWRAP_SECCOMP_ARCH |
overrides uname -m for the default blob (cross-arch tests) |
The allowlist cache key is
sha256("bwrap-common-seccomp-v2\n<arch>\n<spec>\n"); cached files are mode
0600.
| Path | Purpose |
|---|---|
/usr/lib/bwrap-common/bwrap-common.sh |
Library |
/usr/lib/bwrap-common/bwrap-seccomp-gen |
Allowlist compiler |
/usr/lib/bwrap-common/seccomp/default.<arch>.bpf |
Precompiled default blocklist |
seccomp/default.conf |
Default blocklist source |
-
bubblewrap(bwrap) -
bash -
libseccomp(runtime, for the seccomp helper) -
gcc+libseccompheaders (build-time, formake build) -
verify-lib (recommended, for integrity verification before sourcing)
-
xdg-dbus-proxy(required for the defaultfilteredD-Bus mode; optional withdbus=none/unfiltered) -
hardened_malloc (required by default; opt out with
malloc=noif it is not installed)
AGPL-3.0-or-later