Skip to main content
       ______________________
      /  pi in Apptainer    /|
     /____________________/ |
     |  read • ask • write | /
     |____________________|/
               a4a

a4a — sandboxed pi, inside your usual terminal

apptainer4agents is a minimal, KISS tool to sandbox the pi.dev AI harness. Consisting of about 800 lines of code, it is meant to rely on existing well-tested tools for the heavy work, namely Apptainer, a containerization solution that is super-efficient for CPU-heavy tasks and Bubblewrap, the container behind Flatpak and Anthropic's sandbox.

The core principle is to offer a starting tool that is adaptable, forkable, and modifiable.

Why

Keep herdr and Ovis on your PC. Run pi inside Apptainer, allow agents to install and configure their own OS, control what they can read and write. Approve access only to directories pi needs to change.

All with ~800 lines of code.

FAQ

  • Why Apptainer and not podman/docker/bubblewrap? The reason is that I work with machine learning and statistics, so I actuallly prefer Apptainer. However, there is also a technical rational: Apptainer is designed from the ground to be relocatable (no complicated installations), rootless, configurable with common shell commands, and to support GPUs (both NVIDIA and AMD). You can certainly use docker/podman/any-other-container in place of Apptainer, just fork!

  • Why Ovis and not herdr-app/pi-web-ui/put-your-gui-tool? Because Ovis is the mroe mature GUI in the Linux agent echosystem AFAIK.

  • Will you add feature X? No, if I don't need it. But I'm happy to merge PRs carefully tested that stay in the KISS approach.

Features

  • Compatibility and integration guaranteed for Herdr and Ovis.
  • run starts pi; shell opens an unrestricted container Bash.
  • Pi can install software in the writable container root; your real files stay read-only until approved.
  • Approval and revocation restart only pi, preserving its conversation.
  • Persistent container system, optional GPU, fakeroot by default.

Wanted PRs

  • Network sandbox
  • Other agents (codex, claude, omp, opencde, dsh, etc.)
  • Testing and integration of more herdr guis

User guide

Small example commands

Run these from a host herdr pane:

a4a build
a4a run
a4a run -- -c                  # Continue the last conversation
a4a run -- --model MODEL
a4a --gpu nvidia run           # If GPU was not enabled during build
a4a shell                     # Unrestricted shell: writes affect real files

Installation

Prepare a Debian/Ubuntu PC:

sudo apt-get update
# Common tools, usually already installed
sudo apt-get install -y bash python3 curl ca-certificates tar bzip2
# Rootless container helpers.
sudo apt-get install -y uidmap fakeroot

Install herdr and Ovis on the host, using their own installation guides. Keep their pi integrations in your usual ~/.pi/agent configuration; the wrapper reuses installed extensions read-only. It does not install or configure Ovis.

Install with pipx install apptainer4agents (Python 3.11 or newer). The first a4a run creates ~/.config/apptainer4agents/config.toml (or under XDG_CONFIG_HOME) without replacing existing settings. Edit that file for GPU, display and storage defaults, then run a4a build. It holds plain values, never commands. Only config.toml is supported; translate any old config.sh settings manually. Existing container state is not moved on upgrade. Launcher and wrapper code comes from the installed package, not saved config-directory copies. Old implementation copies are ignored and are not deleted automatically. The build downloads local Apptainer if missing and installs pi, omp and Bubblewrap. It does not install herdr or herdr-app in new containers.

If fakeroot fails, ensure your account has at least 65,536 subordinate IDs in both /etc/subuid and /etc/subgid, and user namespaces are enabled. See Apptainer setup.

Usage

Pi knows about two permission tools:

  • request_write_access: existing directory plus a non-empty reason; prompts through pi's TUI/RPC UI, then restarts pi after approval.
  • revoke_write_access: removes the directory's grant and overlapping grants, then restarts pi. Previous writes are not undone.

After approval or denial, pi restarts and receives one automatic message describing the updated permissions, so it can continue without user prompting. Grants last until the wrapper exits. Writes affect your real files immediately. Approval is cooperative: it is not tamper-proof against hostile pi extensions.

