Skip to main content

AI-Container

Podman based container for isolating AI tooling for a individual project.

Context

In the past, I have repeatedly observed and experienced coding agents accessing or using files and content which they either weren't supposed to, or even technically "did not have access to."

On one occasion, for example, file access was explicitly restricted (e.g., the path was blocked). However, the agent exploited its ability to run bash commands, using them to traverse and scan the restricted paths instead of relying on standard read/write methods.

For this reason, I believe it is essential to implement clear restrictions or a contextual sandbox that is shared with the AI, and which it cannot as easily circumvent by simply invoking a different command.

Prerequisites

  • Podman (>= 5.0) - Container runtime. Install
  • Python (>= 3.13) - Required for the CLI. Install
  • uv - Used to install and run the CLI. Install

Image builds and volume creation are performed through the Podman Python SDK, which talks to the Podman service socket. Make sure the socket is running:

systemctl --user enable --now podman.socket

Installation

Install the ai-container package:

uv tool install ai-container

Or from source:

git clone https://github.com/yourusername/ai-container.git
cd ai-container
uv tool install .

The ai command will then be available.

Usage

Basic Commands

ai agent pi /path/to/project        # Run PI coding agent
ai agent opc /path/to/project       # Run OpenCode coding agent
ai agent claude /path/to/project    # Run Claude Code
ai agent aic /path/to/project       # Run aichat
ai agent llm /path/to/project       # Run llm
ai shell /path/to/project           # Interactive shell in container

ai agent <tool> [paths...] [-- args...] is the single entry point for every tool. Valid tools: pi, opc, claude, aic, llm.

Pass additional arguments to the tool after --:

ai agent pi /path/to/project -- --verbose --model claude-3-sonnet

Mounting Folders

The paths you pass decide what the container sees in /workspace:

ai shell                           # nothing mounted, empty /workspace
ai shell ./app                     # contents of ./app  -> /workspace
ai shell ./mount1 ../mount2        # ./mount1           -> /workspace/mount1
                                   # ../mount2          -> /workspace/mount2

When you pass several paths, each folder is mounted under its own name, so folder names must be distinct.

Use --host-paths to mount folders at the same absolute path as on the host instead (handy when paths show up in logs, configs or tool output):

ai shell --host-paths ~/src/app            # /Users/foo/src/app -> /Users/foo/src/app
ai agent pi --host-paths ~/src/app ~/lib   # starts in their common parent (/Users/foo)

To make this the default, set host_paths = true in a config file (see Config Files); --no-host-paths switches it off for a single run. The container starts in the deepest folder that contains all mounts. Paths that would hide parts of the container system (e.g. /, /usr, /etc, /root) are refused.

Rebuilding the Container Image

The container image is built automatically on first use via the Podman SDK. When you want to pull in the latest tool versions, force a rebuild with the image rebuild command:

ai image rebuild                  # rebuild the default (configured) image
ai image rebuild pi pi-python     # rebuild several images, parents first
ai image rebuild pi,pi-python     # same, comma-separated
ai image rebuild --all            # rebuild every image, parents first
ai image rebuild --deep pi        # also rebuild parents (claude, base)
ai image rebuild --no-cache pi    # ignore the layer cache, fetch latest tools

By default, build steps whose instructions did not change are reused from the layer cache, so tools installed by e.g. npm install -g are not updated. Use --no-cache to re-run every step. Only the named images are rebuilt, their parent images are built only if missing. Add --deep to rebuild the whole parent chain as well (combine both for a complete refresh: ai image rebuild --deep --no-cache pi-python).

Custom Environments

Need a specific toolchain (Rust, Go, an extra editor, ...)? Define a custom environment: a thin image built FROM aic:base that adds your tooling on top of everything the base image already provides.

Select an environment with the -e/--env option of shell and agent; image rebuild takes image names as arguments:

ai shell -e rust .            # shell in the rust environment
ai agent -e rust pi .         # run pi in the rust environment
ai image rebuild rust         # (re)build the rust image (FROM aic:base)
ai image rebuild rust,go pi   # environments and built-in images can be mixed

