DaytonaDocs

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.

Python
def create(name: str, size_gb: int | None = None) -> Dict[str, Any]
ParameterTypeDefaultDescription
namestrVolume name (unique within the project).
size_gbintNoneOptional size in GiB; server default applies when omitted.

Returns: the volume dict (id, name, size_gb, state, timestamps).

Python
vol = daytona.volume.create("datasets", size_gb=50)

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.

Python
def get(name_or_id: str, create: bool = False) -> Dict[str, Any]
ParameterTypeDefaultDescription
name_or_idstrVolume id or name.
createboolFalseCreate the volume if it does not exist.

Returns: the volume dict. Raises: DaytonaNotFoundError when missing and create=False.

Python
vol = daytona.volume.get("datasets", create=True)

list()

Lists the project's volumes. Deleted volumes are excluded unless include_deleted=True.

Python
def list(include_deleted: bool = False) -> List[Dict[str, Any]]

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.

Python
def delete(volume: Dict[str, Any]) -> None

Raises: DaytonaConflictError if the volume is currently attached.

Python
daytona.volume.delete(daytona.volume.get("datasets"))

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).

Python
from rlp import CreateSandboxFromImageParams, VolumeMount
 
sandbox = daytona.create(CreateSandboxFromImageParams(
    image="python:3.12-slim",
    volumes=[VolumeMount(volume_id="datasets", mount_path="/data")],
))
FieldTypeDefaultDescription
volume_idstrVolume id or name (resolved server-side).
mount_pathstrAbsolute in-sandbox mount path.
subpathstrNoneMount a subdirectory of the volume instead of its root.

See using volumes for commit semantics and concurrency notes.

On this page