Skip to content

Images

The daemon holds the images sandboxes start from: those of the kits, and the templates saved from sandboxes. client.images lists, pulls, reads, moves and removes them. This page covers each of those.

docs_src/client/images.py
import fastsandbox


async def main() -> None:
    client = await fastsandbox.connect()
    images = client.images
    for image in await images.list():
        print(f"{image.reference} {image.size or 0} bytes")

    # A pull followed as it happens; `images.pull()` waits for its end instead.
    reference = "docker.io/sbx/shell:latest"
    async with await images.pull_stream(reference) as progress:
        async for line in progress:
            if line.error is not None:
                raise RuntimeError(f"pull failed: {line.error}")
            print(f"pull: {line.status}")

    details = await images.inspect(reference)
    print(f"{reference}: user {details.user}, entrypoint {details.entrypoint}")
    print(f"unknown image held: {await images.exists('docker.io/library/no-such:image')}")


if __name__ == "__main__":
    fastsandbox.run(main())

Listing and reading

Call Gives
list() every image, untagged ones included, as ImageSummary; reference names it
exists(reference) whether the daemon holds it
inspect(reference) its details, an ImageInspect: user, entrypoint, command, agent; NotFoundError for an image the daemon does not hold
local_metadata(reference) whether it is a locally saved snapshot; an unknown image gives the defaults, not an error

Pulling

  • pull(reference) pulls an image and waits for the outcome. A pull the registry refuses raises an ApiError, such as 403 registry_access_denied; a failure reported during the pull, an OperationFailedError. When the registry refuses a pull, a cached copy is used, as the CLI does.
  • pull_stream(reference) pulls it and streams its progress, a PullProgress per line: a status, the layer id, the byte counts of progress_detail, and an error, always the last line of a failed pull. Layers report the same status many times.

Pulls are long operations: their deadline is the long-operation deadline of the client (see Deadlines). The images of a kit are loaded from its package when a sandbox is created; forging the package pulls the image of its base kit, once (see Kits).

Moving images

An image moves between daemons as an archive, in the docker save format:

A template saved from a sandbox (see Templates) goes to another host this way:

with open("my-snapshot.tar", "wb") as file:
    async for chunk in await client.images.export_stream("my-snapshot:v1"):
        file.write(chunk)
# On the other host:
await other.images.load_file("my-snapshot.tar")