Skip to content

feat(js): add experimental sandbox memory snapshot support#233

Open
willydouhard wants to merge 1 commit intomodal-labs:mainfrom
willydouhard:feat/sandbox-snapshots
Open

feat(js): add experimental sandbox memory snapshot support#233
willydouhard wants to merge 1 commit intomodal-labs:mainfrom
willydouhard:feat/sandbox-snapshots

Conversation

@willydouhard
Copy link

@willydouhard willydouhard commented Dec 4, 2025

Summary

  • Add experimental memory snapshot support to the JavaScript/TypeScript SDK
  • Add SandboxSnapshot class and _experimentalSnapshot() / _experimentalFromSnapshot() methods for creating and restoring sandbox memory snapshots
  • Add experimentalOptions parameter to SandboxCreateParams for server-side feature flags
  • Fix missing forcePathStyle field in CloudBucketMount proto conversion

Changes

New Features

  • sandbox._experimentalSnapshot(): Takes a memory snapshot of a running sandbox
  • sandboxes._experimentalFromSnapshot(snapshot, params): Restores a sandbox from a snapshot
  • SandboxSnapshot class: Represents a stored sandbox snapshot
  • _experimentalEnableSnapshot option in SandboxCreateParams: Enables memory snapshots for a sandbox
  • experimentalOptions in SandboxCreateParams: Pass experimental feature flags to the server

Bug Fixes

  • Added missing forcePathStyle: false to CloudBucketMount.toProto()

Test Plan

  • Added unit tests for buildSandboxCreateRequestProto with new experimental options
  • Manual testing of snapshot/restore functionality with a live Modal environment

Note

Adds experimental sandbox memory snapshot create/restore APIs, exposes SandboxSnapshot, supports experimental options in create params, and fixes missing forcePathStyle in cloud bucket mount proto.

  • Sandbox (experimental snapshots):
    • Add Sandbox#_experimentalSnapshot() to create memory snapshots and wait for completion.
    • Add SandboxService#_experimentalFromSnapshot() to restore from SandboxSnapshot with optional name override handling.
    • Introduce SandboxSnapshot class and SandboxFromSnapshotParams type.
    • Extend SandboxCreateParams with experimentalOptions and _experimentalEnableSnapshot; include experimentalOptions and enableSnapshot in create request proto.
  • Exports:
    • Export SandboxSnapshot and SandboxFromSnapshotParams from index.ts.
  • Cloud bucket mounts:
    • Include forcePathStyle: false in CloudBucketMount#toProto().
  • Tests:
    • Add unit tests covering experimentalOptions, _experimentalEnableSnapshot, and their defaults in buildSandboxCreateRequestProto.

Written by Cursor Bugbot for commit f90f057. This will update automatically on new commits. Configure here.

Add support for experimental memory snapshots in the JavaScript/TypeScript SDK:
- Add `_experimentalEnableSnapshot` option to `SandboxCreateParams`
- Add `experimentalOptions` for server-side feature flags
- Add `SandboxSnapshot` class for snapshot management
- Add `_experimentalSnapshot()` method on `Sandbox` to create snapshots
- Add `_experimentalFromSnapshot()` method on `SandboxService` to restore from snapshots
- Fix missing `forcePathStyle` in CloudBucketMount proto conversion
sandboxId: this.sandboxId,
});

const snapshotId = snapResp.snapshotId;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Missing validation for snapshotId from API response

The _experimentalSnapshot method uses snapResp.snapshotId without validating it exists. If the API response is missing snapshotId, it would pass an undefined/empty value to sandboxSnapshotWait and return a SandboxSnapshot with an invalid ID. The analogous snapshotFilesystem method validates resp.imageId before use with a check like if (!resp.imageId) throw new Error(...).

Fix in Cursor Fix in Web

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant