Skip to content

E2B.Webhook reference

Source: packages/e2b/src/ReadWebhook.ts

Read an E2B Webhook’s delivery history and stats: debug a failing endpoint, or alert on failed deliveries.

const hook = yield* E2B.ReadWebhook(Lifecycle);
// in fetch:
const failed = yield* hook.deliveries({ deliveryStatus: ["failed"] });

Source: packages/e2b/src/ReadWebhookHttp.ts Kind: Layer · Provides: E2B.ReadWebhook

HTTP implementation of ReadWebhook. Works on any host.

Effect.gen(function* () {
const hook = yield* E2B.ReadWebhook(Lifecycle);
// ...
}).pipe(Effect.provide(E2B.ReadWebhookHttp))

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.

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)),
) {}

Source: packages/e2b/src/SandboxEventsLive.ts Kind: Layer · Provides: E2B.SandboxEvents

SandboxEvents on any WebhookHost: every Cloudflare Worker is one.

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.

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