Skip to main content

Module container

Module container 

Source
Expand description

Container management for container-type agent panes (Phase 1).

Manages persistent Docker containers — one per container agent. Each container runs the configured image (e.g. ghcr.io/agentmuxai/agent-claude) with tini as PID 1 and is kept alive between turns. Individual turns are executed via docker exec -i (no -t — avoids CR/LF corruption of NDJSON).

Platform support (cross-platform, matches SPEC_CONTAINER_PANE_SUPPORT_2026_06_11.md):

  • DOCKER_HOST when set (unix, tcp with or without TLS, https, npipe), else the sockets Docker, Podman, Colima and OrbStack leave in their usual places; the first that answers a ping is used (container/runtime.rs).
  • Windows: named pipe //./pipe/docker_engine

Independence boundary: this module has no dependency on any other project’s container code. Docker best practices here were researched independently.

Re-exports§

pub use self::pull::StartEvent;
pub use self::pull::StartObserver;
pub use crate::backend::container::runtime::ContainerRuntimeHandle;

Modules§

argv
A container turn’s CLI arguments: the one-shot shape a docker exec turn runs with.
cli
Installing the provider CLI inside a container agent’s container.
cli_release
The container route for the agent CLIs that are not on npm: grok and muse (a pinned release file). The same registry as the host’s own copy (backend::cli_download::SPECS) gives the URL, the SHA-256 and the size, so one pin covers both. No vendor script is run, and nothing a caller sends decides what is fetched: the script gets its values from the registry as positional parameters, never spliced into the script text.
credential
A scoped credential for container agents, in place of the instance auth key.
drift
A container made from an older agent image than this AgentMux: noticing it, and updating it.
gateway_fwd
The gateway forwarder: how a container agent’s model-gateway request is tied to its own container where srv cannot see which container it comes from (Docker Desktop: every container arrives from one address).
image
Which container image an agent runs, and what happens when it can’t be had.
key_route
A container turn on the model gateway: a model route, or an API-key account (model_gateway::catalog::KEY_ROUTE_ID). The container is given only the gateway’s address and a token for that one agent (and account); a key stays in the keychain. At the start of each turn this module makes that token current (a changed address or account, or a container made again, gets a new one and the earlier ends; a turn that overlaps another on the same grant shares its token) and ties it to the container’s own address on the agents network, so the gateway accepts it from that container and no other:
keychain_credentials
A container agent’s login for a Claude account whose credentials are in the macOS Keychain.
limits
CPU, memory and process limits of a container agent’s container. docs/specs/SPEC_CONTAINER_AGENT_RESOURCE_LIMITS_2026_10_29.md.
listener
How a container agent’s agentmux-mcp and hooks reach srv on Linux (P9 of the container-parity work).
mount_source
Comparing a bind mount’s source as Docker reports it with the host path it was asked for.
mounts
The mounts of a container agent’s home: the per-agent volume, the bound account’s credentials, and the agent’s Personal Memory folder.
oneshot
A one-shot, locked-down container: a command that runs once, with nothing but what it is given, and whose output comes back (a Drone Run step, docs/specs/SPEC_DRONE_GENERAL_AUTOMATION_2026_11_11.md §3.6).
oom
Telling a container agent’s user that something in the container was stopped for going over its memory limit, instead of a bare exit 137. docs/specs/SPEC_CONTAINER_AGENT_RESOURCE_LIMITS_2026_10_29.md §5.
pull
Pulling a container agent’s image: the progress the pane shows, and the limits that end a pull which has stopped (spec docs/specs/SPEC_CONTAINER_AGENTS_AT_PARITY_2026_10_27.md, P1 and P2).
reap
Stopping a provider-CLI install whose turn was cancelled.
routes
What a container agent is told when it calls a route it may not. Which routes those are is in route_audience (a route srv serves is for everyone unless an entry there says otherwise; a path that is neither is refused), so there is one list to read. This module is the container listener’s view of it. served says whether srv serves a route at a path; srv answers it from its route table.
runtime
Which container runtime this srv talks to (P11 of the container-parity work).
runtime_socket
No container runtime socket, pipe or control folder, and no AgentMux data folder (the root ~/.agentmux, its shared folder, every channel’s and dev build’s data, config, logs and runtime folders), is reachable through any mount of a container agent, or a folder that holds one (a home folder, the AgentMux root), whichever field the mount comes from (its volumes list, its workspace folder) and whoever wrote it (the definition, a template, a block’s launch settings, another channel’s registry). Sources are compared case-insensitively, with \ as /, . and .. resolved, and a link followed where the path exists. refused_mount is asked once, before an existing container is reused or a new one made; definitions that come in from outside (the shared registry, an old template) have the entries dropped (without_refused), and a definition saved with one is refused (refused_in_json).
session_files
A container agent’s provider session files, reached through its container (SPEC_HISTORY_COMPACT_FORM_ONLY_2026_11_23.md section 5.4).
status_source
What backend::container_status reads from the runtime: the list of agent containers and the stream of their events. Names, states and images only: nothing from inside a container.
upload
Writing a small file into a container’s /tmp.

Structs§

ContainerManager
Shared container manager. Clone-on-Arc; cheap to pass around.
ContainerMountSpec
Host directories a container agent needs mounted to be able to work.
ExecSession
Exec session handle for a single turn.

Enums§

CliProvision
Whether provision_cli found the CLI in place or had to install it.
ContainerError
Errors from container operations.

Constants§

AGENTMUX_DOCKER_NETWORK
Shared user-defined Docker bridge network every agent container is attached to, ADDITIVE to whatever network_mode/extra_hosts already set up (container→host reachability, unaffected — see the doc comment on network_mode below). Unlike the default bridge network, a user-defined one gives per-container DNS resolution and lets the native dev-proxy (backend::dev_proxy) route to a container by its internal IP. See docs/specs/SPEC_NATIVE_CONTAINER_DEV_PROXY_2026_09_19.md §3.1.
CLAUDE_CREDENTIALS_FILE
The credentials file inside the account’s config dir, and inside the image.
CONTAINER_CLAUDE_DIR
Where the agent CLI’s config dir lives inside the image (CLAUDE_CONFIG_DIR).
CONTAINER_MCP_CONFIG_DIR
Where the folder holding an agent’s MCP config is bind-mounted when it lives outside the working directory, so a container launch never has to write it into a user’s project (#3680). The folder, not the file: a single-file bind would keep the old inode across an atomic rewrite. Shared with agentmux-mcp doctor, which looks for the config here inside a container. Where a container agent’s relocated config folder is mounted.
CONTAINER_WORKSPACE_DIR
Where the agent’s working directory is bind-mounted inside the image.

Functions§

container_name_for_slug
Derive the stable container name for an agent from its slug. Format: agentmux-<slug>. Deterministic so restarts reuse the same container.
container_of_meta
The container a container agent’s pane (its block meta: agentMode = container) runs in, named from its agentId as the launch path names it. None for any other pane.
credentials_dir_if_file_backed
The account config dir to hand to ContainerMountSpec::claude_config_host_dir, or None when this account has no file-backed credential to mount.
rewrite_local_url_for_container
Rewrite a host-loopback AGENTMUX_LOCAL_URL (e.g. http://127.0.0.1:PORT) into something a container’s network namespace can actually reach.