Skip to content

Examples and guides for using the OpenAI API

2.4 KB
Raw Blame

Vercel webhook-managed sandbox

The endpoint verifies the signature and sends the session ID to Vercel Queues. The consumer retrieves current session state and starts a named sandbox. OS locks prevent concurrent jobs from installing twice or starting duplicate executors.

Deploy

Use Node.js 24+ and a dedicated Vercel project with Sandbox and Queues access. See the provider overview. Create the agent using the shared setup, then run from this directory:

npm ci
npx vercel link
uv run client.py --create-agent vercel-webhook-example

In the project's production environment variables, configure:

  • OPENAI_API_KEY: controller/session-read credential.
  • OPENAI_AGENT_ID: agent ID from the shared setup.
  • OPENAI_EXECUTOR_API_KEY: restricted executor credential.
  • OPENAI_WEBHOOK_SECRET: generated by OpenAI when registering the endpoint.

For the first deployment only, use pending-webhook-registration as the signing value; the receiver rejects it with 503.

npx vercel --prod

The webhook URL is https://YOUR_PROJECT.vercel.app/api/webhook. OpenAI must be able to reach it without a login. Use a dedicated project and its production URL; configure deployment protection so OpenAI can reach the receiver. The webhook signature authenticates requests, and Vercel's queue trigger invokes the consumer.

Register the webhook, replace the signing value with the real secret, and redeploy. Then use the client and reconnect flow with this directory's client:

uv run client.py --agent-id "$OPENAI_AGENT_ID"
uv run client.py --session-id "$SESSION_ID" --input "Run another shell command."

Environment-variable changes require a new deployment.

Stop or clean up

The sandbox name is agents- followed by the API session ID. Stop it in the Vercel Sandbox dashboard to release compute between turns; delete it and its snapshots for final cleanup. Deleting a sandbox does not delete retained snapshots. Also delete the API session.

Named sandboxes preserve files between runs; processes must be restarted. The executor is installed on first use. For regular use, bake it into a sandbox snapshot to reduce connection latency. Remove the OpenAI webhook before deleting the example project.

See the application-managed mode for direct provisioning.