SnapshotService
Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
Constructors
new SnapshotService()
new SnapshotService(snapshotsApi: SnapshotsApi, objectStorageApi: ObjectStorageApi): SnapshotService
Parameters:
snapshotsApi
SnapshotsApiobjectStorageApi
ObjectStorageApi
Returns:
SnapshotService
Methods
create()
create(params: CreateSnapshotParams, options: { onLogs: (chunk: string) => void; timeout: number;}): Promise<Snapshot>
Creates and registers a new snapshot from the given Image definition.
Parameters:
params
CreateSnapshotParams - Parameters for snapshot creation.options
Options for the create operation.onLogs?
(chunk: string) => void - This callback function handles snapshot creation logs.timeout?
number - Default is no timeout. Timeout in seconds (0 means no timeout).
Returns:
Promise<Snapshot>
Example:
const image = Image.debianSlim('3.12').pipInstall('numpy');await daytona.snapshot.create({ name: 'my-snapshot', image: image }, { onLogs: console.log });
delete()
delete(snapshot: Snapshot): Promise<void>
Deletes a Snapshot.
Parameters:
snapshot
Snapshot - Snapshot to delete
Returns:
Promise<void>
Throws:
If the Snapshot does not exist or cannot be deleted
Example:
const daytona = new Daytona();const snapshot = await daytona.snapshot.get("snapshot-name");await daytona.snapshot.delete(snapshot);console.log("Snapshot deleted successfully");
get()
get(name: string): Promise<Snapshot>
Gets a Snapshot by its name.
Parameters:
name
string - Name of the Snapshot to retrieve
Returns:
Promise<Snapshot>
- The requested Snapshot
Throws:
If the Snapshot does not exist or cannot be accessed
Example:
const daytona = new Daytona();const snapshot = await daytona.snapshot.get("snapshot-name");console.log(`Snapshot ${snapshot.name} is in state ${snapshot.state}`);
list()
list(): Promise<Snapshot[]>
List all Snapshots.
Returns:
Promise<Snapshot[]>
- List of all Snapshots accessible to the user
Example:
const daytona = new Daytona();const snapshots = await daytona.snapshot.list();console.log(`Found ${snapshots.length} snapshots`);snapshots.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));
CreateSnapshotParams
type CreateSnapshotParams = { entrypoint: string[]; image: string | Image; name: string; resources: Resources;};
Parameters for creating a new snapshot.
Type declaration:
entrypoint?
string[]image
string | Imagename
stringresources?
Resources
Snapshot
type Snapshot = SnapshotDto & { __brand: "Snapshot";};
Represents a Daytona Snapshot which is a pre-configured sandbox.
Type declaration:
\_\_brand
“Snapshot”