Skip to content

Instantly share code, notes, and snippets.

@lemajes
Last active June 2, 2026 08:18
Show Gist options
  • Select an option

  • Save lemajes/767046db009dc5717608a66f0b9811eb to your computer and use it in GitHub Desktop.

Select an option

Save lemajes/767046db009dc5717608a66f0b9811eb to your computer and use it in GitHub Desktop.
CHROOT V2

Install requirements

sudo apt install debootstrap schroot -y

Create chroot

sudo debootstrap --arch=amd64 bookworm /var/chroot/debian12 https://deb.debian.org/debian
# sudo mount --bind ~/rootme /var/chroot/debian12/home/ # mount workfolder if needed

Mount the chroot and install tools and things (UNSECURE)

sudo chroot /var/chroot/debian12 /bin/bash

Install node and npm in chroot

sudo chroot /var/lib/chroot/debian12 /bin/bash -c \
  "apt-get install -y nodejs npm"

Mount the chroot with unshare (SECURE)

#!/bin/bash
# ~/bin/claude-jail.sh

JAIL=/var/chroot/debian12
PROJECT=${1:-~/rootme}
EXTRA=${2:-~/ai}

mkdir -p "$JAIL/home"
mkdir -p "$JAIL/mnt/extra"
mkdir -p "$JAIL/proc"
mkdir -p "$JAIL/tmp"
sudo mkdir -p "$JAIL/mnt/extra"
suod chown -R root:root $JAIL/

sudo unshare --mount --pid --fork --map-root-user /bin/bash -c "
  mount --bind '$PROJECT'  '$JAIL/home'      &&
  mount --bind '$EXTRA'    '$JAIL/mnt/extra' &&
  mount -t proc proc       '$JAIL/proc'      &&
  mount -t tmpfs tmpfs     '$JAIL/tmp'       &&
  chroot '$JAIL' /bin/bash -c 'cd /home && npx @anthropic-ai/claude-code'
  umount '$JAIL/mnt/extra' 2>/dev/null
  umount '$JAIL/home'      2>/dev/null
  umount '$JAIL/proc'      2>/dev/null
  umount '$JAIL/tmp'       2>/dev/null
"

Start jail

claude-jail.sh ~/rootme ~/documents/specs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment