
Vercel Sandbox now sends webhooks when a sandbox session is ready, is approaching its timeout, or is stopped. Use these notifications to update application state, decide whether to extend an agent session, or trigger cleanup.
Subscribe to sandbox.session.started, sandbox.session.expiring, and sandbox.session.stopped in your team's webhook settings. Each event includes sandbox and session details, so your backend can identify the affected session. Stopped events include the stop reason (requested, snapshot, timeout, exited, or error) and the session's duration, active CPU time, and network transfer.
Vercel sends sandbox.session.expiring 1 minute before a session times out, or the time configured by expiryNotificationLeadTime. Each time you extend the session, you get a new warning 1 minute before the new timeout.
Inside a verified webhook handler, inspect a stopped session:
if (event.type === 'sandbox.session.stopped') { const { id, stopReason, activeCpuDurationMs, networkTransfer } = event.payload.session; console.log({ id, stopReason, activeCpuDurationMs, networkTransfer });}
An event can be delivered more than once, so key your handler on the session ID, and on sandbox.expiresAt for expiring events.
Agents can subscribe to the same events through Vercel MCP. An agent that creates a sandbox can listen for sandbox.session.expiring and call extend_session_timeout to keep the session running.
Copy link to headingKeep agent sessions running with Sandbox lifecycle events and Workflow SDK
A workflow can wait on lifecycle events and extend its sandbox session while the agent is still working, without polling.
export const sandboxEvents = defineHook<SandboxSessionEvent>();
export async function agentTask(taskId: string, sandboxName: string) { 'use workflow'; const sandboxHook = sandboxEvents.create({ token: sandboxName }); for await (const { type } of sandboxHook) { if (type === 'sandbox.session.expiring' && (await isAgentWorking(taskId))) { await extendSession(sandboxName, ms('10m')); } if (type === 'sandbox.session.stopped') break; }}
Use lifecycle hooks with Vercel Workflows
Learn more in the Sandbox lifecycle webhooks documentation.