VolumeService
Create and manage persistent volumes.
VolumeService manages persistent volumes: named, shareable directory trees that outlive any single sandbox. Attach a volume at sandbox creation via volumes=[VolumeMount(...)]; the sandbox works on a private scratch copy whose changes are committed back in the background, so they survive teardown and are visible to the next sandbox that attaches the same volume. Obtain the service as daytona.volume. See the volumes guide.
create()
Creates a volume. Volumes are ready immediately after creation.
| Parameter | Type | Default | Description |
|---|---|---|---|
name | str | — | Volume name (unique within the project). |
size_gb | int | None | Optional size in GiB; server default applies when omitted. |
Returns: the volume dict (id, name, size_gb, state, timestamps).
get()
Fetches a volume by id or name. With create=True, a missing volume is created on the fly — the Daytona-style get-or-create pattern.
| Parameter | Type | Default | Description |
|---|---|---|---|
name_or_id | str | — | Volume id or name. |
create | bool | False | Create the volume if it does not exist. |
Returns: the volume dict. Raises: DaytonaNotFoundError when missing and create=False.
list()
Lists the project's volumes. Deleted volumes are excluded unless include_deleted=True.
Returns: a list of volume dicts.
delete()
Deletes a volume. Accepts a volume dict (its id is used) or a plain id/name string. Fails with a conflict if the volume is attached to a live sandbox.
Raises: DaytonaConflictError if the volume is currently attached.
Attaching volumes: VolumeMount
Attach volumes at sandbox creation with the VolumeMount dataclass in CreateSandbox*Params.volumes. A sandbox with volumes cold-boots (it bypasses snapshot-resume templates).
| Field | Type | Default | Description |
|---|---|---|---|
volume_id | str | — | Volume id or name (resolved server-side). |
mount_path | str | — | Absolute in-sandbox mount path. |
subpath | str | None | Mount a subdirectory of the volume instead of its root. |
See using volumes for commit semantics and concurrency notes.