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: [...]; 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 | string | — | Volume name (unique within the project). |
sizeGb | number | — | Optional size in GiB; server default applies when omitted. |
Returns: the Volume DTO (id, name, size_gb, state, timestamps).
get()
Fetches a volume by id or name. With create set to true, a missing volume is created on the fly — the Daytona-style get-or-create pattern.
| Parameter | Type | Default | Description |
|---|---|---|---|
nameOrId | string | — | Volume id or name. |
create | boolean | false | Create the volume if it does not exist. |
Returns: the Volume DTO. Throws: DaytonaNotFoundError when missing and create is false.
list()
Lists the project's volumes. Deleted volumes are excluded unless includeDeleted is true.
Returns: an array of Volume DTOs. Volume state is one of ready, deleting, deleted, or error.
delete()
Deletes a volume. Accepts a Volume DTO (its id is used) or a plain id/name string. Fails with a conflict if the volume is attached to a live sandbox.
Throws: DaytonaConflictError if the volume is currently attached.
Attaching volumes: VolumeMount
Attach volumes at sandbox creation with VolumeMount objects in volumes. A sandbox with volumes cold-boots (it bypasses snapshot-resume templates).
| Field | Type | Default | Description |
|---|---|---|---|
volumeId | string | — | Volume id or name (resolved server-side). |
mountPath | string | — | Absolute in-sandbox mount path. |
subpath | string | — | Mount a subdirectory of the volume instead of its root. |
See using volumes for commit semantics and concurrency notes.