Option Effect
--state DIR Store the environment elsewhere.
--project DIR Choose the project; default: current directory.
--no-root Disable fakeroot.
--gpu none|nvidia|amd Override the GPU choice saved at build time.
--gui auto|none|x11|wayland|both Choose display sharing. auto shares what the shell can reach; both shares X11 and Wayland, skipping whichever is missing. x11 and wayland are strict and stop when their display is absent.
--read-only / --writable Container system mode; writable by default.
--no-scan Skip secret scanning for this launch; keep the static blocklist.
--help Command help.
--version Print the installed a4a version.

Options precede the command; pi arguments follow --. Host NVIDIA/AMD drivers are required for GPU access. A GPU selected during build is reused by plain ./a4a run; the build does not install host drivers. Pi's Bubblewrap sandbox preserves GPU device nodes exposed by Apptainer (NVIDIA, DRM and AMD KFD), without sharing the whole /dev tree.

The same values live in config.toml as root, writable, gpu, gui, state, and extra (extra Apptainer arguments). Command-line flags win. Unknown keys and invalid values stop the launch with the file path in the message, so a typo cannot silently change mounts.

To discard container system changes, stop all container processes first:

rm -rf -- ~/.local/share/apptainer4agents/rootfs
a4a build

Use your actual state path if customized. This deletes system changes, not your host home. There is no overlay or undo for writes already made to the host.

Hidden sensitive files

Pi cannot read the built-in sensitive home paths (SSH/GPG keys, cloud credentials, password stores, browser profiles and other credential files). Add home-relative paths in config.toml; your entries extend the built-in list:

denied_home_paths = ["private", ".config/my-service/token"]
secret_scan = true

Before Pi starts, fdfind selects files smaller than 500,000 bytes by filename: credential, secret, token and password names; .env variants; SSH private-key names; and JSON, TOML, YAML, INI, CONF, ENV, PEM, KEY, P12 and PFX extensions. Matching is case-insensitive and includes hidden and ignored files. Search stays on one filesystem, does not follow symlinks, and includes files up to six directories below home. Files with other names or deeper paths are not scanned. One local Gitleaks scan checks temporary copies of selected files. Findings hide the originals; temporary copies and the redacted report are then deleted. Unreadable files and files that disappear during selection are skipped, with a count printed at startup. Skipped files are not checked for secrets. Scanning is enabled by default. Use a4a --no-scan to skip it for one launch, or secret_scan = false to disable it in config. The static blocklist stays active. Missing Gitleaks or scan failures stop startup. Gitleaks's own rules, binary detection, directory exclusions and permissions limit coverage.

Blocked paths stay blocked, including after parent write approvals. There is no read-access tool or private-key exposure workflow. If other blocked information is needed, Pi asks you to provide only the necessary information yourself, with a warning that it enters model context. SSH/GPG use explicitly forwarded sockets.

This is a startup scan and path blocklist, not complete secret isolation. Large or binary files, hard-link copies, symlink-only external trees, environment variables and files created after startup may still expose secrets. Existing conversations and private Pi settings may already contain credentials. a4a shell is outside Pi's privacy sandbox.

The recipe installs Gitleaks through apt alongside the other tools. Existing images need that package installed. Package upgrades supply current launcher and wrapper code automatically on the next launch; active sessions are unchanged.

User credentials and agent forwarding

Pi is instructed to use the launching user's configuration under /home/agent, not /root. Git gets an explicit global config path. SSH may need ssh -F /home/agent/.ssh/config and explicit identity/known-hosts paths because OpenSSH can use the account database instead of HOME. Host credential helpers must also exist in the container; desktop keyring and D-Bus helpers are not forwarded. Fakeroot does not reliably support switching commands to the host UID.

Forwarding grants real authority: Pi can authenticate through SSH, or sign and decrypt through GPG. Use only keys appropriate for the task; prefer SSH keys loaded with confirmation and expiry (ssh-add -c -t 1h). Agent keys remain on the host, but forwarding does not prevent misuse of their operations.

Forwarding is off by default. Enable it before the command:

a4a --ssh-agent run
a4a --gpg-agent run
a4a --ssh-agent --gpg-agent run

