﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>> ## Documentation Index
> Fetch the complete documentation index at: https://docs.boat.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Webhooks

> Receive signed notifications when a sandbox becomes ready, finishes restoring, fails, stops, degrades or recovers.

A webhook sends sandbox lifecycle events to your HTTPS endpoint. One webhook gets the events of all the sandboxes in your account.

Use webhooks to:

* Start work when a sandbox is usable.
* Respond when a sandbox fails to start.
* Continue an automation after a sandbox stops.

boat sends 6 events: `sandbox.ready`, `sandbox.hydrated`, `sandbox.error`, `sandbox.archived` (stopped), `sandbox.degraded` and `sandbox.recovered`. Read [Events](#events).

| | CLI | API | SDKs | Dashboard |
| - | - | - | - | - |
| Register | `boat webhook create` | `POST /webhooks` | `createWebhook` | [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) |
| List / read | `boat webhook list` | `GET /webhooks`, `GET /webhooks/{id}` | `listWebhooks`, `getWebhook` | [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) |
| Edit in place | not available | `PATCH /webhooks/{id}` | `updateWebhook` | not available |
| Rotate secret | `boat webhook rotate` | `POST /webhooks/{id}/rotate` | `rotateWebhookSigningSecret` | [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) |
| Remove | `boat webhook remove` | `DELETE /webhooks/{id}` | `deleteWebhook` | [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) |
| Delivery history | not available | not available | not available | [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) → Deliveries |

## Register an endpoint

The examples use `BOAT_API_BASE=https://boat.dev/api/v1`. The API key needs the `account.admin` action.

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat webhook create https://example.com/hooks/sandbox \
  --name production \
  --event ready \
  --event error \
  --event archived
```

```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS -X POST "$BOAT_API_BASE/webhooks" \
  -H "Authorization: Bearer $BOAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "production",
    "url": "https://example.com/hooks/sandbox",
    "events": ["sandbox.ready", "sandbox.error", "sandbox.archived"]
  }'
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
const created = await sandbox.createWebhook({
  name: "production",
  url: "https://example.com/hooks/sandbox",
  events: new Set(["sandbox.ready", "sandbox.error", "sandbox.archived"]),
});
console.log(created.webhook.id, created.secret);   // secret is shown once
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
from boat_sdk.models.webhook_create_request import WebhookCreateRequest

created = sandbox.create_webhook(WebhookCreateRequest(
    name="production",
    url="https://example.com/hooks/sandbox",
    events=["sandbox.ready", "sandbox.error", "sandbox.archived"],
))
print(created.webhook.id, created.secret)   # secret is shown once
```

How to name events:

| Surface | Event names | If you give no event |
| - | - | - |
| CLI `--event` | `ready`, `error`, `archived`, `hydrated`, `degraded` or `recovered`. The `sandbox.` prefix is optional. | You get all six events. |
| API and SDKs | The full name, for example `sandbox.ready`. | The call fails. You must give at least one event. |

The call returns a signing secret that starts with `whsec_`. **You see this secret only once.** Store it in your secret manager.

> [!NOTE]
>
> The endpoint must use HTTPS on port 443. Its address must resolve only to public IP addresses. boat does not follow redirects. An account can register up to 10 endpoint URLs.

## Manage endpoints

```bash CLI theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
boat webhook list
boat webhook rotate <id>   # replaces the signing secret
boat webhook remove <id>
```

```bash curl theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
curl -sS "$BOAT_API_BASE/webhooks" \
  -H "Authorization: Bearer $BOAT_API_KEY"

curl -sS "$BOAT_API_BASE/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $BOAT_API_KEY"

curl -sS -X PATCH "$BOAT_API_BASE/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $BOAT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"events":["sandbox.error"]}'

curl -sS -X POST "$BOAT_API_BASE/webhooks/$WEBHOOK_ID/rotate" \
  -H "Authorization: Bearer $BOAT_API_KEY"

