axio-tools-docker

Docker sandbox lifecycle and sandbox-bound coding tools.

class axio_tools_docker.DockerSandbox(url: str = 'unix:///var/run/docker.sock', *, image: str = 'python:latest', memory: str = '256m', cpus: str = '1.0', network: bool | str = False, workdir: str = '/workspace', volumes: dict[str, str] | None = None, named_volumes: dict[str, str] | None = None, volumes_remove: bool = False, env: dict[str, str] | None = None, user: str = '', name: str = '', remove: bool = True, read_only: bool = False, shm_size: str = '', cap_add: list[str] | None = None, cap_drop: list[str] | None = None, privileged: bool = False, ulimits: dict[str, int | tuple[int, int]] | None = None, tmpfs: dict[str, str] | None = None, ports: dict[int, int] | None = None, platform: str = '', extra_hosts: dict[str, str] | None = None, devices: list[str] | None = None, dns: list[str] | None = None)[source]

Async context manager that provides a sandboxed Docker container with axio tools.

property container_id: str

Return the ID of the running container. Only valid inside async with.

async ensure_image() → None[source]

Pull the image if it is not present locally.

async ensure_running() → None[source]

Start the container if it exists but isn’t running (e.g. a reused one that was stopped). Idempotent — a no-op for a freshly-started container.

async exec(command: str, timeout: float = 30, stdin: str | None = None) → str[source]

Execute a shell command inside the container and return its output.

async get_archive(path: str) → TarFile[source]

Fetch a path from the container as a TarFile object.

async read_file_bytes(path: str) → bytes[source]

Read a file from inside the container and return raw bytes.

property tools: tuple[Tool[Any], ...]

The axio Tool instances for this sandbox, built fresh (bound to self, so a fork’s tools bind to the fork). Only valid inside async with.

async write_bytes(path: str, data: bytes, mode: int = 420) → str[source]

Write raw bytes to a file inside the container. Parent dirs are created.

async write_file(path: str, content: str, mode: int = 420) → str[source]

Write a string to a file inside the container.