Receive webhooks
A receiver that checks signatures, drops duplicates and answers fast.
| Runs on | Your server. No sandbox is needed. |
|---|---|
| Dashboard step | An owner or admin adds the webhook on the Webhooks page. |
| Cost | Free |
1The receiver
Standard library only. It prints each new event and the kill reason.
receiver.py
# A webhook receiver with only the Python standard library. import hashlib, hmac, json, os, time from http.server import BaseHTTPRequestHandler, HTTPServer SECRET = os.environ["FDTN_WEBHOOK_SECRET"] # the signing secret from the Webhooks page seen = set() # event IDs, to drop duplicates def verify(headers, body: bytes) -> bool: ts = headers.get("fdtn-timestamp", "0") if abs(time.time() - int(ts)) > 300: return False # older than 5 minutes: maybe a replay want = hmac.new(SECRET.encode(), ts.encode() + b"." + body, hashlib.sha256).hexdigest() return hmac.compare_digest("v1=" + want, headers.get("fdtn-signature", "")) class Hook(BaseHTTPRequestHandler): def do_POST(self): body = self.rfile.read(int(self.headers["content-length"])) if not verify(self.headers, body): self.send_response(401); self.end_headers(); return event = json.loads(body) self.send_response(200); self.end_headers() # answer fast, work after if event["id"] in seen: return seen.add(event["id"]) meta = event["event_data"].get("sandbox_metadata", {}) print(event["type"], event["sandbox_id"], meta, flush=True) if event["type"] == "sandbox.lifecycle.killed": print(" reason:", event["event_data"].get("kill_reason"), flush=True) HTTPServer(("0.0.0.0", int(os.environ.get("PORT", "8080"))), Hook).serve_forever()
2Test it on your computer
This script signs a sample event and sends it three times: once, again with the same ID, and with a bad signature.
send_test.py
# Sign a sample event the way FDTN does and send it to the receiver. import hashlib, hmac, json, os, sys, time, urllib.request, urllib.error url, secret = sys.argv[1], os.environ["FDTN_WEBHOOK_SECRET"] event = { "id": "evt-test-1", "version": "v2", "type": "sandbox.lifecycle.killed", "timestamp": "2026-11-15T10:15:00Z", "event_category": "lifecycle", "event_label": "kill", "event_data": {"sandbox_metadata": {"run": "eval-1"}, "kill_reason": "timeout"}, "sandbox_id": "i8x3k-test", } body = json.dumps(event).encode() def send(signature): ts = str(int(time.time())) sig = signature or "v1=" + hmac.new(secret.encode(), ts.encode() + b"." + body, hashlib.sha256).hexdigest() req = urllib.request.Request(url, body, {"content-type": "application/json", "fdtn-timestamp": ts, "fdtn-signature": sig}) try: return urllib.request.urlopen(req, timeout=30).status except urllib.error.HTTPError as e: return e.code print("good signature:", send(None)) print("same event again:", send(None)) print("bad signature:", send("v1=00"))
- Start the receiver with a test secret:
FDTN_WEBHOOK_SECRET=whsec_test_only python3 receiver.py - In a second terminal, send the events:
$ FDTN_WEBHOOK_SECRET=whsec_test_only python3 send_test.py http://localhost:8080/
good signature: 200
same event again: 200
bad signature: 401The receiver prints the event once:
sandbox.lifecycle.killed i8x3k-test {'run': 'eval-1'}
reason: timeout3Connect it in the dashboard
- Run the receiver on a public HTTPS address, on port 443 or 8443.
- Open Webhooks at compute.fdtn.dev. Add the URL and select events.
- Set the signing secret as
FDTN_WEBHOOK_SECRETon your server and restart the receiver. - Click Send test event. The receiver prints
sandbox.lifecycle.created.
Notes
- The signature is HMAC-SHA256 of
fdtn-timestamp, a dot and the raw body. Verify before you parse JSON. Verify the signature - A timestamp older than 5 minutes fails, to stop replays.
- We retry a failed delivery up to five times, so drop repeated event IDs. On more than one server, keep the IDs in a shared store.
- Answer
200first, then work. We stop waiting after 10 seconds. sandbox_metadataholds the create metadata, for examplerun=eval-1.