Volumes
Volumes are FUSE-based mounts that provide shared file access across Sandboxes. They allow Sandboxes to read from large files instantly - no need to upload files manually to each Sandbox. Volume data is stored on an S3-compatible object store.
- Multiple volumes can be mounted to a single Sandbox
- A single volume can be mounted to multiple Sandboxes
Creating Volumes
Before mounting a volume to a Sandbox, it must be created.
volume = daytona.volume.get("my-volume", create=True)
const volume = await daytona.volume.get('my-volume', true)
See: volume.get (Python SDK), volume.get (TypeScript SDK)
Mounting Volumes
Once a volume is created, it can be mounted to a Sandbox by specifying it in the CreateSandboxFromSnapshotParams
object:
import osfrom daytona import CreateSandboxFromSnapshotParams, Daytona, VolumeMount
daytona = Daytona()
# Create a new volume or get an existing onevolume = daytona.volume.get("my-volume", create=True)
# Mount the volume to the sandboxmount_dir_1 = "/home/daytona/volume"
params = CreateSandboxFromSnapshotParams( language="python", volumes=[VolumeMount(volumeId=volume.id, mountPath=mount_dir_1)],)sandbox = daytona.create(params)
import { Daytona } from '@daytonaio/sdk'import path from 'path'
const daytona = new Daytona()
// Create a new volume or get an existing oneconst volume = await daytona.volume.get('my-volume', true)
// Mount the volume to the sandboxconst mountDir1 = '/home/daytona/volume'
const sandbox1 = await daytona.create({ language: 'typescript', volumes: [{ volumeId: volume.id, mountPath: mountDir1 }],})
See: CreateSandboxFromSnapshotParams (Python SDK), CreateSandboxFromSnapshotParams (TypeScript SDK)
Working with Volumes
Once mounted, you can read from and write to the volume just like any other directory in the Sandbox file system. Files written to the volume persist beyond the lifecycle of any individual Sandbox.
# Write to a file in the mounted volumewith open("/home/daytona/volume/example.txt", "w") as f: f.write("Hello from Daytona volume!")
# When you're done with the sandbox, you can remove it# The volume will persist even after the sandbox is removedsandbox.delete()
import fs from 'fs/promises'
// Write to a file in the mounted volumeawait fs.writeFile('/home/daytona/volume/example.txt', 'Hello from Daytona volume!')
// When you're done with the sandbox, you can remove it// The volume will persist even after the sandbox is removedawait daytona.delete(sandbox1)
Deleting Volumes
When a volume is no longer needed, it can be deleted.
volume = daytona.volume.get("my-volume", create=True)daytona.volume.delete(volume)
const volume = await daytona.volume.get('my-volume', true)await daytona.volume.delete(volume)
Limitations
Since volumes are FUSE-based mounts, they can not be used for applications that require block storage access (like database tables). Volumes are generally slower for both read and write operations compared to the local Sandbox file system.