SSH requires a live host SSH_AUTH_SOCK. GPG requires host gpgconf and a running extra socket (gpgconf --launch gpg-agent). Only that restricted socket is forwarded, never the main GPG agent socket. Pi receives a private GPG home with copies of public keyrings; private keys are not copied. Keyboxd-only public-key stores are not yet supported. Handle any confirmation or pinentry prompts on the host. Forwarding is a socket bind through both sandboxes, not a per-operation approval proxy. Other credential files outside the blocklist and scan coverage may remain readable even when forwarding is off; this is not complete credential isolation.

New images include OpenSSH and GnuPG clients. Existing images need those clients installed from an ordinary a4a shell. Only settings persist outside the package; the current package wrapper is mounted read-only into the container on launch.

Internals

src/a4a/cli.py validates config.toml and passes the values to src/a4a/assets/launcher.sh, which launches Apptainer. src/a4a/assets/pi-wrapper/guard.py launches Bubblewrap and handles restarts. The home is mounted at both its original path and /home/agent. The working directory keeps its host path; /workspace is an additional alias.

Private pi state lives in STATE/pi, mounted at the same path inside the container. The foreground supervisor re-executes with argv[0] pi and PI_CODING_AGENT_DIR set to the project's agent directory. This lets Ovis validate the reported conversation against that directory even though the sandboxed Pi runs in a separate terminal session. Standard agent/sessions storage avoids the --session-dir override Ovis rejects. These directories contain private settings and may contain credentials.

The herdr bridge permits only pane.report_agent and pane.report_agent_session, for the launching pane. It does not expose host command execution. Herdr's pi extension must already be installed. Ovis must be able to inspect the container processes and read the advertised host paths; full browser integration remains to be verified. Existing old sessions are not migrated to the new host state.

Checks:

scripts/sync-assets.py  # after editing assets outside the package
bash -n src/a4a/assets/launcher.sh src/a4a/assets/bootstrap.sh
python3 -m unittest discover -s tests -v
node tests/test_request.mjs

Credits

Apptainer · herdr · Ovis · Bubblewrap

License: GNU General Public License v3.0 or later. See LICENSE.

Release

scripts/sync-assets.py        # copy edited assets into the package
python3 scripts/release.py patch  # or minor / major

The release script requires a clean working tree and confirmation in an interactive terminal. It bumps the version, builds the packages in a temporary directory, unpacks the wheel there, and runs all tests with the new package metadata on the path. Build or test failures restore the original pyproject.toml. Your installed package is not changed, and no virtual environment or pip install is used.

After tests pass, it uploads only the new artifacts to PyPI, then commits, tags, pushes, and creates the GitHub release. Upload happens before tagging. If an upload fails, the new version is kept because PyPI may already have accepted some files; check PyPI before retrying. It needs build, twine and gh with PyPI and GitHub credentials. With uv, install them in a persistent environment and run the script with it:

uv run scripts/release.py patch

Metadata

Release files for apptainer4agents 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apptainer4agents 0.1.2
File Size Uploaded Provenance Actions
apptainer4agents-0.1.2.tar.gz 76.3 kB Without provenance Details for apptainer4agents-0.1.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for apptainer4agents 0.1.2
File Interpreter ABI Platform Actions
apptainer4agents-0.1.2-py3-none-any.whl Python 3 none any Details for apptainer4agents-0.1.2-py3-none-any.whl

Total release size: 127.7 kB

Release files / apptainer4agents-0.1.2.tar.gz

Download URL apptainer4agents-0.1.2.tar.gz
Size 76.3 kB
Tags Source
SHA-256 checksum
How to use checksums
ec45fdb2ce0161ec446a491ae6532e401f3404965920ad0404059d13ee050700
BLAKE2b-256 checksum
How to use checksums
e379275ae50ccab2f539a6920969a6d13aab66bc750cc79c61071cdc8bae0ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / apptainer4agents-0.1.2-py3-none-any.whl

Download URL apptainer4agents-0.1.2-py3-none-any.whl
Size 51.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cf6f940a5da2dede349887bc86e98ee0a876004ed74f8b2650991e359991aa73
BLAKE2b-256 checksum
How to use checksums
f77cc2a561741a77bd2cd3262bf93c186ffdee3a4e17f03e6095b7fad8a1464a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for apptainer4agents 0.1.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page