SnapshotService
Service for managing Daytona Snapshots. Can be used to list, get, create and delete Snapshots.
Constructors
Constructor
new SnapshotService(
clientConfig: Configuration,
snapshotsApi: SnapshotsApi,
objectStorageApi: ObjectStorageApi,
defaultRegionId?: string): SnapshotService;Parameters:
clientConfigConfigurationsnapshotsApiSnapshotsApiobjectStorageApiObjectStorageApidefaultRegionId?string
Returns:
SnapshotService
Methods
activate()
activate(snapshot: string | Snapshot): Promise<Snapshot>;Activates a snapshot.
Parameters:
snapshotstring | Snapshot - Snapshot to activate, or its ID or name
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.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: string | Snapshot): Promise<void>;Deletes a Snapshot.
Parameters:
snapshotstring | Snapshot - Snapshot to delete, or its ID or name
Returns:
Promise<void>
Throws:
If the Snapshot does not exist or cannot be deleted
Example:
const daytona = new Daytona();
await daytona.snapshot.delete("snapshot-name");
console.log("Snapshot deleted successfully");get()
get(idOrName: string): Promise<Snapshot>;Gets a Snapshot by its ID or name.
Parameters:
idOrNamestring - ID or 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()
Call Signature
list(query?: ListSnapshotsQuery): Promise<PaginatedSnapshots>;List paginated list of Snapshots.
Parameters:
query?ListSnapshotsQuery - Pagination and filter options
Returns:
Promise<PaginatedSnapshots>- Paginated list of Snapshots
Example:
const daytona = new Daytona();
const { items, total, page: currentPage, totalPages } = await daytona.snapshot.list({ page: 2, limit: 10 });
console.log(`Page ${currentPage} of ${totalPages} (${total} snapshots total)`);
items.forEach(snapshot => console.log(`${snapshot.name} (${snapshot.imageName})`));Call Signature
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
Deprecated
Use list(query) with a ListSnapshotsQuery object instead.
ListSnapshotsQuery
Properties:
limit?number - Maximum number of items per pagepage?number - Page number for pagination (starting from 1)sourceSandboxId?string - Filter by the ID of the sandbox the snapshot was created from
PaginatedSnapshots
Represents a paginated list of Daytona Snapshots.
Properties:
-
itemsSnapshot[] - List of Snapshot instances in the current page. -
pagenumber - Current page number.- Inherited from:
PaginatedSnapshotsDto.page
- Inherited from:
-
totalnumber - Total number of Snapshots across all pages.- Inherited from:
PaginatedSnapshotsDto.total
- Inherited from:
-
totalPagesnumber - Total number of pages available.- Inherited from:
PaginatedSnapshotsDto.totalPages
- Inherited from:
Extends:
Omit<PaginatedSnapshotsDto,"items">
CreateSnapshotParams
type CreateSnapshotParams = {
entrypoint?: string[];
image: string | Image;
name: string;
regionId?: string;
resources?: Resources;
sandboxClass?: SandboxClass;
};Properties:
entrypoint?string[] - Entrypoint of the snapshot.imagestring | Image - Image of the snapshot. If a string is provided, it should be available on some registry. If an Image instance is provided, it will be used to create a new image in Daytona.namestring - Name of the snapshot.regionId?string - ID of the region where the snapshot will be available. Defaults to organization default region if not specified.resources?Resources - Resources of the snapshot.sandboxClass?SandboxClass - Target sandbox class. Determines which runners can host sandboxes created from this snapshot.
Parameters for creating a new snapshot.
Snapshot
type Snapshot = SnapshotDto & {
__brand: "Snapshot";
};Represents a Daytona Snapshot which is a pre-configured sandbox.
Type Declaration
__brand
__brand: "Snapshot";