> For the list of every page, fetch /llms.txt. The API contract is the OpenAPI file linked from the API reference.

# Webhooks

Meadow can POST to your server each time a sandbox changes status, so you do not have to poll.

Next step: set a `webhook_url`, then verify the signature of every delivery with the code below.

## Set the address

There are two places. A sandbox's own `webhook_url` wins over the project's.

On one sandbox:

```json
{"image": "python:3.12-slim", "webhook_url": "https://hooks.example.com/meadow"}
```

On the project, for every sandbox in it that has no address of its own (needs an `admin` key):

```bash
curl -sS -X PATCH "$MEADOW_BASE_URL/v1/projects/$PROJECT_ID" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"webhook_url": "https://hooks.example.com/meadow"}'
```

The address must use `https` and resolve to a public address. These return 400:

| Address | Message |
| --- | --- |
| `http://...` | `webhook_url must use https` |
| A private IP such as `https://10.0.0.5/hook` | `webhook_url destination address is not allowed` |
| `https://localhost/hook` | `webhook_url destination host is not allowed` |

An address that names Meadow's own API host is accepted and never delivered. Point `webhook_url` at your own receiver.

The address is read when each event happens. Changing it does not move events that are already queued.

## Events

| `type` | Sent when |
| --- | --- |
| `sandbox.creating` | The create request was accepted. |
| `sandbox.provider_failed` | One provider failed and Meadow is moving on. One event per failed provider. |
| `sandbox.running` | The sandbox started. |
| `sandbox.terminated` | The sandbox ended: your delete, a timeout, or the provider's lifetime limit. |
| `sandbox.failed` | No provider could start it, or the provider lost it. |

A normal life is `creating`, `running`, `terminated`. A create with a misspelled image and two providers sent `creating`, `provider_failed`, `provider_failed`, `failed`.

There are no events for commands, files, or image builds.

A project's address also receives `budget.threshold_crossed` when spend reaches a budget threshold. Branch on `type`. See [Budgets and alerts](/call-models/budgets-and-alerts#what-an-alert-is).

## Payload

Each delivery is a POST with `content-type: application/json`, `user-agent: meadow-webhooks/1`, the three Standard Webhooks headers (`webhook-id`, `webhook-timestamp`, `webhook-signature`) and Meadow's own `x-meadow-signature` header. The body:

```json
{
  "created_at": "2026-11-23T22:26:25.143Z",
  "id": "evt_000059aa",
  "sandbox": {
    "attempts": [{"duration_ms": 3256, "outcome": "served", "provider": "daytona"}],
    "created_at": "2026-11-23T22:26:21.655Z",
    "expires_at": "2026-11-23T22:41:25.143Z",
    "failure_reason": null,
    "id": "sbx_000017c9",
    "labels": {"team": "docs"},
    "name": "web",
    "ports": [8000],
    "project_id": "prj_00009122",
    "provider": "daytona",
    "provider_sandbox_id": "0000946e",
    "resources": {"cpu": 2, "memory_mb": 4096},
    "ssh": true,
    "started_at": "2026-11-23T22:26:25.143Z",
    "status": "running",
    "terminated_at": null
  },
  "type": "sandbox.running"
}
```

`sandbox` is the same object the API returns, as it was when the event happened, without `cost`: only `GET /v1/sandboxes` and `GET /v1/sandboxes/{sandbox_id}` return that. `id` is the same on every retry of one event, so use it to drop duplicates.

## Verify the signature

Anyone can POST to your address. Check the signature before you trust a delivery.

Every delivery is signed twice, with the same secret. Check either signature.

