> ## Documentation Index
> Fetch the complete documentation index at: https://docs.styne.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Receive a signed HTTPS POST at your own URL when one of your sandboxes changes state or one of your browser profiles signs out or back in.

Deliveries follow the [Standard Webhooks](https://www.standardwebhooks.com) scheme, so the verification libraries that exist for it work unchanged.

## Choose events

| Event | Sent when |
| - | - |
| `sandbox.created` | A sandbox started (a fork child also names its `parent_sandbox_id`) |
| `sandbox.paused` | A sandbox was paused |
| `sandbox.resumed` | A paused sandbox is running again |
| `sandbox.killed` | A sandbox ended because it was killed, or was evicted or lost by its node (`reason` says which) |
| `sandbox.timeout` | A sandbox ended because it reached its timeout |
| `sandbox.error` | A sandbox ended with an error (`detail` carries the node's short reason) |
| `profile.expired` | A check found a browser profile signed out (`source` is `check` or `step`; `relogin` says whether a re-login started) |
| `signin.completed` | An end user finished a sign-in link (`purpose` is `signin` or `relogin`; `check_passed` is the result of the check that follows) |
| `relogin.succeeded` | A re-login run signed a profile back in (`run_id`, `trigger`, `used_totp`) |
| `relogin.needs_human` | A re-login run needs a person (`reason`, `action`, and a `signin_link` when one was made) |

An endpoint names the events it wants (`events`), or `*` for all of them, including ones added later. Moving a sandbox between
nodes sends nothing: the sandbox lives on.

## Read the payload

```json theme={"theme":"css-variables"}
{
  "id": "evt_0b3f7c1e9d2a4c5e8f6a1b2c3d4e5f60",
  "type": "sandbox.killed",
  "created_at": "2026-11-12T10:00:03Z",
  "api_version": "2026-10-22",
  "data": {
    "object": "sandbox",
    "sandbox_id": "sbx_0123456789abcdef",
    "state": "stopped",
    "reason": "killed",
    "at": "2026-11-12T10:00:02.512Z"
  }
}
```

`data` is thin: ids, state, reason and time. Fetch the sandbox for anything more. The event `id` is stable for a state change:
the same change is never delivered under two ids, and a retry of one delivery carries the same `webhook-id` header. Deliveries
are at least once, so deduplicate on that id.

## Manage endpoints

| Method | Path | What it does |
| - | - | - |
| `POST` | `/webhooks` | Register `{url, events, description}`; the response carries the signing secret once |
| `GET` | `/webhooks` | List |
| `GET` | `/webhooks/{id}` | Read one |
| `PATCH` | `/webhooks/{id}` | Change url, events, description or status (enabled, disabled) |
| `DELETE` | `/webhooks/{id}` | Delete |
| `POST` | `/webhooks/{id}/rotate-secret` | New secret; the old one still verifies for a short overlap |
| `POST` | `/webhooks/{id}/test` | Send a webhook.test event to this endpoint only |
| `GET` | `/webhooks/{id}/deliveries` | The delivery log: state, attempts, last status |

Endpoints belong to the account of the API key that creates them. An endpoint never receives another account's events.
The URL must be `https`.

## Verify a delivery

Each request carries `webhook-id`, `webhook-timestamp` and `webhook-signature`. The signature is `v1,` plus the base64
HMAC-SHA256 of `{id}.{timestamp}.{raw body}`, keyed with the secret after its `whsec_` prefix is base64-decoded. Verify the
raw bytes, before any JSON parsing, and refuse a timestamp more than five minutes old.

```python Python theme={"theme":"css-variables"}
import base64, hashlib, hmac, time  # Python 3.9+

def verify(secret: str, headers: dict, body: bytes) -> bool:
    if abs(time.time() - int(headers["webhook-timestamp"])) > 300:
        return False
    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f'{headers["webhook-id"]}.{headers["webhook-timestamp"]}.'.encode() + body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
    return any(hmac.compare_digest(expected, s.removeprefix("v1,"))
               for s in headers["webhook-signature"].split() if s.startswith("v1,"))
```

```typescript TypeScript theme={"theme":"css-variables"}
// Node 20+
import { createHmac, timingSafeEqual } from 'node:crypto';

export function verify(secret, headers, rawBody) {
  if (Math.abs(Date.now() / 1000 - Number(headers['webhook-timestamp'])) > 300) return false;
  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const signed = `${headers['webhook-id']}.${headers['webhook-timestamp']}.${rawBody}`;
  const expected = createHmac('sha256', key).update(signed).digest();
  return headers['webhook-signature'].split(' ').some((s) => {
    if (!s.startsWith('v1,')) return false;
    const got = Buffer.from(s.slice(3), 'base64');
    return got.length === expected.length && timingSafeEqual(got, expected);
  });
}
```

During a secret rotation the header can hold two signatures; the examples accept either.

## Retries and failures

Answer with any `2xx` within 15 seconds. Anything else is retried with growing waits (5 seconds, 5 minutes, 30 minutes, then
hours, ten attempts in all over about three days, each wait jittered). `410 Gone` disables the endpoint, as does a long run of
failures; the delivery log says why. A failed delivery can be retried by hand from the log while its payload is kept (7 days).

Events are stored after the sandbox's state change has been recorded, off the path of the sandbox call itself: a slow or
failing endpoint never slows a sandbox.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.