curl -sS -X DELETE "$BOAT_API_BASE/webhooks/$WEBHOOK_ID" \
  -H "Authorization: Bearer $BOAT_API_KEY"
```

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
await sandbox.listWebhooks();
await sandbox.getWebhook({ webhookId: "wh_0123456789abcdef01234567" });

await sandbox.updateWebhook({
  webhookId: "wh_0123456789abcdef01234567",
  events: new Set(["sandbox.error"]),
});

const rotated = await sandbox.rotateWebhookSigningSecret({ webhookId: "wh_0123456789abcdef01234567" });
console.log(rotated.secret);

await sandbox.deleteWebhook({ webhookId: "wh_0123456789abcdef01234567" });
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
from boat_sdk.models.webhook_update_request import WebhookUpdateRequest

sandbox.list_webhooks()
sandbox.get_webhook("wh_0123456789abcdef01234567")

sandbox.update_webhook(
    "wh_0123456789abcdef01234567",
    WebhookUpdateRequest(events=["sandbox.error"]),
)

rotated = sandbox.rotate_webhook_signing_secret("wh_0123456789abcdef01234567")
print(rotated.secret)

sandbox.delete_webhook("wh_0123456789abcdef01234567")
```

The [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) tab of the dashboard does the same tasks. Only the dashboard shows the delivery history.

> [!NOTE]
>
> Only the API and SDKs can change the name, URL or events of an endpoint in place (`PATCH /webhooks/{webhookId}`). The CLI and the dashboard cannot edit an endpoint. Delete it and create it again. This gives you a new signing secret.

When you rotate the secret, accept the old secret and the new secret for a short time. A delivery attempt that already started can still carry the old signature.

When you delete an endpoint, boat removes its queued deliveries. A delivery attempt that already started can still arrive.

## Events

