MuonTrap provides resource limits (cgroups), but not filesystem or network isolation. To achieve true sandboxing (e.g., for browsers or untrusted code), layer bubblewrap (bwrap) under MuonTrap. MuonTrap manages the lifecycle and resource caps, while bwrap manages namespaces and isolation.
Recommended flags for bwrap:
--unshare-all: Provides fresh namespaces (PID, network, etc.).--die-with-parent: Ensures the sandbox dies if MuonTrap dies.--ro-bind / --bind: Controls filesystem visibility.
{MuonTrap.Daemon,
["bwrap",
[
"--ro-bind", "/usr", "/usr",
"--ro-bind", "/lib", "/lib",
"--ro-bind", "/lib64", "/lib64",
"--proc", "/proc",
"--dev", "/dev",
"--bind", "/tmp/browser-home", "/home/browser",
"--unshare-all",
"--die-with-parent",
"--",
"/usr/bin/my-browser"
],
[
cgroup_base: "mycgroup",
cgroup: %{
memory_max: 536_870_912,
memory_oom_group: true,
cpu_max: {50_000, 100_000},
pids_max: 200
}
]
]}