Skip to content
News

AI insights

Vercel Sandbox Lifecycle Webhooks: Auto-Extend Sessions

Learn how Vercel Sandbox's started, expiring, and stopped webhooks work with Vercel MCP and Workflow SDK to auto-extend agent sessions without polling.

Vercel Sandbox Lifecycle Webhooks: Auto-Extend Sessions

Q. How can you prevent long-running agent tasks on Vercel Sandbox from hitting a timeout mid-execution without polling? With Vercel Sandbox session lifecycle webhooks introduced on November 30, 2026, your backend or agent can subscribe to sandbox.session.expiring and extend the session 1 minute before timeout (or at a custom lead time). You can chain extensions through a webhook handler, Vercel MCP events, or Workflow SDK hooks, and capture CPU and network usage when the session stops.

⚠️ Accuracy guardrail: This article is based on the Vercel Changelog (published November 30, 2026), the Sandbox Lifecycle Webhooks documentation, and the Vercel MCP tool reference as of December 2, 2026. Upper bounds on webhook delivery latency and per-plan webhook endpoint quotas are not published in those docs and are omitted here; plan requirements and behavior may change with future updates.

30-second summary

  • Three lifecycle events: Teams can subscribe to sandbox.session.started, sandbox.session.expiring, and sandbox.session.stopped.
  • Automatic extension loop: expiring fires 1 minute before timeout by default (configurable via expiryNotificationLeadTime from 60s to 1h). Calling extendTimeout() or MCP extend_session_timeout schedules a fresh warning before the new deadline.
  • Stop reasons and usage: stopped events include stopReason (requested, snapshot, timeout, exited, or error), duration, activeCpuDurationMs, and networkTransfer (ingress and egress bytes).
  • Idempotency is mandatory: Events may arrive more than once with a new event id or out of order, so deduplicate by event.type + payload.session.id (plus payload.sandbox.expiresAt for expiring events).

Vercel Sandbox lifecycle webhooks and Workflow SDK extension flow

Why lifecycle webhooks beat polling

When an agent builds a repository or drives a headless browser inside a sandbox, total runtime is hard to predict upfront. Previously, teams either polled the Sandbox API on a timer or set oversized timeouts that risked wasted active CPU overhead.

Lifecycle webhooks push state transitions to your backend even for sessions started or stopped by another caller. If you are already combining persistent storage from Vercel Drives CLI and standalone SDK or live desktop streaming with Vercel Sandbox screen-relay, event-driven hooks let you extend active sessions and clean up right as they end.

Q. Are Sandbox lifecycle webhooks available on the Hobby plan? According to the official documentation, subscribing to account webhooks requires a Pro or Enterprise team with permission to configure team webhooks.

Advertisement

The three events and payload fields

Every event carries payload.team.id, payload.project.id, payload.sandbox (name, currentSessionId, currentSnapshotId, status, expiresAt, expiryNotificationLeadTime), and payload.session (id, status, startedAt). Sessions that fail to start emit no events, and payload.user.id is always null.

Event name Triggered when Typical action
sandbox.session.started After creating or resuming a sandbox Mark job state as running
sandbox.session.expiring 1 minute before timeout (default) Extend timeout if active, or save state
sandbox.session.stopped After stop time, usage, and snapshot are saved Record stopReason, CPU/network usage, cleanup

Stopped events also add stoppedAt, stopReason, duration (ms), activeCpuDurationMs (ms), and networkTransfer (ingress and egress in bytes). As the docs note, stopReason explains how the sandbox stopped—not whether the task inside succeeded.

Official Vercel Changelog announcement for Sandbox session lifecycle webhooks

Expiry warnings and the extension timeline

By default, Vercel sends sandbox.session.expiring 1 minute before a session times out. If your workload needs more time to wrap up or snapshot, pass expiryNotificationLeadTime in milliseconds—between 60000 (1 minute) and 3600000 (1 hour)—when creating, forking, or updating a sandbox via the REST API.

In a 10-minute session, expiring arrives at 9:00. If your handler calls sandbox.extendTimeout() (TypeScript SDK) or extend_execution_time_limit() (Python SDK) at 9:30 to add 5 minutes, the deadline shifts to 15:00 and a new warning fires at 14:00. Note that requesting an extension cancels the pending warning for the old deadline—if the extension call fails, no second warning arrives for the original timeout, so tracking payload.sandbox.expiresAt in your own code remains good practice.

Vercel MCP, Workflow SDK, and duplicate delivery

Agents connected via Vercel MCP can subscribe to the same team-wide lifecycle events and call extend_session_timeout (requiring sessionId) whenever sandbox.session.expiring arrives. With Vercel Workflow SDK, defineHook<SandboxSessionEvent>() lets a workflow await for await (const { type } of sandboxHook) without polling, extending via extendSession(sandboxName, ms('10m')) while work is active and breaking on sandbox.session.stopped.

if (event.type === 'sandbox.session.stopped') {
  const { id, stopReason, activeCpuDurationMs, networkTransfer } =
    event.payload.session;
  console.log({ id, stopReason, activeCpuDurationMs, networkTransfer });
}

Always verify the x-vercel-signature header before trusting any webhook payload. Because Vercel can deliver an event more than once with a fresh id, and started/stopped can arrive out of order, key idempotency on (event.type, payload.session.id)—plus payload.sandbox.expiresAt for expiring events—and fetch current sandbox state if needed before taking action.

Developer workspace inspecting webhook payloads and logs

Toris's take

When to adopt right away: If you run multi-minute AI coding, testing, or browser agents on Vercel Sandbox under a Pro or Enterprise team, pairing a short initial timeout with expiring-driven extensions avoids both premature cutoffs and idle over-provisioning.

When to keep it simple: If you are on a Hobby plan or your sandbox tasks consistently finish within a minute or two, managing expiresAt directly from the caller avoids extra webhook infrastructure. For mission-critical jobs, pair expiring hooks with local expiresAt tracking and snapshots in case an extension call fails.

Sources

Advertisement