- The [Standard Webhooks](https://www.standardwebhooks.com) headers. Libraries for most languages verify them, so you write no signature code. Use these in new receivers.
- Meadow's own `x-meadow-signature` header. It came first and stays for now. A receiver that checks it keeps working with no change. If it is ever removed, the [changelog](/reference/changelog) will say so first.

### Standard Webhooks

```text
webhook-id: evt_000059aa
webhook-timestamp: 1795472791
webhook-signature: v1,<44 base64 characters>
```

- `webhook-id` is the event `id`. It is the same on every retry of one event, so you can use it to drop duplicates.
- `webhook-timestamp` is the time of this delivery attempt, in Unix seconds. Reject one that is more than 5 minutes from your clock.
- `webhook-signature` is `v1,` and then the HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<raw body>`, in standard base64. The key is the bytes you get by base64-decoding the part of your secret after `whsec_`.
- For 24 hours after you rotate the secret, the header holds one signature for each valid secret, separated by spaces, newest first.

With the Python library (`pip install standardwebhooks`):

```python
from standardwebhooks.webhooks import Webhook, WebhookVerificationError

def verified(secret: str, raw_body: bytes, headers: dict) -> bool:
    try:
        Webhook(secret).verify(raw_body, headers)
        return True
    except WebhookVerificationError:
        return False
```

The signature was checked against the reference library and against values computed with `openssl`, in Meadow's tests. The sample above was not run against a delivery from the hosted beta.

A secret issued before the update of 2026-11-28 is written in URL-safe base64, which the Standard Webhooks libraries do not read. Do one of these:

- Rotate the secret (see [Rotate the secret](#rotate-the-secret)). A new secret is in standard base64 and works with the libraries as it is.
- Or keep the secret and convert it before you hand it to a library: in the part after `whsec_`, replace every `-` with `+` and every `_` with `/`. The `x-meadow-signature` check below uses the secret exactly as issued, with no conversion.

### Meadow's own header

```text
x-meadow-signature: t=1795472791,v1=<64 hex characters>
```

- `t` is the time of this delivery attempt, in Unix seconds.
- `v1` is the HMAC-SHA256 of `<t>.<body>`, in hex, keyed with your project's webhook secret.

The secret starts with `whsec_`. It is returned once, in `webhook_secret`, when the project is created or the secret is rotated. See [Projects](/set-up-your-account/projects). If you never saved it, rotate it to get a new one.

To verify:

1. Read the raw body bytes. Do not parse and re-encode the JSON first.
2. Reject a `t` more than 5 minutes from your clock.
3. Compute the HMAC of `t`, a dot, and the body with each secret you hold.
4. Accept when any `v1` in the header matches, using a constant-time comparison.

The header can carry several `v1` values after a rotation, so compare against all of them.

### Python

Standard library only. Put one secret, or several separated by commas, in `MEADOW_WEBHOOK_SECRET`.

```python
import hashlib
import hmac
import json
import os
import time
from http.server import BaseHTTPRequestHandler, HTTPServer

TOLERANCE_SECONDS = 300


def verify(body: bytes, header: str, secrets: list[str]) -> bool:
    timestamp = None
    signatures = []
    for part in header.split(","):
        name, _, value = part.strip().partition("=")
        if name == "t":
            timestamp = value
        elif name == "v1":
            signatures.append(value)
    if timestamp is None or not timestamp.isdigit() or not signatures:
        return False
    if abs(time.time() - int(timestamp)) > TOLERANCE_SECONDS:
        return False
    signed = timestamp.encode() + b"." + body
    for secret in secrets:
        expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
        if any(hmac.compare_digest(expected, s) for s in signatures):
            return True
    return False


class Handler(BaseHTTPRequestHandler):
    def do_POST(self):
        body = self.rfile.read(int(self.headers.get("Content-Length", 0)))
        header = self.headers.get("X-Meadow-Signature", "")
        secrets = os.environ["MEADOW_WEBHOOK_SECRET"].split(",")
        if not verify(body, header, secrets):
            self.send_response(401)
            self.end_headers()
            return
        event = json.loads(body)
        print(event["type"], event["id"], event["sandbox"]["id"], event["sandbox"]["status"], flush=True)
        self.send_response(204)
        self.end_headers()

    def log_message(self, *args):
        pass


if __name__ == "__main__":
    HTTPServer(("127.0.0.1", 8787), Handler).serve_forever()
```

### Go

```go
package main

import (
	"crypto/hmac"
	"crypto/sha256"
	"encoding/hex"
	"encoding/json"
	"io"
	"log"
	"net/http"
	"os"
	"strconv"
	"strings"
	"time"
)

const tolerance = 5 * time.Minute

func verify(body []byte, header string, secrets []string, now time.Time) bool {
	var timestamp string
	var signatures []string
	for _, part := range strings.Split(header, ",") {
		name, value, _ := strings.Cut(strings.TrimSpace(part), "=")
		switch name {
		case "t":
			timestamp = value
		case "v1":
			signatures = append(signatures, value)
		}
	}
	seconds, err := strconv.ParseInt(timestamp, 10, 64)
	if err != nil {
		return false
	}
	age := now.Sub(time.Unix(seconds, 0))
	if age > tolerance || age < -tolerance {
		return false
	}
	for _, secret := range secrets {
		mac := hmac.New(sha256.New, []byte(secret))
		mac.Write([]byte(timestamp + "."))
		mac.Write(body)
		expected := []byte(hex.EncodeToString(mac.Sum(nil)))
		for _, signature := range signatures {
			if hmac.Equal(expected, []byte(signature)) {
				return true
			}
		}
	}
	return false
}

type event struct {
	ID      string `json:"id"`
	Type    string `json:"type"`
	Sandbox struct {
		ID     string `json:"id"`
		Status string `json:"status"`
	} `json:"sandbox"`
}

func main() {
	secrets := strings.Split(os.Getenv("MEADOW_WEBHOOK_SECRET"), ",")
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		body, err := io.ReadAll(http.MaxBytesReader(w, r.Body, 1<<20))
		if err != nil {
			w.WriteHeader(http.StatusBadRequest)
			return
		}
		if !verify(body, r.Header.Get("X-Meadow-Signature"), secrets, time.Now()) {
			w.WriteHeader(http.StatusUnauthorized)
			return
		}
		var ev event
		if err := json.Unmarshal(body, &ev); err != nil {
			w.WriteHeader(http.StatusBadRequest)
			return
		}
		log.Println(ev.Type, ev.ID, ev.Sandbox.ID, ev.Sandbox.Status)
		w.WriteHeader(http.StatusNoContent)
	})
	log.Fatal(http.ListenAndServe("127.0.0.1:8787", nil))
}
```

Both programs listen on plain HTTP at `127.0.0.1:8787`, and Meadow delivers only to a public `https` address. To try one from a laptop, put an HTTPS tunnel or a TLS reverse proxy in front of port 8787 and use its public URL as `webhook_url`. In production, run the handler behind your usual HTTPS front end.

Both programs received live deliveries from the hosted beta. The Python one printed:

```text
sandbox.creating evt_0000ae03 sbx_0000b035 creating
sandbox.running evt_00006b88 sbx_0000b035 running
sandbox.terminated evt_0000a6d2 sbx_0000b035 terminated
```

Both verify functions were also checked against one captured delivery that carried two `v1` values: each secret alone passed, a wrong secret failed, a changed body failed, and a clock 301 seconds late failed.

## Retries

Only a 2xx answer counts as delivered. Anything else is retried: another status, a redirect (redirects are not followed), a connection error, or no answer within 10 seconds.

| | |
| --- | --- |
| Retry window | 72 hours from the time the event was created, as Stripe and OpenAI do |
| Waits between attempts | 5 s after the first failure, then twice the wait before, up to 12 hours |
| Given up | After the try at 72 hours. The event is then dropped. |

In our runs a receiver that answered 500 to a first attempt got the second attempt 5 to 6 seconds later. Those runs were on the hosted beta when it retried for one hour. The 72 hour window has not been seen there yet.

What this means for your receiver:

- Answer 2xx fast and do the work afterwards. Deliveries to one address are sent one at a time, so a slow receiver delays its own later events.
- Expect duplicates. Drop an event `id` you have already handled.
- Do not rely on order. A retried `sandbox.creating` can arrive after `sandbox.running`. Read `sandbox.status` and the timestamps.
- `t` and `webhook-timestamp` change on each retry, and so do the signatures. `webhook-id` does not.
- An event that was given up on is never sent again. After an outage longer than 72 hours, read `GET /v1/sandboxes` to catch up.

## Rotate the secret

```bash
curl -sS -X PATCH "$MEADOW_BASE_URL/v1/projects/$PROJECT_ID" \
  -H "Authorization: Bearer $MEADOW_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"rotate_webhook_secret": true}'
```

```json
{
  "created_at": "2026-11-23T22:18:10.842Z",
  "id": "prj_00009122",
  "name": "evals",
  "webhook_secret": "whsec_...",
  "webhook_url": null
}
```

The new secret is shown once. The old secret stays valid for 24 hours. During that time each delivery carries one `v1` for the new secret and one for each earlier secret still inside its own 24 hours, newest first:

```text
x-meadow-signature: t=1795472956,v1=<new secret>,v1=<old secret>
```

We rotated, then deleted a sandbox. The next delivery carried two `v1` values, and both the old and the new secret verified it. In a later run a receiver that held only the old secret, and then one that held only the new secret, each accepted all three events of a sandbox, and a receiver with a wrong secret accepted none.

A rotation without downtime:

1. Rotate and save the new secret.
2. Give your receiver both secrets. The sample code accepts a comma-separated list.
3. After 24 hours, remove the old secret.

A receiver that keeps only the old secret keeps working for those 24 hours, and one that switches straight to the new secret works at once.

More in [Known limits](/reference/known-limits#receiving-webhooks).

## API reference

Operations on this page: [`createSandbox`](/reference/api-reference#createsandbox), [`updateProject`](/reference/api-reference#updateproject), [`createProject`](/reference/api-reference#createproject).