Skip to documentation
API + guides

01Documentation

Webhooks

Receive asynchronous event notifications from sandboxes via webhooks. Webhooks allow you to react to process events, sandbox lifecycle changes, and file modifications.

Webhook Configuration#

Configure webhooks when claiming a sandbox:

FieldTypeDescription
urlstringWebhook endpoint URL (required)
secretstringShared secret for payload signing (optional)
watch_dirstringDirectory to monitor for file events (optional)
ℹ

Webhooks are configured per-sandbox at creation time. Each sandbox can have its own webhook configuration.

ℹ

secret is optional. For quick debugging, you can leave it empty and use services like webhook.site to inspect incoming events directly.

Delivery Guarantees#

Webhook requests may be delivered more than once, so consumers must deduplicate by event_id. Your endpoint should return a 2xx status only after it has durably recorded the event. Retries are best-effort and do not guarantee that an unavailable endpoint eventually receives every event.

When a sandbox is created with a webhook, procd writes signed delivery records to a reserved outbox under /var/lib/sandbox0/procd/webhook-outbox before acknowledging the internal publish request, then dispatches them with backoff. The outbox is part of the persistent sandbox rootfs and remains scoped to the sandbox identity. Runtime outbox delivery requires running guest compute; it waits while compute is paused. Its retryable failures are transport errors, 429, and 5xx; other non-2xx responses are terminal. The manager deletion outbox below has its own retry policy.

Sandbox deletion has an additional manager-level path. When manager commits a sandbox deletion, it writes the exact signed sandbox.deleted request to a PostgreSQL outbox in the same transaction. Runtime and RootFS cleanup never wait for the external endpoint. Manager retries transport errors and HTTP 408, 425, 429, and 5xx responses with exponential backoff for up to 24 hours. Other non-2xx responses are terminal. After the 24-hour delivery window expires, manager stops retrying and later removes the bounded outbox record.

ℹ

Webhook delivery is eventually consistent. Temporary endpoint outages, procd container restarts, and manager restarts can cause retries. A response can be delivered more than once when the receiver accepts it but manager cannot durably record the success.


Event Types#

Sandbox Events#

EventDescription
sandbox.readySandbox has been initialized and is ready
sandbox.pausedProcess-local pause notification; not a guaranteed Nomad lifecycle event (see below)
sandbox.resumedProcess-local resume notification; not a guaranteed Nomad lifecycle event (see below)
sandbox.killedSandbox has been killed
sandbox.deletedManager has committed sandbox deletion and queued the final notification

Process Events#

These notifications come from procd Context processes. They do not observe every workload subprocess; use the session journal for supervised session attempts.

EventDescription
process.startedA new process/context has started
process.exitedA process has exited (includes exit code)
process.crashedA managed process ended in a crashed or killed state, including non-zero command exits

File Events#

EventDescription
file.modifiedA file event occurred (create, write, remove, rename, or chmod)
ℹ

File events require watch_dir and running guest compute. The filesystem operation is in payload.event_type; the envelope's event_type remains file.modified. Atomic file replacement can produce temporary-file and rename events. Offline paused-file edits do not run this watcher or create a replayable file-change history.

Agent Events#

EventDescription
agent.eventCustom event published by the sandbox via the webhook publish API

Configure Webhook at Sandbox Creation#

Set up webhooks when claiming a sandbox.

go
webhookURL := os.Getenv("SANDBOX0_WEBHOOK_URL") webhookSecret := os.Getenv("SANDBOX0_WEBHOOK_SECRET") if webhookURL == "" { log.Fatal("SANDBOX0_WEBHOOK_URL is required") } sandbox, err := client.ClaimSandbox( ctx, "default", sandbox0.WithSandboxHardTTL(300), sandbox0.WithSandboxWebhook(webhookURL, webhookSecret), sandbox0.WithSandboxWebhookWatchDir("/tmp/webhook-demo"), ) if err != nil { log.Fatal(err) } fmt.Printf("Sandbox ID: %s\n", sandbox.ID)

Signature Verification#

When a secret is configured, webhook payloads are signed using HMAC-SHA256.

ℹ

If secret is not configured, Sandbox0 will not send the X-Sandbox0-Signature header.

X-Sandbox0-Signature: <hex-encoded-signature>

