Skip to content
View as Markdown

Service for managing Daytona Snapshots.

Provides operations to create, list, retrieve, and delete snapshots.

public Snapshot create(String name, String imageName)

Creates a snapshot from an existing image reference.

Parameters:

  • name String - snapshot name
  • imageName String - source image name or tag

Returns:

  • Snapshot - created Snapshot

Throws:

  • io.daytona.sdk.exception.DaytonaException - if the API request fails
public Snapshot create(String name, String imageName, SandboxClass sandboxClass)

Creates a snapshot from an existing image reference with a target sandbox class.

Parameters:

  • name String - snapshot name
  • imageName String - source image name or tag
  • sandboxClass SandboxClass - target sandbox class; null for default

Returns:

  • Snapshot - created Snapshot

Throws:

  • io.daytona.sdk.exception.DaytonaException - if the API request fails
public Snapshot create(String name, Image image, Consumer<String> onLogs)

Creates a snapshot from a declarative Image with optional build log streaming.

Parameters:

  • name String - snapshot name
  • image Image - declarative image definition
  • onLogs Consumer<String> - callback for build log lines; null to skip streaming

Returns:

  • Snapshot - created Snapshot in active or error state

Throws:

  • DaytonaException - if the API request fails or the build fails
public Snapshot create(String name, Image image, io.daytona.sdk.model.Resources resources, Consumer<String> onLogs)

Creates a snapshot from a declarative Image with resources and optional build log streaming.

Parameters:

  • name String - snapshot name
  • image Image - declarative image definition
  • resources io.daytona.sdk.model.Resources - CPU/GPU/memory/disk resources; null for defaults
  • onLogs Consumer<String> - callback for build log lines; null to skip streaming

Returns:

  • Snapshot - created Snapshot in active or error state

Throws:

  • DaytonaException - if the API request fails or the build fails
public Snapshot create(String name, Image image, io.daytona.sdk.model.Resources resources, SandboxClass sandboxClass, Consumer<String> onLogs)

Creates a snapshot from a declarative Image with resources, sandbox class, and optional build log streaming.

Parameters:

  • name String - snapshot name
  • image Image - declarative image definition
  • resources io.daytona.sdk.model.Resources - CPU/GPU/memory/disk resources; null for defaults
  • sandboxClass SandboxClass - target sandbox class; null for default
  • onLogs Consumer<String> - callback for build log lines; null to skip streaming

Returns:

  • Snapshot - created Snapshot in active or error state

Throws:

  • DaytonaException - if the API request fails or the build fails
public PaginatedSnapshots list(Integer page, Integer limit)

Lists snapshots with pagination.

try (Daytona daytona = new Daytona()) {
PaginatedSnapshots page = daytona.snapshot().list(2, 10);
System.out.printf("Page %d of %d (%d snapshots total)%n",
page.getPage(), page.getTotalPages(), page.getTotal());
for (var snapshot : page.getItems()) {
System.out.println(snapshot.getName() + " (" + snapshot.getImageName() + ")");
}
}

Parameters:

  • page Integer - page number starting from 1; defaults to 1 when null
  • limit Integer - maximum number of items per page; defaults to 10 when null

Returns:

  • PaginatedSnapshots - paginated snapshot result

Throws:

  • io.daytona.sdk.exception.DaytonaException - if the API request fails
public PaginatedSnapshots list(Integer page, Integer limit, String sourceSandboxId)

Lists snapshots with pagination, optionally filtered by source sandbox.

Parameters:

  • page Integer - page number starting from 1; defaults to 1 when null
  • limit Integer - maximum number of items per page; defaults to 10 when null
  • sourceSandboxId String - filter by the ID of the sandbox the snapshot was created from; ignored when null

Returns:

  • PaginatedSnapshots - paginated snapshot result

Throws:

  • io.daytona.sdk.exception.DaytonaException - if the API request fails
public Snapshot get(String nameOrId)

Retrieves a snapshot by name or ID.

Parameters:

  • nameOrId String - snapshot name or identifier

Returns:

  • Snapshot - matching Snapshot

Throws:

  • io.daytona.sdk.exception.DaytonaException - if no snapshot is found or request fails
public void delete(String nameOrId)

Deletes a snapshot by ID or name.

Snapshot names may themselves be UUID-formatted, so a UUID-shaped input is first tried directly against the ID-only delete endpoint (1 call) and only resolved through the ID-or-name GET /snapshots lookup on a 404. Non-UUID input is resolved first (2 calls); a UUID-formatted name costs 3 calls in the worst case.

Parameters:

  • nameOrId String - snapshot identifier or name

Throws:

  • io.daytona.sdk.exception.DaytonaException - if deletion fails
public void delete(Snapshot snapshot)

Deletes a snapshot using its already-known identifier.

Issues a single delete call — no resolution is performed.

Parameters:

  • snapshot Snapshot - snapshot to delete; its Snapshot#getId() id is used verbatim

Throws:

  • io.daytona.sdk.exception.DaytonaException - if deletion fails
public Snapshot activate(String nameOrId)

Activates a snapshot by ID or name.

Snapshot names may themselves be UUID-formatted, so a UUID-shaped input is first tried directly against the ID-only activate endpoint (1 call) and only resolved through the ID-or-name GET /snapshots lookup on a 404. Non-UUID input is resolved first (2 calls); a UUID-formatted name costs 3 calls in the worst case.

Parameters:

  • nameOrId String - snapshot identifier or name

Returns:

  • Snapshot - the activated Snapshot

Throws:

  • io.daytona.sdk.exception.DaytonaException - if activation fails or no snapshot is found
public Snapshot activate(Snapshot snapshot)

Activates a snapshot using its already-known identifier.

Issues a single activate call — no resolution is performed.

Parameters:

  • snapshot Snapshot - snapshot to activate; its Snapshot#getId() id is used verbatim

Returns:

  • Snapshot - the activated Snapshot

Throws:

  • io.daytona.sdk.exception.DaytonaException - if activation fails