E2B.Webhook reference
ReadWebhook
Section titled “ReadWebhook”Source:
packages/e2b/src/ReadWebhook.ts
Read an E2B Webhook’s delivery history and stats: debug a failing
endpoint, or alert on failed deliveries.
ReadWebhook: Reading deliveries
Section titled “ReadWebhook: Reading deliveries”const hook = yield* E2B.ReadWebhook(Lifecycle);// in fetch:const failed = yield* hook.deliveries({ deliveryStatus: ["failed"] });ReadWebhookHttp
Section titled “ReadWebhookHttp”Source:
packages/e2b/src/ReadWebhookHttp.tsKind: Layer · Provides:E2B.ReadWebhook
HTTP implementation of ReadWebhook. Works on any host.
ReadWebhookHttp: Provide the layer
Section titled “ReadWebhookHttp: Provide the layer”Effect.gen(function* () { const hook = yield* E2B.ReadWebhook(Lifecycle); // ...}).pipe(Effect.provide(E2B.ReadWebhookHttp))SandboxEvents
Section titled “SandboxEvents”Source:
packages/e2b/src/SandboxEvents.ts
Receive E2B sandbox lifecycle events (created, paused, resumed, checkpointed, updated, killed) in a Worker or any other webhook host.
At deploy, an Webhook is created pointing at the host. At runtime,
each delivery’s e2b-signature is verified before the handler runs; an
unsigned or wrongly signed request is rejected with 401. E2B retries a
failed delivery up to three times, so handlers should be idempotent on
event.id.
SandboxEvents: Handling lifecycle events
Section titled “SandboxEvents: Handling lifecycle events”export default class Api extends Cloudflare.Worker<Api>()( "Api", { main: import.meta.url }, Effect.gen(function* () { yield* E2B.consumeSandboxEvents({ events: ["sandbox.lifecycle.killed"] }, (event) => Effect.log(`sandbox ${event.sandbox_id} killed: ${event.event_data?.kill_reason}`), ); return { fetch: Effect.succeed(HttpServerResponse.text("ok")) }; }).pipe(Effect.provide(E2B.SandboxEventsLive)),) {}SandboxEventsLive
Section titled “SandboxEventsLive”Source:
packages/e2b/src/SandboxEventsLive.tsKind: Layer · Provides:E2B.SandboxEvents
SandboxEvents on any WebhookHost: every Cloudflare Worker
is one.
Webhook
Section titled “Webhook”Source:
packages/e2b/src/Webhook.ts
An E2B webhook: E2B POSTs every sandbox lifecycle event (created, paused, resumed, checkpointed, updated, killed) in your team to a URL.
Use E2B.SandboxEvents to point a webhook at a Worker or Function and
handle the events there; it declares this resource for you and verifies
each delivery’s signature. Declare a Webhook directly for an endpoint
Alchemy does not deploy.
E2B webhooks carry no labels, so Alchemy recognises its webhooks by their generated name.
Webhook: Creating a Webhook
Section titled “Webhook: Creating a Webhook”export const Lifecycle = E2B.Webhook("Lifecycle", { url: "https://hooks.example.com/e2b", events: ["sandbox.lifecycle.paused", "sandbox.lifecycle.killed"], signatureSecret: Alchemy.Secret("E2B_WEBHOOK_SECRET"),});Webhook: Referencing a webhook the stack doesn’t manage
Section titled “Webhook: Referencing a webhook the stack doesn’t manage”E2B.Webhook.lookup finds an existing webhook by name. Nothing is created,
adopted or deleted.
const audit = E2B.Webhook.lookup({ name: "audit" });const deliveries = yield* E2B.ReadWebhook(audit);