Skip to content
mcwellingPublic

About

Per-project Podman containers for coding agents

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Urithiru

Per-project Podman or Docker containers for coding agents.

Urithiru starts, resumes and removes one container per project and runs commands in it, with timeouts, cancellation that really stops what a command started, memory and CPU sizing, and out-of-memory detection. It knows nothing about agents, models or terminals, so any agent harness can use it.

It began as the container layer of Syl and is shared with Bondsmith, a desktop app that hosts many agents. The name is the tower in Brandon Sanderson's Stormlight Archive that houses every order of Radiants, which is what this is meant to do for agents.

Status

Early. The library is what Syl uses in production. The toolchain work (giving each project the right languages and libraries) is planned; see docs/roadmap.html.

Command line and MCP

The urithiru binary drives one project's container, for any harness. Every command takes --json.

urithiru start                      # build what's missing, start or resume
urithiru exec -- cargo test         # run a command in it
urithiru env show                   # image, packages, runtimes, devcontainer
urithiru env add protoc             # install now; prints the diff that keeps it
urithiru env add libpq-dev --kind package
urithiru env check -- cargo build   # environment's fault or the code's? (exit 0/1/3/4)
urithiru env build                  # build the image only
urithiru env prune --dry-run        # runtimes no project has used in 90 days
urithiru env bake --save env.tar    # the image with its runtimes inside
urithiru --image TAG start          # run a baked image as it is
urithiru stop
urithiru mcp                        # MCP server (stdio): env_show, env_check, env_add

urithiru mcp gives any agent, not just Syl, two tools. env_show reports what the container has. env_add installs a missing tool or Debian package into the running container right away. A tool from mise's registry, such as protoc, jq or terraform, arrives in seconds through the shared runtimes volume, checksummed; anything else goes through apt. It returns a diff to mise.toml (tools) or urithiru.toml (packages) that would make the change permanent. The project's files aren't touched: the agent shows the diff to its user. Until the diff is applied, a recreated container won't have the addition. A harness such as Bondsmith starts urithiru mcp --project DIR next to each agent and passes it in ACP's session/new mcpServers.

env check

urithiru env check -- CMD runs a build or test command in the container. When it fails, it reads the output for what compilers, linkers, shells, pkg-config and mise print when something isn't installed:

Finding Example line Suggests
missing_command bash: line 1: protoc: command not found env add protoc
missing_header fatal error: openssl/ssl.h: No such file or directory env add libssl-dev --kind package
missing_library /usr/bin/ld: cannot find -lpq env add libpq-dev --kind package
missing_pkgconfig Package libpq was not found in the pkg-config search path. env add libpq-dev --kind package
missing_runtime mise ERROR No version is set for shim: go env add go
no_network Could not resolve host: example.com none
out_of_memory the container's cgroup counted a kill during the command none
  • The verdict: passed, environment (something points at the environment), code (failed, and nothing does) or timed_out. The exit code follows it: 0, 3, 1 or 4.
  • Suggestions: a suggestion is high confidence when the name comes from Urithiru's table of common commands, headers and libraries, and a guess otherwise (-lfoo becomes libfoo-dev).
  • Nothing is installed. An agent, or you, decides whether to run the suggested env add.
  • Over MCP, the same check is the env_check tool.

Baking

urithiru env bake builds the project's image with the runtimes it declares installed inside, using the same allow-list as the shared volume (core and aqua), and with its go.mod version switched on. It's tagged <repo>-baked:<hash> and can be written to a tarball (--save FILE) or pushed (--push REF; log in with your engine first).

A baked image needs neither the network nor the runtimes volume. It's never used unless asked for: urithiru --image TAG start, or Profile::image_override. For CI:

urithiru env bake --save env.tar          # once, wherever the spec changes
docker load -i env.tar                    # in CI, or on a teammate's machine
urithiru --image urithiru-ready-baked:<hash> --network none start
urithiru exec -- make test

urithiru.toml

System packages a project needs, read for every caller and added to the profile's own list:

packages = ["libpq-dev", "protobuf-compiler"]

Runtimes stay in mise.toml and the other files mise reads.

Use

[dependencies]
urithiru = { git = "https://github.com/mcwelling/urithiru" }
use std::time::Duration;
use tokio_util::sync::CancellationToken;
use urithiru::{Container, ContainerOptions, Mount, Profile};

