Skip to content

Commit 8a8e564

Browse files
committed
feat: snapshots
1 parent 4af9b4c commit 8a8e564

File tree

16 files changed

+1404
-258
lines changed

16 files changed

+1404
-258
lines changed

packages/js-sdk/src/api/schema.gen.ts

Lines changed: 263 additions & 242 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/js-sdk/src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ export type {
4747
SandboxListOpts,
4848
SandboxPaginator,
4949
SandboxNetworkOpts,
50+
SnapshotInfo,
51+
SnapshotOpts,
52+
SnapshotListOpts,
53+
SnapshotPaginator,
5054
} from './sandbox/sandboxApi'
5155

5256
export type { McpServer } from './sandbox/mcp'

packages/js-sdk/src/sandbox/commands/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export { Pty } from './pty'
2828
/**
2929
* Options for sending a command request.
3030
*/
31-
export interface CommandRequestOpts
32-
extends Partial<Pick<ConnectionOpts, 'requestTimeoutMs'>> {}
31+
export interface CommandRequestOpts extends Partial<
32+
Pick<ConnectionOpts, 'requestTimeoutMs'>
33+
> {}
3334

3435
/**
3536
* Options for starting a new command.

packages/js-sdk/src/sandbox/commands/pty.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ import { CommandHandle } from './commandHandle'
2121
import { authenticationHeader, handleRpcError } from '../../envd/rpc'
2222
import { handleProcessStartEvent } from '../../envd/api'
2323

24-
export interface PtyCreateOpts
25-
extends Pick<ConnectionOpts, 'requestTimeoutMs'> {
24+
export interface PtyCreateOpts extends Pick<
25+
ConnectionOpts,
26+
'requestTimeoutMs'
27+
> {
2628
/**
2729
* Number of columns for the PTY.
2830
*/

packages/js-sdk/src/sandbox/filesystem/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ function mapModifiedTime(modifiedTime: Timestamp | undefined) {
129129
/**
130130
* Options for the sandbox filesystem operations.
131131
*/
132-
export interface FilesystemRequestOpts
133-
extends Partial<Pick<ConnectionOpts, 'requestTimeoutMs'>> {
132+
export interface FilesystemRequestOpts extends Partial<
133+
Pick<ConnectionOpts, 'requestTimeoutMs'>
134+
> {
134135
/**
135136
* User to use for the operation in the sandbox.
136137
* This affects the resolution of relative paths and ownership of the created filesystem objects.

packages/js-sdk/src/sandbox/index.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import {
1919
SandboxListOpts,
2020
SandboxPaginator,
2121
SandboxBetaCreateOpts,
22+
SnapshotOpts,
23+
SnapshotListOpts,
24+
SnapshotInfo,
25+
SnapshotPaginator,
2226
} from './sandboxApi'
2327
import { getSignature } from './signature'
2428
import { compareVersions } from 'compare-versions'
@@ -572,6 +576,52 @@ export class Sandbox extends SandboxApi {
572576
return await SandboxApi.betaPause(this.sandboxId, opts)
573577
}
574578

579+
/**
580+
* Create a snapshot of the sandbox's current state.
581+
*
582+
* The snapshot can be used to create new sandboxes with the same filesystem and state.
583+
* Snapshots are persistent and survive sandbox deletion.
584+
*
585+
* Use the returned `snapshotId` with `Sandbox.create(snapshotId)` to create a new sandbox from the snapshot.
586+
*
587+
* @param opts snapshot options.
588+
*
589+
* @returns snapshot information including the snapshot ID.
590+
*
591+
* @example
592+
* ```ts
593+
* const sandbox = await Sandbox.create()
594+
* await sandbox.files.write('/app/state.json', '{"step": 1}')
595+
*
596+
* // Create a snapshot
597+
* const snapshot = await sandbox.snapshot()
598+
*
599+
* // Create a new sandbox from the snapshot
600+
* const newSandbox = await Sandbox.create(snapshot.snapshotId)
601+
* ```
602+
*/
603+
async snapshot(opts?: SnapshotOpts): Promise<SnapshotInfo> {
604+
return await SandboxApi.createSnapshot(this.sandboxId, {
605+
...this.connectionConfig,
606+
...opts,
607+
})
608+
}
609+
610+
/**
611+
* List all snapshots created from this sandbox.
612+
*
613+
* @param opts list options.
614+
*
615+
* @returns paginator for listing snapshots from this sandbox.
616+
*/
617+
listSnapshots(opts?: Omit<SnapshotListOpts, 'sandboxId'>): SnapshotPaginator {
618+
return SandboxApi.listSnapshots({
619+
...this.connectionConfig,
620+
...opts,
621+
sandboxId: this.sandboxId,
622+
})
623+
}
624+
575625
/**
576626
*
577627
* Get the MCP URL for the sandbox.

0 commit comments

Comments
 (0)