Skip to content

feat(vercel-sandbox,sandbox): introduce keepLast parameters for SDK/CLI#193

Merged
marc-vercel merged 4 commits into
mainfrom
marc-vercel/keep-last-snapshots
May 15, 2026
Merged

feat(vercel-sandbox,sandbox): introduce keepLast parameters for SDK/CLI#193
marc-vercel merged 4 commits into
mainfrom
marc-vercel/keep-last-snapshots

Conversation

@marc-vercel
Copy link
Copy Markdown
Collaborator

@marc-vercel marc-vercel commented May 15, 2026

Re-apply #164, which was closed.

CLI

sandbox create accepts retention policy flags. By default, evicted snapshots are deleted immediately; pass --delete-evicted-snapshots false to let them fall back to the sandbox's default expiration instead.

> sandbox create --keep-last-snapshots 3
> sandbox create --keep-last-snapshots 3 --keep-last-snapshots-for 7d
> sandbox create --keep-last-snapshots 5 --keep-last-snapshots-for 30d --delete-evicted-snapshots false

The sandbox config command exposes one subcommand per retention field. The two modifier subcommands (keep-last-snapshots-for, delete-evicted-snapshots) require an existing policy.

> sandbox config keep-last-snapshots my-sandbox 3
> sandbox config keep-last-snapshots-for my-sandbox 7d
> sandbox config delete-evicted-snapshots my-sandbox false

# Pass 0 to remove the policy:
> sandbox config keep-last-snapshots my-sandbox 0

sandbox config list includes a new "Keep last snapshots" row:

> sandbox config list my-sandbox

FIELD                 VALUE
vCPUs                 2
Timeout               10 minutes
Persistent            true
Network policy        restricted
Snapshot expiration   7 days
Keep last snapshots   count=3, for=7 days, delete-evicted-snapshots=true
Current snapshot      -
Tags                  -

SDK

Sandbox.create and Sandbox.update accept a new optional keepLastSnapshots field.

const sandbox = await Sandbox.create({
  keepLastSnapshots: {
    count: 3,
    expiration: 7 * 24 * 60 * 60 * 1000,   // ms, 0 = never. Falls back to snapshotExpiration when omitted.
    deleteEvicted: true,                    // default true
  },
});

On Sandbox.update, pass null to remove the policy:

await sandbox.update({ keepLastSnapshots: null });

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 15, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
sandbox Ready Ready Preview, Comment, Open in v0 May 15, 2026 9:14am
sandbox-cli Ready Ready Preview, Comment, Open in v0 May 15, 2026 9:14am
sandbox-sdk Ready Ready Preview, Comment, Open in v0 May 15, 2026 9:14am
sandbox-sdk-ai-example Ready Ready Preview, Comment, Open in v0 May 15, 2026 9:14am
workflow-code-runner Ready Ready Preview, Comment, Open in v0 May 15, 2026 9:14am

- sandbox.test.ts: wrap the new clear-keepLastSnapshots test in
  try/finally so the persistent sandbox is deleted on success and
  failure, matching the surrounding tests.
- validators.ts: make keepLastSnapshots.deleteEvicted optional to
  match the input types and the SDK getter.
- sandbox.ts: align getter type with the validator.
- config.ts: only render delete-evicted-snapshots=... in
  formatKeepLastSnapshots when the field is set, matching the
  success message behavior.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the single `sandbox config keep-last-snapshots` command (which used
flags for expiration and delete-evicted behavior) with three subcommands:

- `keep-last-snapshots <name> <count>` — count, 0 clears the policy
- `keep-last-snapshots-for <name> <duration|none>` — expiration
- `delete-evicted-snapshots <name> <true|false>` — eviction behavior

The two new subcommands fetch the existing policy and merge to preserve
unrelated fields. They error if no policy is set yet.
@marc-vercel marc-vercel merged commit c6bd09c into main May 15, 2026
14 checks passed
@marc-vercel marc-vercel deleted the marc-vercel/keep-last-snapshots branch May 15, 2026 12:26
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.

3 participants