Skip to main content

ContainerRuntime

Struct ContainerRuntime 

Source
pub struct ContainerRuntime { /* private fields */ }
Expand description

An AgentRuntime that runs each agent in its own container via a docker/podman CLI (shelled out through tokio::process, so no Docker API dependency — the engine binary is the only requirement).

One container per agent, named a2a-agent-<id>. The engine is the source of truth for liveness (inspect); the in-memory map only remembers each agent’s published port so health can probe its card.

Images: an agent runs from the base image (with_base_image) unless its config names its own with [runtime] image, which is how an agent whose handler no TOML can express gets deployed like any other. Either way the container gets the same contract — the config bind-mounted at /etc/agent.toml and named by A2A_CONFIG, HOST=0.0.0.0, the configured port published, and the allowlisted variables passed through — but only the base image is given a command (a2a run --config …). An agent’s own image boots by its own ENTRYPOINT.

Binding: the in-container agent must bind 0.0.0.0 to be reachable through the published port. The base image sets HOST=0.0.0.0 and this adapter passes -e HOST=0.0.0.0; since the config’s default_host reads HOST, a config that omits host binds all interfaces. A config that hard-codes host = "127.0.0.1" will not be reachable.

Secrets: keep them out of the TOML as ${VAR} refs. Each referenced variable — provided it is on the EnvAllowlist — is injected into the container as a value-less -e VAR pass-through, resolved from this process’s environment by the engine CLI. So the bind-mounted TOML and the docker create argv never carry secret values, and the in-container a2a run expands the refs at startup. The deploying process (e.g. a2a control-plane) must therefore hold the secrets in its own env; provisioning fails fast if a ref has no value and no ${VAR:-default}.

The allowlist is deny-by-default (with_allowed_env): without it, any accepted config could name any variable this process holds and have it expanded into the agent’s card for anyone to read back.

Hardening: every agent is created with capabilities dropped, privilege escalation blocked, a process cap, and — where its storage permits — a read-only root filesystem. See ContainerHardening for what is on by default and why resource ceilings are not. Two consequences worth knowing: an agent cannot bind a port below 1024 (the image runs as a non-root user anyway), and a handler that writes outside /tmp needs either sqlx storage or a relaxed policy.

Platform: the config is bind-mounted (-v host:container), so host config paths must be expressible as a Docker volume source — works on Linux/macOS; Windows host paths need conversion (out of scope here).

Implementations§

Source§

impl ContainerRuntime

Source

pub fn new() -> Self

Use docker with the default base image.

Source

pub fn with_engine(engine: impl Into<String>) -> Self

Use a specific engine binary ("docker" or "podman").

Source

pub fn with_hardening(self, hardening: ContainerHardening) -> Self

Replace the hardening policy applied to every agent this runtime provisions (default: ContainerHardening::default).

Source

pub fn with_base_image(self, image: impl Into<String>) -> Self

Override the base image (default [DEFAULT_IMAGE]).

This is the image for agents that do not name one. An agent whose config sets [runtime] image runs from that instead, whatever this is set to.

Source

pub fn with_allowed_env(self, allowed: EnvAllowlist) -> Self

Permit deployed configs to reference these host environment variables. Anything not listed is rejected at provision.

Trait Implementations§

Source§

impl AgentRuntime for ContainerRuntime

Source§

fn recover<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Recovered<AgentId>, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Rebuild the id → port map from the engine, which kept running while this process was not.

ps -a on purpose: a stopped-but-existing container is still an agent this runtime manages, and adopting it is what makes stop/undeploy work on it after a restart instead of returning NotFound.

Source§

fn logs<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 AgentId, tail: Option<usize>, ) -> Pin<Box<dyn Future<Output = Result<Vec<String>, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Replay the container’s output via the engine, which retains it for the container’s whole life — including after it exits, which is exactly when the log matters most.

Source§

fn provision<'life0, 'async_trait>( &'life0 self, spec: AgentSpec, ) -> Pin<Box<dyn Future<Output = Result<AgentId, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Register an agent to be run, without starting it. Returns its AgentId.
Source§

fn start<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 AgentId, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Start a provisioned agent. RuntimeError::AlreadyRunning if it is already live, RuntimeError::NotFound if it was never provisioned.
Source§

fn stop<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 AgentId, ) -> Pin<Box<dyn Future<Output = Result<(), RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Stop a running agent. Idempotent: stopping an already-stopped agent is Ok. RuntimeError::NotFound if it was never provisioned.
Source§

fn health<'life0, 'life1, 'async_trait>( &'life0 self, id: &'life1 AgentId, ) -> Pin<Box<dyn Future<Output = Result<RuntimeHealth, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Report an agent’s current RuntimeHealth.
Source§

fn list<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<RuntimeStatus>, RuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

List every provisioned agent with its current status.
Source§

impl Clone for ContainerRuntime

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for ContainerRuntime

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more