What a Volume is#

A Volume is Yak-managed durable filesystem state. Its files remain available across Task Invocations until a client or Task changes or removes them. Use a Volume for checkpoints, generated artifacts or shared files that later Invocations must read. See Storage choices to compare it with external object storage and disposable scratch.

Create and resolve a Volume#

Create a Volume in the selected Environment with the CLI:

bash
yak volume create quickstart-checkpoints --environment development
yak volume list --environment development

The Python SDK can strictly resolve an existing name with Volume.get(...), create one with Volume.create(...), or use Volume.from_name(...) to atomically resolve-or-create by default. Volume names are scoped to an Environment. CLI commands accept --environment; the SDK uses the selected environment, defaulting to development when omitted.

Client-side small-file staging#

Volume.open(path, mode) gives the client a staged view for small files. Writes and deletes remain in local SDK staging until publish() sends them to the durable Volume. discard_staged() drops local edits that have not been published. If publishing fails part-way through, successfully published files are no longer staged and unfinished files remain staged for retry.

Use upload() and download() for file transfers and directory trees. Those methods stream directly between the client and durable Volume; they do not go through the small-file staging map and do not require publish().

python
volume = yak.Volume.from_name("quickstart-checkpoints")
with volume.open("reports/summary.txt", "w") as file:
    file.write("ready\n")
volume.publish()

volume.download("reports/summary.txt", "./summary.txt")

The canonical example below also mounts a published subtree read-only into a Task.

Mount a Volume into a Task#

Declare a Volume in @app.task(volumes=...). Use volume.mount(read_only=True) to reject writes through that Task mount, or use subpath to expose a durable subtree as the mount root:

python
volume = yak.Volume.from_name("quickstart-checkpoints")

@app.task(volumes={"/checkpoint": volume.mount(read_only=True, subpath="reports")})
def read_checkpoint() -> str:
    from pathlib import Path
    return Path("/checkpoint/summary.txt").read_text()

SDK file operations and mounted filesystem access are two interfaces to the same durable Volume. Client-side staging is explicit; writes through a writable Task mount are filesystem writes rather than entries in the client’s staged map.

CLI operations#

The CLI supports yak volume create, get, list, ls, upload, download, remove, cp, mv, and delete (rm is an alias for deleting a whole Volume). Use --recursive for directory-tree transfers and operations that act on a directory. Use --json when a script needs structured command output. Check yak volume <command> --help for the exact positional arguments and options in the installed release.

Failures and limits#

An unknown Volume name raises VolumeNotFoundError in the SDK. Whole-Volume lifecycle conflicts can raise VolumeAlreadyExistsError, VolumeInUseError or VolumeConflictError; file operations use familiar FileNotFoundError and FileExistsError where appropriate. A read-only mount rejects mutations from the Task. See Troubleshooting for how to separate storage errors from Task failures.