The signature is the hex-encoded HMAC-SHA256 of the request body.

Verification Example#

The Python receiver uses Flask (pip install Flask); the TypeScript receiver uses Express (npm install express, plus @types/express for TypeScript).

These examples require a non-empty SANDBOX0_WEBHOOK_SECRET matching the sandbox configuration. They demonstrate signature checks; add durable event recording and event_id deduplication before returning success in your receiver.

go
import ( "io" "net/http" "os" sandbox0 "github.com/sandbox0-ai/sdk-go" ) func webhookHandler(w http.ResponseWriter, r *http.Request) { // Verify against raw request bytes, not a re-serialized JSON object. payload, err := io.ReadAll(r.Body) if err != nil { http.Error(w, "read body failed", http.StatusBadRequest) return } signature := r.Header.Get("X-Sandbox0-Signature") secret := os.Getenv("SANDBOX0_WEBHOOK_SECRET") if secret == "" { http.Error(w, "webhook verification is not configured", http.StatusServiceUnavailable) return } if !sandbox0.VerifyWebhookSignature(secret, payload, signature) { http.Error(w, "invalid signature", http.StatusUnauthorized) return } // Durably record and deduplicate event_id before returning success. w.WriteHeader(http.StatusOK) }

Triggering Webhook Events#

Sandbox Events#

sandbox.ready is emitted during runtime initialization. sandbox.killed is a best-effort graceful procd shutdown event, and sandbox.deleted is queued by manager after durable deletion.

The current Nomad lifecycle pauses by retiring compute and resumes by launching or restoring a runtime. It does not call the legacy process-local pause/resume handlers that emit sandbox.paused and sandbox.resumed. Do not treat those webhook names as guaranteed notifications of public pause/resume completion. Use committed sandbox details, lifecycle wait helpers, or an exact operation receipt when correctness depends on that transition.

python
# Observe committed lifecycle state; these calls do not prove webhook delivery. paused = client.sandboxes.pause_and_wait(sandbox.id) print(paused.status) running = client.sandboxes.resume_and_wait(sandbox.id) print(running.status)

Process Events#

go
// A one-shot command starts and exits, unlike a cached REPL. _, err = sandbox.Cmd(ctx, `echo "hello world"`) if err != nil { log.Fatal(err) } log.Println("Process events triggered") // Non-zero process exit is result metadata, not an SDK request error. result, err := sandbox.Cmd(ctx, `/bin/sh -c "exit 2"`) if err != nil { log.Fatal(err) } if result.ExitCode != nil { log.Printf("Process exit code: %d", *result.ExitCode) }

File Events#

go
// Ensure watch directory exists _, err = sandbox.Mkdir(ctx, "/tmp/webhook-demo", true) if err != nil { log.Fatal(err) } // Trigger file.modified events (with payload.event_type: "create", "write") _, err = sandbox.WriteFile(ctx, "/tmp/webhook-demo/file.txt", []byte("hello")) if err != nil { log.Fatal(err) } log.Println("File created/written (delivery is asynchronous)") // Trigger file.modified event (with payload.event_type: "rename") _, err = sandbox.MoveFile(ctx, "/tmp/webhook-demo/file.txt", "/tmp/webhook-demo/file-renamed.txt") if err != nil { log.Fatal(err) } log.Println("File renamed (delivery is asynchronous)") // Trigger file.modified event (with payload.event_type: "chmod") _, err = sandbox.Cmd(ctx, `/bin/sh -c "chmod 600 /tmp/webhook-demo/file-renamed.txt"`) if err != nil { log.Fatal(err) } log.Println("File chmodded (delivery is asynchronous)") // Trigger file.modified event (with payload.event_type: "remove") _, err = sandbox.DeleteFile(ctx, "/tmp/webhook-demo/file-renamed.txt") if err != nil { log.Fatal(err) } log.Println("File removed (delivery is asynchronous)")

Agent Events#

Publish custom events from within the sandbox using the webhook publish API:

go
// Publish a custom agent event from within the sandbox _, err = sandbox.Run(ctx, "bash", `curl -X POST http://localhost:49983/api/v1/webhook/publish \ -H "Content-Type: application/json" \ -d '{"payload": {"message": "Task completed", "progress": 100}}'`) if err != nil { log.Fatal(err) } log.Println("Agent event published")

Next Steps#