| Name | Modified | Size | Downloads / Week |
|---|---|---|---|
| README.md | 2026-11-22 | 12.3 kB | |
| vibe-chroot | 2026-11-22 | 26.5 kB | |
| Totals: 2 Items | 38.8 kB | 7 |
vibe-chroot
Run host software, as your normal user, inside a chroot whose /home
contains only the paths you choose — a "limited mirror" of your home
directory. Everything else in the sandbox is the host: the same binaries,
libraries, config, devices and services, bind-mounted in place.
Think of it as "a normal shell, except /home is a window you control."
vibe-chroot <target_chroot_directory> <mirrored_directory_list_file>
Inspired by /usr/bin/arch-chroot from the Arch Linux arch-install-scripts
package (upstream: https://gitlab.archlinux.org/archlinux/arch-install-scripts).
The differences from it are deliberate and
listed below.
What it does
- Validates the arguments and the mirror list, and captures your current
environment — all as your user, no privileges. It also pre-creates the
whole mountpoint skeleton as your user, so the leftovers you will see
after the session are always
rm -rf-able without root. - Asks for one short root session via
su(root password,sudois deliberately not used). That root session: - sweeps any stale mounts a previously crashed session left under the target (and repairs skeleton ownership if a past run left it root-owned),
- refuses to proceed if the target contains anything that is not a previously left skeleton,
- seals the target (
--make-private) and mounts: freshproc/sys(+efivarfs), host/dev(rbind — real devices and udev permissions), host/run, a freshtmpfs/tmp, - bind-mounts every other top-level host directory (
/boot,/etc,/usr,/var, …) or recreates its symlinks — so all host software keeps working, - bind-mounts the entries from your list into
/home/<you>, - hands back an interactive login shell to you (via
su -P, so the shell gets a real pseudo-terminal and job control works), with your environment restored. - When you leave the shell (or interrupt it, or it crashes), the same root session unmounts everything it mounted and cleans up its temporary files. The empty skeleton directory tree is left in place for you.
The tool never deletes user data: a target directory containing anything it does not recognize is refused, not wiped.
Requirements
- modern Linux (bash ≥ 4.4, GNU coreutils, util-linux
su(with-P/--ptysupport)/chroot/mount/umount/findmnt/flock, GNU findutils) - a working
suto root — i.e. a root password (if your distro locked root, set a root password first; this tool will not usesudo) - an interactive terminal (the session is TTY-based)
Quickstart
Pick the few things from your home the sandbox should contain, one per line
(relative to $HOME, files or directories):
# ~/vibe.list
.bash_profile
.bashrc
.Xauthority
.asoundrc
config
projects/web
notes/todo.md
vibe-chroot ~/vibe-chroot-root ~/vibe.list
You are asked for the root password once, then you are in:
$ pwd
/home/<you>
$ ls
bash_profile bashrc Xauthority asoundrc config projects notes
$ gcc hello.c && ./a.out # host toolchain, host devices, host DNS…
$ exit
# == > removed 20 mount(s) under /home/<you>/vibe-chroot-root
# == > session ended — all mounts under … were removed
cd back out to the host and rm -rf ~/vibe-chroot-root whenever you are
done with the skeleton.
List file format
One entry per line; blank lines and # comments are ignored.
| Rule | Detail |
|---|---|
| base | paths are relative to $HOME — no absolute paths |
| kinds | regular files and directories (symlink targets must stay inside $HOME) |
| structure | preserved: projects/web → /home/<you>/projects/web |
| nesting | allowed; a child entry is mounted on top of its parent entry |
| duplicates | warned about, ignored |
. / the whole home |
refused (the point of the tool is a limited mirror) |
.. escapes |
refused |
| missing / not file-or-dir | hard error with the line number |
What you see inside the chroot
| Path | Source | Notes |
|---|---|---|
/proc |
fresh procfs | host PID space (same as arch-chroot), nosuid,noexec,nodev |
/sys |
fresh sysfs | read-only |
/sys/firmware/efi/efivars |
fresh efivarfs | only if the host has it |
/dev |
rbind of host /dev |
real devices incl. /dev/pts, /dev/shm; host udev permissions; the copies are made private |
/run |
rbind of host /run |
/run/user/<uid> (your session bus), udev, systemd sockets; the copies are made private |
/tmp |
fresh tmpfs | 1777, private to the session |
/bin /lib /lib64 /sbin … |
host symlinks recreated | merged-usr layouts handled naturally |
/boot /etc /mnt /opt /root /srv /usr /var + anything else at / |
rbind | full host rootfs ⇒ all host software works; each copy made private |
/home/<you> |
fresh empty dir | only your listed entries appear inside |
/home/<anyone-else> |
absent | other users' homes are simply not there |
"Private" copies, explained: a bind/rbind of a host mount joins the
host's mount peer group if the host mount is shared (on a systemd host:
/run, /run/user/<uid>, /dev/pts, /dev/shm are shared). Unmounting a
peer-group member propagates the unmount into the host — i.e. tearing the
sandbox down would unmount your live /run/user/<uid> and kill the desktop
session (Wayland/X11 sockets, D-Bus) with it. Every bind this tool creates is
therefore made private at creation time (--make-rprivate, exactly what
arch-chroot does for /run), which detaches the copies from any peer group
so teardown can never touch host mounts.
Environment
Your environment is captured NUL-safely before su (via env -0,
base64-encoded into a 0600 handoff file) and overlaid after the inner
su - <you> resets the environment — so your original PATH, EDITOR,
XDG_*, … win, while the correct login values (HOME=/home/<you>, SHELL,
USER, …) come from su. Bash read-only and terminal-geometry variables
(UID, EUID, PPID, IFS, LINES, COLUMNS, PWD, …) are skipped so
the new shell stays sane. The restore step execs your $SHELL
(login+interactive, with graceful fallbacks for shells without those flags),
so .bash_profile/.profile/.bashrc behave exactly like in a normal
terminal session.
Lifecycle, crash recovery, locking
- Everything privileged happens inside the one
suinvocation:setup → shell → teardown. There is no detached state you can accidentally be left in. - Teardown is driven by the full mount table filtered by the target path
(deepest first, plain
umountwith a lazy fallback) and is registered as anEXIT/INT/TERM/HUPtrap inside the root script — soexit,Ctrl-C,killand mid-setup crashes all end in "unmount everything under the target, remove the temp files". (Note:findmnt <target>alone would not be enough — when<target>is itself a mount point, findmnt prints only that one mount, not the subtree — which is why the filter approach is used.) - A session left behind by a hard kill (e.g. a machine reboot with the session running) leaves stale mounts; the next run sweeps them first (and repairs skeleton ownership to your user, in case a past run left it root-owned) and then proceeds.
- One session per target directory: a per-target
flock(acquired before anything is created under the target, and inherited throughsu) makes a concurrent second run fail fast instead of writing into the first session's tree. - Per-run temporary material (mode
0600/0700, under/tmp/.vibe-chroot-<user>.<pid>/):.vibe-meta(target, user, env blob),.vibe-entries,.vibe-toplevel, and the generated privileged script.vibe-setup.sh. Both the root teardown and the outer script remove the directory.
Debug mode
Run with VIBE_DEBUG set to any non-empty value:
VIBE_DEBUG=1 vibe-chroot ~/vibe-chroot-root ~/vibe.list
The outer script and the root session then print (dbg) … lines for the
key steps: the allowed-skeleton computation, the pre-created skeleton, each
mount and each unmount (with targets), the ownership repair, and the
handoff files. The flag is passed to the root session via a marker file in
the workdir, so it works even if PAM filters the environment across su.
Guarantees (and non-guarantees)
- Guaranteed: the tool never deletes or overwrites anything outside the
target directory and its own temp files; the host
$HOMEis only ever mounted, never written; a non-conforming target is refused, not cleaned; teardown cannot propagate unmounts to host mounts (private copies). - Not guaranteed (by design): this is a filesystem sandbox, not a
container. You are the same UID on the same kernel; host processes are
visible in
/proc; host services remain reachable (D-Bus, sockets, network). It does not protect the host from you — it protects you and your work from your own environment (config sprawl, cache pollution, experiments).
Design notes versus arch-chroot
- One
su-gated root session instead of "must already be root": the unprivileged user invokes the whole lifecycle, and teardown is guaranteed to run in the same session that did the setup. /devis rbind of the host (freshdevtmpfsinarch-chroot): audio, GPUs, USB, disks and their udev-set ownership/groups all just work.- Top-level
/is enumerated dynamically (dirs rbind, symlinks recreated) instead of assuming a package-managed chroot — so it follows whatever distro layout the host has, including merged-usr and extra directories like/snapor/opt/vendor. - Propagation isolation on every rbind (
--make-rprivate):arch-chrootapplies it to/run; here every host-mount copy is private, because the sandbox lives inside the host's mount namespace and an unshared peer-group leak would unmount live host sockets. - The mirror list takes files too, and the sandbox home is a subset mirror rather than the real home.
- No
unshare/PID namespace, no systemd-run, nosetpriv— the stated goal is "normal system, limited/home", and plainsu+chrootare what the constraint set allows.
Troubleshooting
| Symptom | Meaning / fix |
|---|---|
contains paths that do not belong to a vibe-chroot skeleton |
You (or something else) put files into the target dir. Remove them (or the whole target) and retry. The tool will not do it for you. |
| leftover skeleton is root-owned and not rm-able (runs with the old version) | The next run repairs ownership to your user before mounting; until then, delete it as root. |
another vibe-chroot session is using '…' |
A previous session with this target is still alive (or its root side was killed but the inner shell wasn't). End it, or kill the leftover bash/su under the target. |
refusing to run as root |
Invoke as a regular user — the escalation to root is the tool's own. |
su: Authentication failure |
No root password set on the system (common on modern distros). Set one with passwd (as a sudo user) or use a system where su-to-root works. |
su: … pty errors / no prompt |
Run from an interactive terminal; a piped/daemon context has no TTY for the session. |
| mounts left behind | Should not happen; if it does: run vibe-chroot again with the same target (it auto-sweeps and then works), or unmount manually (as root): T=<target>; findmnt -rn -o TARGET \| awk -v t="$T" '$0==t \|\| index($0, t "/")==1' \| sort -r \| while read -r m; do umount -l "$m" \|\| true; done |
| a command in the sandbox can't reach a device | Devices come 1:1 from the host — check ls -l /dev/… on the host; the sandbox adds no restriction. |
| need more visibility into a failure | VIBE_DEBUG=1 vibe-chroot … — the (dbg) lines show every mount/unmount and gate decision. |
License
GPL-2.0-only — matching /usr/bin/arch-chroot from the arch-install-scripts
package (upstream: https://gitlab.archlinux.org/archlinux/arch-install-scripts),
which served as the structural inspiration for the setup/teardown patterns.