Metadata-Version: 2.4
Name: walls
Version: 0.2.7
Summary: Wall in Claude Code agents to the current folder using Apptainer/Singularity containers
Author-email: Your Name <your@email.com>
License: MIT
Project-URL: Homepage, https://github.com/munch-group/walls
Project-URL: Repository, https://github.com/munch-group/walls
Project-URL: Documentation, https://munch-group.org/walls
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0
Requires-Dist: tomli>=2.0; python_version < "3.11"
Requires-Dist: tomli-w>=1.0
Dynamic: license-file

# walls

`walls` runs Claude Code (or anything else) in an [Apptainer/Singularity](https://apptainer.org) container where **only the current folder is writable**. It is meant for large shared file servers, where you, and so any agent you start, can write to many files that belong to many people.

```bash
cd /faststorage/project/my-analysis
walls            # bash in a box; the folder is at the same path. Now run: claude
```

## What the box can and cannot touch

| Host | Inside the box |
| --- | --- |
| Current folder | read-write at its own path (or at `/work`, see `mounts.workdir`) |
| `$HOME` | `~/.walls/home` (shared by all boxes; holds the Claude Code install and login) |
| `/tmp`, `/var/tmp` | private per folder, kept in `~/.walls/work/<folder>-<hash>` |
| Extra folders (`--ro`, `--rw`, `mounts.*`) | at their real paths, read-only unless asked otherwise |
| Host `PATH` (unless turned off) | read-only, at the real paths; for an entry ending in `/bin`, the whole folder above it |
| Everything else on the host | not mounted (`--contain --no-mount hostfs,bind-paths`) |
| Host processes | not visible and not signalable from inside the box (see below) |

The main goal is to shield the rest of the file system from Claude sessions. Shielding boxes from each other matters less: they share `~/.walls/home`, so one box can read what another left there.

To make that boundary hold, walls refuses to:

- wall in `/` or your home folder,
- give write access to a folder that contains walls' own folders (claude home, scratch, images, config).

All configuration lives in `~/.walls/config.toml`, outside any walled folder. Settings for a single folder are stored there too, under `[folders."<path>"]`, so nothing running inside a box can change what the next box may see.

## Install

```bash
pip install git+https://github.com/munch-group/walls   # or, once released: conda install -c munch-group walls
walls setup                # creates ~/.walls, pulls the image, installs Claude Code
walls doctor               # checks that everything is in place
```

If the default image is missing, `walls setup` asks whether to pull `docker://mcr.microsoft.com/devcontainers/base:ubuntu` as the image `ubuntu`. If your home quota is small, point `APPTAINER_CACHEDIR` and `APPTAINER_TMPDIR` at a scratch disk first.

### Where walls keeps its files

Everything is in one folder, `~/.walls`:

| Path | Holds |
| --- | --- |
| `~/.walls/config.toml` | all settings |
| `~/.walls/home` | `$HOME` inside every box |
| `~/.walls/work` | a scratch folder per box |
| `~/.walls/images` | the `.sif` images |
| `~/.walls/cache` | what walls remembers about images |

Set `WALLS_HOME` to keep the whole folder somewhere else, or move a single part with `paths.home`, `paths.work` or `paths.images` (for example the images to a scratch disk). To uninstall, close all boxes and delete the folder; that also removes the Claude Code install and login kept in `~/.walls/home`.

Earlier versions kept these in `~/claude-home`, `~/claude-work`, `~/.config/walls` and `~/.local/share/walls/images`. If any of these exist, `walls setup` offers to move them into `~/.walls`; if you decline, it sets up a fresh `~/.walls` and leaves them unused. A folder whose location you had set yourself stays where it is.

## Usage

```bash
walls                              # interactive bash in a box
walls /data/ref /data/db           # ...plus read-only access to these folders
walls --rw ../shared-results       # ...plus read-write access to this one
walls -- claude                    # run a command instead of a shell
walls --no-host-path --aliases     # one-off: no host PATH, import bash aliases
walls --dry-run                    # print the apptainer command and rcfile, start nothing
```

### Images

```bash
walls image pull                                   # image.source, named 'ubuntu'
walls image pull docker://ubuntu:24.04 --name plain
walls image build my.def --name custom --fakeroot
walls image list
walls image use ubuntu [--folder]                  # default for all boxes, or for this folder
walls image rm ubuntu
```

### Claude Code

```bash
walls claude install     # official installer, run inside a box with HOME=~/.walls/home
walls claude update
```

These, and `walls setup`, run in a box of their own and so follow `apptainer.private_pid`. On a host that refuses a box its own process namespace (a cluster front end), run them on a compute node or add `--no-private-pid`:

```bash
walls setup --no-private-pid
```

### Configuration

```bash
walls config show [--effective] [--folder [DIR]]
walls config get  shell.import_aliases
walls config set  shell.import_aliases true             # globally
walls config set  path.mount_host_path false --folder   # only for the current folder
walls config add  mounts.ro /faststorage/project/ref --folder
walls config remove mounts.ro /faststorage/project/ref --folder
walls config unset path.mount_host_path --folder
walls config folders [--prune]                          # folders with their own settings
walls config edit                                       # $EDITOR, validated afterwards
```

Settings are applied in this order, each overriding the one before:

1. built-in defaults
2. global settings
3. the current folder's settings
4. command-line flags

List settings (such as `mounts.ro`) from different levels are combined rather than replaced.

| Key | Default | Meaning |
| --- | --- | --- |
| `paths.home` | `~/.walls/home` | `$HOME` inside every box (global only) |
| `paths.work` | `~/.walls/work` | per-box scratch (global only) |
| `paths.images` | `~/.walls/images` | where named `.sif` images live (global only) |
| `image.default` | `ubuntu` | image name or `.sif` path |
| `image.source` | `docker://mcr.microsoft.com/devcontainers/base:ubuntu` | what `walls image pull` fetches when given no source |
| `image.source_name` | `ubuntu` | the image name that pull is stored under |
| `apptainer.binary` | `auto` | `apptainer`, falling back to `singularity` |
| `apptainer.private_pid` | `true` | give the box its own process and IPC namespaces (`--pid --ipc`); no box is started on hosts that refuse this |
| `apptainer.extra_args` | `[]` | extra arguments passed to `apptainer exec` |
| `mounts.ro` / `mounts.rw` | `[]` | extra folders, mounted at their real paths |
| `mounts.workdir` | `host` | where the walled folder is mounted: `host` for its real host path, or an absolute path such as `/work` |
| `shell.import_aliases` | `false` | copy the aliases from your host `bash` into the box |
| `shell.import_color_aliases` | `true` | copy only the host aliases that add a colour option, such as `ls='ls --color=auto'` |
| `shell.prompt` | `host` | `host` gives the box the prompt (`PS1`) of your host `bash`; anything else is used as the `PS1` itself |
| `shell.prompt_prefix` | magenta `[walls]` | put in front of the prompt; `$BOX` in it is the name of the walled folder |
| `shell.env_pass` | `TERM`, `COLORTERM`, `LS_COLORS`, `GREP_COLORS`, `GCC_COLORS`, `CLICOLOR`, `CLICOLOR_FORCE`, `NO_COLOR`, `FORCE_COLOR` | host environment variables passed into the box |
| `path.mount_host_path` | `true` | mount the host `PATH` read-only and append it to the box `PATH` |
| `path.exclude` | `/bin`, `/sbin`, `/usr/*`, ... | `PATH` entries never mounted (the image provides these) |

**Prompt.** A box shows the prompt of your host shell with a magenta `[walls]` in front. walls reads `PS1` from `bash -ic` on the host at every start. A prompt that runs commands (`$(...)` or backticks, as git status prompts do) is replaced by `\w\$ `, because what it calls is usually missing in the box. A prompt that the host builds in `PROMPT_COMMAND` (starship and similar) is not mirrored either: the box gets whatever `PS1` is before that runs.

**Aliases.** With `shell.import_aliases`, walls reads the aliases that `bash -ic 'alias -p'` reports on the host. They are defined in the box after `~/.walls/home/.bashrc` has been sourced. An alias that refers to a host path only works if that path is mounted.

**Colours.** A box colours command output the way your host terminal does. The colour variables in `shell.env_pass` are passed in, and with `shell.import_color_aliases` (on by default) walls copies the host aliases that only run a command with a `--color` option, such as `ls='ls --color=auto'` or `ll='ls -l --color=auto'`. Other aliases are left out unless `shell.import_aliases` is on. `walls --no-aliases` starts a box without any host aliases. Colour settings kept in files in your host home, such as `~/.gitconfig` or `~/.dircolors`, are not copied.

**Working directory.** By default (`mounts.workdir host`) the walled folder is mounted at its own host path and that is the box's working directory, so an absolute path is the same inside and outside the box and tools that print or store paths behave the same way. Any parent folders the box does not already have are created as empty **read-only** mounts, so a stray write to a parent fails with "Read-only file system" rather than silently going to the box's throwaway overlay and vanishing when the box closes. walls cannot do this when the real path sits under a system directory the box provides itself (such as `/tmp`, `/usr` or `/opt`), or where it would hide the box home or Claude Code's install. It then starts no box and says why; it does not fall back to another mount point. To mount the folder at a fixed path instead, run `walls --workdir /work` for one run or `walls config set mounts.workdir /work --folder` to keep it for that folder. With a fixed path, every such folder has the same path in the box, and tools that store settings per path (Claude Code keeps its sessions that way, in the shared box home) cannot tell the folders apart.

**Host PATH.** By default the folders on your host `PATH` are mounted read-only in the box and appended to its `PATH`, so the programs you have on the host are there in the box too. `walls --no-host-path` starts a box without them, and `path.mount_host_path false` turns this off for good. The `PATH` is the one of the shell that starts `walls`, so an environment activated there is part of it. This widens what a box can **read**: everything in the mounted folders, not only the programs. For a `PATH` entry ending in `/bin`, walls mounts the parent prefix so that the rest of the installation is available too: a conda env's `bin/python` needs the env's `lib/`. So an entry such as `/faststorage/project/x/bin` makes all of `/faststorage/project/x` readable in the box; run `walls --dry-run` to see what is mounted. The parent is not used if it is `/`, a top-level folder, or your home folder. The mounts are read-only, so installing into them from a box fails (for example `pixi global install` when `~/.pixi` is mounted). Host entries are appended after the box's own `PATH`, so the image's tools win. A `PATH` entry inside the walled folder, such as the `bin` of a pixi or conda environment kept in the project, needs no mount of its own: it is added to the box `PATH` at the path the folder has in the box (under `/work` with `mounts.workdir /work`, where an environment that stores its own path may still not run). Every skipped entry is reported at each start: an entry is skipped with a warning if mounting it would hide something in the box home, e.g. `~/.local`, where Claude Code is installed. An empty folder in the box home does not count: the container runtime leaves one behind as the mount point.

**glibc.** A host program runs in the box only if the image's glibc is at least as new as the one the program was built for. When a box starts with host `PATH` mounts, walls warns if this machine's glibc is newer than the image's. `walls doctor` goes further and lists each mounted host program that needs a newer glibc than the image has. The image's glibc version is read once per image file and remembered in `~/.walls/cache/image-glibc.json`. Only glibc is checked: a host program can still fail in the box because a shared library it needs is not mounted.

**The walled folder.** The wall protects what is outside the folder, not the folder from what happens in it. A program in a box can change anything in the walled folder and in every folder mounted read-write, and whatever it leaves there runs with your full access when you later run it on the host. That goes for scripts, a `Makefile`, notebooks and task definitions, and also for git: a hook in `.git/hooks` or a setting in `.git/config` is run by ordinary `git` commands, and a shell prompt that shows git status is enough to trigger one. So after a box has worked in a folder, treat the folder's contents as you would code from someone else: look at what changed (`git status`, `git diff`) before you run it on the host, and note that `git diff` does not show changes inside `.git`. The same holds for `~/.walls/home`, which every box can write to: walls only ever runs what is in it inside a box.

**Processes.** A box gets its own process and IPC namespaces (`--pid --ipc`): it sees only its own processes and cannot signal any on the host. This needs a host that lets a user namespace mount a new `/proc`. A host refuses when files are mounted over parts of `/proc`, as on some cluster front ends. On such a host walls starts no box and says why; it does not fall back to a weaker box. Start the box on a host that allows it instead, for example a compute node with `srun --pty walls`. `walls doctor` tells you whether the current host allows it.

To start a box on such a host anyway, switch the separation off with `walls --no-private-pid` or `apptainer.private_pid false`. A program in that box can list all host processes with their command lines and send signals to (and so kill) your own host processes. There is no in-between that works: a box without any `/proc` hides the host's processes, but Claude Code does not start in it.

**User namespace.** walls always starts Apptainer in a user namespace (`--userns`) and fails if the host does not allow that; it never uses Apptainer's setuid mode. The user namespace is what keeps a box from reading host files through `/proc/<pid>/root`.

**Network.** The network is not walled in. A box shares the host's network, so a program in it has the same network reach as you have on that host: the internet, other machines on the local network, every service that listens on the host's `localhost` (on a shared machine that includes other users' services), and abstract unix sockets. This breaks the wall if one of those services acts for you without asking who is calling, such as a Jupyter server without a token, a Dask or Ray scheduler, or a development server. Do not run such services on a host while a box is running there. Files that hold credentials for services, such as SSH keys and Jupyter tokens, are not visible in a box unless you mount them.

walls starts a box with a clean environment, so the host's proxy variables (`HTTPS_PROXY` and the like) are not set in it. On a host that reaches the internet only through a proxy, add them to `shell.env_pass`.

## How it works

`walls` resolves the settings, then writes a small bash rcfile to `~/.walls/work/<box>/walls.bashrc`, which is mounted read-only at `/walls/bashrc`. That rcfile sources `~/.walls/home/.bashrc` and then sets the prompt, `PATH` and aliases. Finally walls replaces itself with:

```bash
apptainer exec --userns --contain --cleanenv --pid --ipc --no-mount bind-paths,hostfs \
  --home ~/.walls/home:/home/$USER --workdir ~/.walls/work/<box> --writable-tmpfs \
  --bind $PWD:$PWD:rw --pwd $PWD --bind <extra mounts> <image>.sif bash --rcfile /walls/bashrc -i
```

Run `walls --dry-run` to see the exact command for the current folder.
