跳到正文
AI NEWS JOURNAL
VercelAI NEWS / JOURNAL

Vercel Sandbox adds session lifecycle webhooks

Vercel Sandbox now sends webhooks for session events including started, expiring, and stopped, enabling real-time updates and automated session management. Developers can subscribe to sandbox.session.started, sandbox.session.expiring, and sandbox.session.stopped events via webhook settings. The expiring event is sent one minute before timeout (configurable via expiryNotificationLeadTime), with a new notification issued upon session extension. Stopped events include stop reason, duration, CPU time, and network transfer data. Handlers should key on session ID and expiresAt for idempotency. Agents can use Vercel MCP to listen and extend sessions. Workflows can leverage lifecycle hooks to wait for events and extend sessions dynamically without polling, using the Workflow SDK.

翻译服务暂未运行,当前显示原文。

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(); 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.

资料来源

阅读原文 ↗

相关主题

← 继续阅读全部动态