let project = std::path::Path::new("/path/to/project");
let mut profile = Profile::new("my-agent", project.join(".my-agent/container-id"));
profile.setup = Some("apt-get update -qq && apt-get install -y ripgrep".into());
profile.mounts.push(Mount::read_only(project.join(".my-agent"), "/workspace/.my-agent"));

let container = Container::new(project, profile).with_options(ContainerOptions::default());
container.start_or_resume(false, &|msg| eprintln!("{msg}"))?;

let out = container.exec("cargo test", Duration::from_secs(600), &CancellationToken::new()).await?;
println!("{}", out.stdout);

What a profile sets

Field Meaning
name_prefix Containers are named <prefix>-<first 10 hex of SHA-256(project path)>.
base_image Image to build on. None, the default, is Urithiru's own base (below).
image_repo Repository the profile's image is tagged in: <repo>:<hash>. Defaults to <prefix>-ready.
setup Shell command (bash) that installs the profile's tools. It becomes one RUN step on top of the base, built once and reused.
mounts Extra bind mounts. The project is always mounted read-write at /workspace; a read-only mount inside it (a state directory, say) lays over the project's copy.
env NAME=value variables for the container.
after_start Commands run after every start or resume (copying keys, setting a git identity). Failures are ignored.
options_label Label recording the memory, CPU and network options, so a change recreates the container.
marker File holding the id of the container last started, so a leftover container with the same name is replaced instead of reused.
legacy_name An older container name to remove when it holds this project.

Images

Urithiru builds images rather than saving a configured container:

  • The base, images/base.Containerfile: debian:trixie-slim pinned by digest, every package from one day's snapshot of the Debian archive (security updates included), and mise checked against its published SHA-256. It has git, curl, ssh, build-essential, pkg-config, python3, xz and unzip. It is tagged urithiru-base:<hash>.
  • The profile's layer: FROM the base, then RUN the profile's setup. It is tagged <image_repo>:<hash>.

Each hash covers the image's inputs and the architecture, so the same inputs give the same tag, and changing any input builds a new image while the old one stays usable. An image that exists is reused, which is also why a container with network = "none" can start once its image has been built. remove(true) removes the profile's image only when no container uses it.

CI builds both images on amd64 and arm64 with Docker and with Podman, and checks that the two engines produce the same tags and the same package versions.

Runtimes

Languages a project declares are installed with mise into one volume, urithiru-mise, shared by every project. Agent containers mount it read-only at /opt/mise, with mise's shims on PATH, so a second project asking for Node 20 reuses the first one's.

  • What counts as declared: what mise reads in the project, such as mise.toml, .tool-versions, .nvmrc, .node-version and .python-version, plus go.mod. mise doesn't read go.mod itself, so Urithiru reads its go and toolchain lines. Rust is left to rustup, which reads rust-toolchain.toml itself.
  • Who reads the project: mise does, offline, in the project's own container, which runs the project's code anyway. That container trusts the project's mise.toml.
  • Who installs: a short-lived installer container, given only specs such as node@20. It never mounts the project, so a hostile mise.toml can't touch other projects' runtimes. It installs only mise's core tools and tools from the aqua registry, which checks checksums. Anything else (npm, cargo, asdf plugins) is reported and skipped.
  • When: on each start, if something declared is missing. With network = "none", missing runtimes are reported instead.
  • Pruning: the installer records which install directories each project uses. Container::prune_runtimes removes those no project has used in 90 days.
  • Turning it off: set Profile.runtimes to false. It's also off when the profile names its own base image, since that image may not have mise.

devcontainer.json

