Skip to content

feat(api): Snapshot complete CRUD + enhanced SnapshotInfo - #3457

Open
AdaAibaby wants to merge 5 commits into
e2b-dev:mainfrom
AdaAibaby:feat/snapshot-crud-enhanced-info
Open

feat(api): Snapshot complete CRUD + enhanced SnapshotInfo#3457
AdaAibaby wants to merge 5 commits into
e2b-dev:mainfrom
AdaAibaby:feat/snapshot-crud-enhanced-info

Conversation

@AdaAibaby

@AdaAibaby AdaAibaby commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #3456
Depends on #3441 (must merge first — this branch includes the fork endpoint commit as its parent)

  • GET /snapshots/{snapshotID} — retrieve a single snapshot by ID or alias (404 if not found/not owned)
  • DELETE /snapshots/{snapshotID} — soft-delete a snapshot template and release its aliases (204 on success)
  • Enhanced SnapshotInfo — adds cpuCount, memoryMB, diskSizeMB, createdAt to both the new GET endpoint and the existing list endpoint

No new DB queries: all fields come from the existing ListTeamSnapshotTemplates row.

Changes

File Change
spec/openapi.yml Add GET/DELETE /snapshots/{snapshotID} paths; add 4 fields to SnapshotInfo schema
api/internal/api/api.gen.go Update SnapshotInfo struct; add server/client interface methods, request builders, response parsers, and gin routes for both new endpoints
handlers/snapshot_get.go New handler — alias resolution → ListTeamSnapshotTemplates (limit 1) → JSON response
handlers/snapshot_delete.go New handler — alias resolution → softDeleteTemplate reuse → cache invalidation
handlers/snapshot_template_list.go Populate 4 new SnapshotInfo fields in the list mapper

Test plan

  • GET /snapshots/{snapshotID} returns 200 with all fields populated
  • GET /snapshots/{snapshotID} returns 404 for unknown snapshot
  • DELETE /snapshots/{snapshotID} returns 204 and removes snapshot
  • GET after DELETE returns 404
  • Other snapshots unaffected after a targeted DELETE
  • GET /snapshots list now includes cpuCount, memoryMB, diskSizeMB, createdAt

Implements Proposal B from issue e2b-dev#3424: fork N sandboxes from a named
snapshot template without requiring the original sandbox to still be running.

Why

RL/agent training workloads need to checkpoint once then run many
evaluation batches from that checkpoint:

  1. Create sandbox, load model weights / install deps (expensive)
  2. Snapshot the sandbox to a named checkpoint (e.g. "team/rl-v1")
  3. Kill original sandbox -- no longer needed
  4. Per training batch: fork N episode sandboxes, run rollouts, kill
  5. Repeat step 4 indefinitely from the same checkpoint

Before this change step 4 was impossible after step 3. The only
alternatives were fork-from-running-sandbox (keeps the source alive,
wastes resources) or N fresh sandboxes (no shared checkpoint, slow).

What

New endpoint: POST /snapshots/{snapshotID}/fork

Request body (same schema as POST /sandboxes/{id}/fork):
  count    int -- number of forks (default 1, max 100)
  timeout  int -- TTL for each fork in seconds

Returns 201 with a list of SandboxForkResult entries, one per requested
fork. Each entry carries either {sandbox: ...} (success) or {error: ...}
(failure), so a partial batch is still useful.

Implementation note: templateCache vs snapshotCache

Ephemeral pause snapshots (source=snapshot) are soft-deleted when the
sandbox is killed -- their deleted_at is set and active_envs returns
nothing, so snapshotCache.Get returns 404 for killed sandboxes.

Named snapshot templates (source=snapshot_template) are persistent: they
survive sandbox deletion and are never touched by the kill path. This
handler resolves the alias via templateCache.ResolveAlias, then fetches
build data from env_build_assignments for the persistent template env --
the same path POST /sandboxes uses to start from a template.

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

Copy link
Copy Markdown

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: 0af41b0c51

ℹ️ 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".

Comment thread packages/api/internal/handlers/snapshot_fork.go
Comment thread packages/api/internal/handlers/snapshot_fork.go Outdated
Comment thread spec/openapi.yml
@AdaAibaby
AdaAibaby force-pushed the feat/snapshot-crud-enhanced-info branch from a55223b to cfd1a5e Compare July 30, 2026 06:33
AdaAibaby and others added 4 commits July 30, 2026 14:33
Unlike /sandboxes/{id}/fork where the source sandbox occupies a slot,
/snapshots/{id}/fork has no running source sandbox. Using >= rejected
count == limit even when all slots were free. Changed to > so users can
fork up to their full concurrency limit in one request.
- Add GET /snapshots/{snapshotID}: returns SnapshotInfo for a single snapshot
- Add DELETE /snapshots/{snapshotID}: soft-deletes a snapshot template (reuses
  softDeleteTemplate, invalidates template cache)
- Extend SnapshotInfo with cpuCount, memoryMB, diskSizeMB, createdAt fields
- Update GET /snapshots list to populate the new fields
- Update spec/openapi.yml and regenerate api.gen.go accordingly

Closes e2b-dev#3456
… create response

POST /sandboxes/{id}/snapshots was returning zero values for the four new
required SnapshotInfo fields. Populate them from the source sandbox, which
already has VCpu, RamMB, TotalDiskSizeMB in memory at the point of return.
@AdaAibaby
AdaAibaby force-pushed the feat/snapshot-crud-enhanced-info branch from 184cf5e to 2d1abe0 Compare July 30, 2026 06:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(api): Snapshot complete CRUD + enhanced SnapshotInfo

2 participants