Skip to content

fix(js-sdk): forward name param and expose names in createSnapshot#1284

Closed
FisherXZ wants to merge 5 commits intoe2b-dev:mainfrom
FisherXZ:fix/1249-snapshot-name-param
Closed

fix(js-sdk): forward name param and expose names in createSnapshot#1284
FisherXZ wants to merge 5 commits intoe2b-dev:mainfrom
FisherXZ:fix/1249-snapshot-name-param

Conversation

@FisherXZ
Copy link
Copy Markdown

@FisherXZ FisherXZ commented Apr 22, 2026

Summary

Closes #1249.

Named snapshots let users write `Sandbox.create('team/my-snapshot')` instead of tracking raw template IDs like `abc123:default`. But passing `name` to `createSnapshot()` / `create_snapshot()` silently had no effect in both SDKs — the generated REST clients were already correct, but the hand-written wrapper layer never forwarded the value or surfaced the response field.

Three layers had the same gap in both SDKs:

Layer Problem
Options type No `name` field — callers had nowhere to pass it
Request body `body: {}` / `PostSandboxesSandboxIDSnapshotsBody()` — `name` never included
`SnapshotInfo` return type Missing `names` field — API response aliases silently dropped
Paginators `listSnapshots` / `list_snapshots` had the same `names` omission

JS SDK changes (`packages/js-sdk/`):

  • Added `SnapshotCreateOpts` interface with `name?: string`
  • Added `names: string[]` to `SnapshotInfo`
  • Forwarded `name` in `SandboxApi.createSnapshot()` using `!== undefined` guard (preserves `name: ''`)
  • Fixed `SnapshotPaginator` to map `names`
  • Exported `SnapshotCreateOpts` from the package index

Python SDK changes (`packages/python-sdk/`):

  • Added `names: List[str]` to `SnapshotInfo` dataclass (`default_factory=list`)
  • Added `name: Optional[str] = None` to `_cls_create_snapshot()` in both sync and async, forwarded as `name if name is not None else UNSET`
  • Updated `create_snapshot()` overloads and implementations (sync + async)
  • Fixed both `SnapshotPaginator.next_items()` to map `names`

Backwards compatible: `name` is optional everywhere, `names` defaults to `[]`.

Usage

JS:
```ts
const snap = await sandbox.createSnapshot({ name: 'my-snapshot' })
console.log(snap.snapshotId) // 'team-slug/my-snapshot:default'
console.log(snap.names) // ['team-slug/my-snapshot:default']

// Now usable by name instead of raw ID
const sbx = await Sandbox.create('team-slug/my-snapshot')
```

Python:
```python
snap = sandbox.create_snapshot(name='my-snapshot')
print(snap.snapshot_id) # 'team-slug/my-snapshot:default'
print(snap.names) # ['team-slug/my-snapshot:default']

sbx = Sandbox.create('team-slug/my-snapshot')
```

Test plan

  • `pnpm run typecheck` — zero errors
  • `pnpm run lint` — zero errors
  • Python `make lint` (ruff check + ruff format) — all pass
  • Changeset added: `patch` bump for `e2b` (JS) and `@e2b/python-sdk`
  • Backwards compatible: `name` is optional, `names` defaults to `[]`
  • Live integration: `createSnapshot({ name: ... })` returns alias in `names` — pending backend round-trip

🤖 Generated with Claude Code

FisherXZ and others added 2 commits April 21, 2026 16:49
Adds SnapshotCreateOpts with an optional name field, threads it through
to the POST body, and adds names[] to SnapshotInfo so callers can create
named snapshots and read back their assigned aliases.

Also fixes SnapshotPaginator.nextItems() which had the same names omission.

Fixes e2b-dev#1249

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 22, 2026

🦋 Changeset detected

Latest commit: 283703f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
e2b Patch
@e2b/python-sdk Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ba584c106a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

},
body: {},
body: {
...(opts?.name && { name: opts.name }),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Forward provided snapshot name without truthy filtering

Using ...(opts?.name && { name: opts.name }) drops the name field when callers pass an empty string, so createSnapshot({ name: "" }) silently behaves like an unnamed snapshot instead of letting the API validate/reject the explicit value. This makes client behavior inconsistent with user input and can create unintended unnamed snapshots; check for undefined instead of truthiness when deciding whether to include name.

Useful? React with 👍 / 👎.

Truthy check silently drops name: '' — check !== undefined instead so
the API can validate/reject an explicit empty string rather than the
SDK quietly omitting it.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@FisherXZ FisherXZ force-pushed the fix/1249-snapshot-name-param branch from fe8b38b to e4c19b2 Compare April 22, 2026 00:09
FisherXZ and others added 2 commits April 21, 2026 17:28
Mirrors the JS SDK fix: adds optional name param to create_snapshot /
_cls_create_snapshot in both sync and async paths, maps names[] from the
API response in SnapshotInfo, and fixes the same omission in both
snapshot paginators.

Also exports SnapshotCreateOpts from the JS SDK public index and adds
a patch changeset for both packages.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
snapshot.names / res.parsed.names is already list[str] from the
generated client, so list() was an unnecessary O(n) copy. Replace
with `or []` to also guard against None for snapshots created before
the names field existed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@mishushakov
Copy link
Copy Markdown
Member

we're working on it here
#1277

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.

JS SDK: createSnapshot does not forward the 'name' parameter to the REST API

2 participants