| Event | boat sends it when |
| - | - |
| `sandbox.ready` | A sandbox becomes usable (`ready`, `idle` or `running`) after it was not usable. This includes recovery from an error. boat can run commands now. Your own services and Docker containers can need more seconds to start. |
| `sandbox.hydrated` | A restored sandbox finishes materializing. See [After a restore](#after-a-restore). |
| `sandbox.error` | A sandbox enters `error`. |
| `sandbox.archived` | A sandbox is stopped. The API reports a stopped sandbox as `archived`. |
| `sandbox.degraded` | The machine is alive, but boat cannot fully reach it. boat sends this about a minute after the machine stops answering. The sandbox keeps running. boat does not stop it. `data.reason` gives the cause. |
| `sandbox.recovered` | A degraded sandbox is fully reachable again. This happens on the same machine, or on a new machine after a resume or an automatic recovery. |

boat creates `sandbox.ready`, `sandbox.error` and `sandbox.archived` in the same database transaction as the state change.

### After a restore

`sandbox.hydrated` arrives after `sandbox.ready`. It can arrive at the same moment, or minutes later.

1. The sandbox becomes `ready`. boat sends `sandbox.ready`.
2. The Docker containers of the sandbox start as soon as their images load.
3. The background disk copy finishes. The Docker volumes move onto the real disk.
4. Each running container's volume mounts move onto the real disk in place. The containers pause for about 0.1 s. They do not restart.
5. boat sends `sandbox.hydrated`.

To poll instead, read `hydrated` and `hydratedAt` on `GET /sandboxes/{id}`.

### Degraded sandboxes

A degraded sandbox shows `"health": "degraded"` and a `healthReason` on `GET /sandboxes/{id}`. The most common cause is a firewall rule inside the sandbox that blocks the boat tunnel. See [Firewall rules](https://docs.boat.dev/hosting/firewall.md).

## Payload

```json theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
{
  "id": "evt_2af97cd17a8248bb8fe37653a235bc91",
  "type": "sandbox.ready",
  "createdAt": "2026-08-11T12:00:00.000Z",
  "data": {
    "sandbox": {
      "id": "bx_23456789",
      "name": "Production worker"
    },
    "previousState": "cloning",
    "state": "ready"
  }
}
```

* `data.sandbox.id` is the public sandbox ID.
* Use the top-level event `id` as an idempotency key.

The fields in `data` change with the event:

| Event | `previousState` | `state` | `reason` |
| - | - | - | - |
| `sandbox.ready`, `sandbox.error`, `sandbox.archived` | yes | yes | no |
| `sandbox.hydrated` | no | no | no |
| `sandbox.degraded`, `sandbox.recovered` | no | yes | yes |

## Verify signatures

Each request has these headers. The header names keep the old `Ascii` prefix.

| Header | Value |
| - | - |
| `X-Ascii-Event` | Event type |
| `X-Ascii-Delivery` | Stable event ID |
| `X-Ascii-Timestamp` | Unix timestamp for this attempt |
| `X-Ascii-Signature` | `v1=` followed by a hex HMAC-SHA256 signature |
| `X-Ascii-Attempt` | Attempt number, starting at 1 |

To verify a request:

1. Compute the expected signature over the exact raw request body:

   ```text theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
   HMAC_SHA256(secret, delivery_id + "." + timestamp + "." + raw_body)
   ```

2. Compare the signatures in constant time.

3. Reject old timestamps.

4. Deduplicate on the delivery ID.

```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
import { createHmac, timingSafeEqual } from "node:crypto";

function verifyWebhook(rawBody: Buffer, headers: Headers, secret: string) {
  const id = headers.get("x-ascii-delivery") ?? "";
  const timestamp = headers.get("x-ascii-timestamp") ?? "";
  const supplied = (headers.get("x-ascii-signature") ?? "").replace(/^v1=/, "");
  const expected = createHmac("sha256", secret)
    .update(`${id}.${timestamp}.`)
    .update(rawBody)
    .digest("hex");

  const issuedAt = Number(timestamp);
  if (!Number.isFinite(issuedAt) || Math.abs(Date.now() / 1000 - issuedAt) > 300) return false;
  if (!/^[a-f0-9]{64}$/i.test(supplied)) return false;
  return timingSafeEqual(Buffer.from(supplied, "hex"), Buffer.from(expected, "hex"));
}
```

```python Python theme={"theme":{"light":"github-light","dark":"github-dark-default"}}
import hmac, re, time
from hashlib import sha256

def verify_webhook(raw_body: bytes, headers, secret: str) -> bool:
    delivery = headers.get("x-ascii-delivery", "")
    timestamp = headers.get("x-ascii-timestamp", "")
    supplied = headers.get("x-ascii-signature", "").removeprefix("v1=")

    try:
        if abs(time.time() - float(timestamp)) > 300:
            return False
    except ValueError:
        return False
    if not re.fullmatch(r"[a-fA-F0-9]{64}", supplied):
        return False

    expected = hmac.new(
        secret.encode(),
        f"{delivery}.{timestamp}.".encode() + raw_body,
        sha256,
    ).hexdigest()
    return hmac.compare_digest(supplied.lower(), expected)
```

> [!WARNING]
>
> Verify the raw bytes before you parse the JSON. If you serialize the body again, the signature changes.

## Delivery and retries

| Your endpoint | What boat does |
| - | - |
| Returns a `2xx` | Marks the event as delivered. |
| Returns another status, fails to connect, or takes more than 5 seconds | Retries with exponential backoff, up to 8 attempts. |

* Delivery is **at least once**. The same event ID can arrive more than once.
* Events can arrive out of order. Use the ID, creation time and state of each event. Do not rely on the request order.
* Return a `2xx` quickly. Move slow work to your own queue.
* boat keeps completed and exhausted delivery records for 30 days.

## Inspect deliveries

1. Open [Webhooks & OTel](https://boat.dev/dashboard?tab=webhooks) in the boat dashboard.
2. Expand **Deliveries** next to an endpoint.

The log of recent deliveries shows:

* The event that boat sent.
* The exact payload.
* The boat ID and the event ID.
* The number of attempts.
* The HTTP result, or a connection diagnostic.
* The time of the next retry, if there is one.


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