When a repo has .devcontainer/devcontainer.json (or .devcontainer.json), a caller can pass it in through devcontainer::load and Profile.devcontainer. This is what Urithiru does with it:

  • Base: image, or build with a Dockerfile (plus its context, args and target), becomes the base. The profile's setup and packages layers go on top of it. Runtimes are off, because the devcontainer brings its own languages.
  • Features from ghcr.io or a local folder are fetched on the host with curl, and each download is checked against its digest. Pins in devcontainer-lock.json are honoured. The Features are built as one layer, with their options as environment variables and their declared containerEnv as ENV.
  • Environment: containerEnv and remoteEnv are set in the container. ${containerEnv:...} and ${containerWorkspaceFolder} are substituted. ${localEnv:...} never is, because it would copy your host's environment, secrets included, into the container.
  • Lifecycle commands: onCreateCommand, updateContentCommand and postCreateCommand run once, when the container is created. postStartCommand runs on every start. Failures are reported, not fatal.
  • Trust: a Dockerfile, Features and lifecycle commands are scripts the repo chose, so they run only when the caller sets Profile.devcontainer_trusted, after asking its user about Devcontainer::fingerprint. Until then Urithiru uses its own base and says why. A plain image needs no trust.
  • Ignored and reported:
    • runArgs, privileged, capAdd, securityOpt and mounts, because they would widen the container's access;
    • initializeCommand, which runs on the host;
    • remoteUser and containerUser: commands run as RunAs decides;
    • forwardPorts.
  • Not supported: Docker Compose.

Sessions

Several clients may share one project's container: several Syl sessions, or Syl and Bondsmith. A start holds an exclusive lock beside the marker (<marker>.lock), and a client that has started holds a shared session lock (<marker>.session) until it's dropped or its process exits. While any other client holds that, a start never removes the container:

  • fresh is refused with "another session is using …".
  • A client whose definition differs (options, user, image, mounts, environment) uses the container as it is, and says so.
  • A client on the other engine is refused.

The one exception is a mount check that ran and found /workspace unmounted.

When a client is done, Container::remove_if_unused ends its session and removes the container only if no other session is open. Use it in place of remove, which removes the container whatever other sessions are open (it's the caller's explicit decision, and P1 doesn't cover it). The decisions are in crates/urithiru-core, proved in Lean against the design's model; see docs/ledger.md.

How commands run

  • Each command gets URITHIRU_EXEC=<tag> in its environment. On a timeout or cancel, every process in the container with that tag is killed, including ones that left the command's process group (setsid, test harnesses, background servers). Each command also runs under timeout -s KILL in the container as a backstop.
  • stdout and stderr are drained together, so a chatty command can't deadlock on a full pipe.
  • memory = "auto" gives the container 75% of what the engine has (its VM's, on macOS), and CARGO_BUILD_JOBS, MAKEFLAGS and CMAKE_BUILD_PARALLEL_LEVEL are set so parallel builds fit in that memory.

Engines

Urithiru drives Podman or Docker through their command lines. Docker covers OrbStack, Colima and Rancher Desktop too, since they provide a docker command. Without a choice, it uses URITHIRU_ENGINE (podman or docker) if set, else whichever of Podman and Docker is running, checked in that order. Callers can pick one with Container::with_engine.

Rootless Podman is the best sandbox: root in the container is your own user on the host. Rootless Docker is the same. Docker Desktop and OrbStack run containers in a VM, which is also fine.

Rootful Docker on Linux is different: root in the container is root on the host. So there, by default, commands run as the project directory's owner (its uid and gid) instead, and files the agent writes stay yours. Escaping the container still gives root on the host, and Urithiru says so when it starts a container there.

ContainerOptions::run_as picks the user:

RunAs Commands run as
Auto (default) The project's owner on rootful Docker on Linux, root elsewhere.
Root root.
HostUser The project's owner. On Podman this uses --userns=keep-id.

As the host user, commands get HOME=/home/urithiru and a passwd entry for their uid. They can't use root, so system packages belong in the profile's setup, and tools a profile installs should live outside /root.

A container is recreated when anything it was created with changes: its image, mounts, environment, user, or limits.

SELinux

On a host enforcing SELinux (Fedora, RHEL and the like), a container can't read a bind mount whose files aren't labelled for containers, whatever their owner. There, Urithiru mounts the project with :z, a shared label, since several sessions may share one container. Other mounts are relabelled only if their Mount asks (Relabel::Shared or Relabel::Private), because relabelling changes the host files' labels: never do it to a home directory or ~/.ssh, whose labels the host's own tools rely on. Mount a copy instead.

Detection reads /sys/fs/selinux/enforce. URITHIRU_SELINUX=1 or 0, or Container::with_selinux, overrides it, for example for an engine on another host. Podman's VM on macOS doesn't need it.

Requirements

Podman 4 or later, or Docker 20.10 or later. On macOS and Windows, a running podman machine or Docker Desktop (or OrbStack, Colima).

License

MIT

About

Per-project Podman containers for coding agents

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages