SnapshotService
Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
Constructors
new SnapshotService()
new SnapshotService( clientConfig: Configuration, snapshotsApi: SnapshotsApi, objectStorageApi: ObjectStorageApi): SnapshotServiceParameters:
clientConfigConfigurationsnapshotsApiSnapshotsApiobjectStorageApiObjectStorageApi
Returns:
SnapshotService
Methods
activate()
activate(snapshot: Snapshot): Promise<Snapshot>Activates a snapshot.
Parameters:
snapshotSnapshot - Snapshot to activate
Returns:
Promise<Snapshot>- The activated Snapshot instance
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:
paramsCreateSnapshotParams - Parameters for snapshot creation.optionsOptions 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:
snapshotSnapshot - 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:
namestring - 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(page?: number, limit?: number): Promise<PaginatedSnapshots>List paginated list of Snapshots.
Parameters:
page?number - Page number for pagination (starting from 1)limit?number - Maximum number of items per page
Returns:
Promise<PaginatedSnapshots>- Paginated list of Snapshots
Example:
const daytona = new Daytona();const result = await daytona.snapshot.list(2, 10);console.log(`Found ${result.total} snapshots`);result.items.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));PaginatedSnapshots
Represents a paginated list of Daytona Snapshots.
Properties:
-
itemsSnapshot[] - List of Snapshot instances in the current page. -
pagenumber - Current page number.- Inherited from:
Omit.page
- Inherited from:
-
totalnumber - Total number of Snapshots across all pages.- Inherited from:
Omit.total
- Inherited from:
-
totalPagesnumber - Total number of pages available.- Inherited from:
Omit.totalPages
- Inherited from:
Extends:
Omit<PaginatedSnapshotsDto,"items">
CreateSnapshotParams
type CreateSnapshotParams = { entrypoint: string[]; image: string | Image; name: string; resources: Resources;};Parameters for creating a new snapshot.
Type declaration:
entrypoint?string[]imagestring | Imagenamestringresources?Resources
Snapshot
type Snapshot = SnapshotDto & { __brand: "Snapshot";};Represents a Daytona Snapshot which is a pre-configured sandbox.
Type declaration:
\_\_brand“Snapshot”