Manage environment definitions with the env group:

ai env list                   # show environments and whether images are built
ai env new rust               # scaffold a Containerfile (FROM aic:base)
ai env new rust --edit        # scaffold and open it in $EDITOR
ai env edit rust              # edit the Containerfile
ai env path rust              # print the Containerfile path
ai env remove rust --purge    # delete the definition (and its image)

Definitions live under ~/.config/ai-container/environments/<name>/ (honoring XDG_CONFIG_HOME). The directory is also the build context, so you can COPY local files into your image. A scaffolded Containerfile looks like:

# rust environment -- extends the ai-container base image.
FROM aic:base

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
    | sh -s -- -y --default-toolchain stable
ENV PATH="/root/.cargo/bin:${PATH}"

WORKDIR /workspace

Without -e, the default base environment is used. Persistence volumes (config, state, share, pi-config, claude) are shared across all environments, so credentials and config are entered once and work everywhere.

Config Files

Defaults for -e/--env, --host-paths and the global flags (--log-level, --dryrun) can be set in a TOML config file, so you don't have to repeat them on every invocation. Files are merged from several sources, highest precedence first:

  1. ./.ai-container.toml — project-local, in the current working directory
  2. ~/.config/ai-container/config.toml — user config (honors XDG_CONFIG_HOME)
  3. ~/.ai-container.toml — home dotfile
  4. Built-in defaults

Command-line flags always override config files. Each layer only needs to set the keys it cares about; the rest fall through to the next layer.

# .ai-container.toml
env = "rust"        # default environment
log_level = "DEBUG" # one of: DEBUG, INFO, WARNING, ERROR, CRITICAL
dryrun = false
host_paths = true   # mount folders at their host paths (see --host-paths)

Provided Tools

  • PI - Coding agent for generation, analysis, and refactoring
  • OpenCode - AI-powered coding assistant
  • Claude Code - Anthropic's official coding agent
  • aichat - Interactive AI chat interface
  • llm - Command-line tool for LLM interaction

Configuration & Persistence

First run: The container image is built (one-time, takes a few minutes).

Tools use their standard configuration methods (within the container):

  • aichat: ~/.config/aichat/config.toml
  • llm: ~/.config/llm/ + environment variables
  • PI: ~/.pi/
  • OpenCode: ~/.config/opencode/
  • Claude Code: ~/.claude/

Configuration persists automatically across all runs and containers through named Podman volumes (config, state, share, pi-config, claude). Configure once, use everywhere:

# First run: setup credentials
ai shell /path/to/project
# Inside container: aichat, llm keys set openai <key>, etc.

# Subsequent runs: credentials available automatically
ai agent pi /path/to/project

Other/Previous Work

Metadata

Release files for ai-container 0.24.0

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

Source distribution (sdist)

Source distribution for ai-container 0.24.0
File Size Uploaded Provenance Actions
ai_container-0.24.0.tar.gz 49.8 kB Without provenance Details for ai_container-0.24.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ai-container 0.24.0
File Interpreter ABI Platform Actions
ai_container-0.24.0-py3-none-any.whl Python 3 none any Details for ai_container-0.24.0-py3-none-any.whl

Total release size: 71.7 kB

Release files / ai_container-0.24.0.tar.gz

Download URL ai_container-0.24.0.tar.gz
Size 49.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a326a27a3dcd6e63ddec1574be1d7f9da97103ebe97c9b27716f2f8ce7de3909
BLAKE2b-256 checksum
How to use checksums
d87a7547d46dcf0be623ade12bb7b895b661bc29dde8b0a728e6f8771686617e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ai_container-0.24.0-py3-none-any.whl

Download URL ai_container-0.24.0-py3-none-any.whl
Size 21.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
27af51a9f49f5cdb255d4d7e0d328587d3f8c52bda264ad460851caee4bad9ea
BLAKE2b-256 checksum
How to use checksums
2558d48e7416ebb3743ebd983182c8e24ebe8b0a382e2936da0b79ac18002b72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for ai-container 0.24.0

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.

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