feat(api): Snapshot complete CRUD + enhanced SnapshotInfo - #3457
Open
AdaAibaby wants to merge 5 commits into
Open
feat(api): Snapshot complete CRUD + enhanced SnapshotInfo#3457AdaAibaby wants to merge 5 commits into
AdaAibaby wants to merge 5 commits into
Conversation
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.
There was a problem hiding this comment.
💡 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".
AdaAibaby
force-pushed
the
feat/snapshot-crud-enhanced-info
branch
from
July 30, 2026 06:33
a55223b to
cfd1a5e
Compare
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
force-pushed
the
feat/snapshot-crud-enhanced-info
branch
from
July 30, 2026 06:44
184cf5e to
2d1abe0
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)SnapshotInfo— addscpuCount,memoryMB,diskSizeMB,createdAtto both the new GET endpoint and the existing list endpointNo new DB queries: all fields come from the existing
ListTeamSnapshotTemplatesrow.Changes
spec/openapi.ymlGET/DELETE/snapshots/{snapshotID}paths; add 4 fields toSnapshotInfoschemaapi/internal/api/api.gen.goSnapshotInfostruct; add server/client interface methods, request builders, response parsers, and gin routes for both new endpointshandlers/snapshot_get.goListTeamSnapshotTemplates(limit 1) → JSON responsehandlers/snapshot_delete.gosoftDeleteTemplatereuse → cache invalidationhandlers/snapshot_template_list.goSnapshotInfofields in the list mapperTest plan
GET /snapshots/{snapshotID}returns 200 with all fields populatedGET /snapshots/{snapshotID}returns 404 for unknown snapshotDELETE /snapshots/{snapshotID}returns 204 and removes snapshotGETafterDELETEreturns 404DELETEGET /snapshotslist now includescpuCount,memoryMB,diskSizeMB,createdAt