Receive sandbox events by webhook
Register my HTTPS receiver for Hermitbox sandbox lifecycle events.
Hermitbox can send a signed HTTPS request to your endpoint when a sandbox is created, wakes, goes to sleep, fails or is deleted. Register your endpoint once, and save its signing secret to a private file: Hermitbox shows the secret only at registration.
- Have your HTTPS receiver ready, and pick a new file in an existing private directory for its signing secret.
- Set
HERMITBOX_API_URL,HERMITBOX_API_KEY,HERMITBOX_WEBHOOK_URLandHERMITBOX_WEBHOOK_FILEprivately, and installhermitboxin the Node program that registers the receiver. - Run this once.
import { writeFileSync } from 'node:fs'
import { Hermitbox } from 'hermitbox'
// The receiver and the secret's file come from the environment.
const receiver = process.env.HERMITBOX_WEBHOOK_URL
const file = process.env.HERMITBOX_WEBHOOK_FILE
if (!receiver || !file) {
throw new Error('Set HERMITBOX_WEBHOOK_URL and HERMITBOX_WEBHOOK_FILE')
}
// Connect with HERMITBOX_API_URL and HERMITBOX_API_KEY from the environment.
const hb = new Hermitbox()
// Register the receiver for sandbox creation and deletion.
const hook = await hb.webhook({ url: receiver, kinds: ['created', 'deleted'] })
try {
// Save the signing secret once, to a new private file.
const saved = JSON.stringify({ id: hook.id, secret: hook.secret }) + '\n'
writeFileSync(file, saved, { mode: 0o600, flag: 'wx' })
} catch (error) {
// Without the saved secret the registration is useless, so remove it.
await hook.delete()
throw error
}
console.log('Webhook registered')The block never prints the secret, and it won’t overwrite an existing file. If it can’t save the secret, it removes the registration.
From a terminal, hermitbox webhook create <url> --kinds created,deleted registers the same way
and prints the secret once; webhook ls, webhook rm and webhook deadletters manage
registrations (CLI).
What your receiver gets
- Kinds:
created,running,sleeping,woken,resting,deleted,failed,ttl_expiredandidle_slept. Register only the ones you need. - Payload:
{id, event, sandboxId, at}. It never carries the sandbox’s environment, metadata or secret values. - Signature: verify
hermitbox-signature(v1=and a lowercase hex HMAC-SHA256 with the saved secret) overhermitbox-timestamp, a dot and the exact received bytes. Compare in constant time, reject stale timestamps and deduplicatehermitbox-idacross retries. - Deadline and retries: each attempt has ten seconds. Return 2xx once you have durably accepted
the event; otherwise it is retried after one, two, four and eight minutes, five attempts in all,
then kept as a dead letter (
hermitbox webhook deadletters <webhook-id>).
Lifecycle webhooks has the full receiver contract. Events reflect the lifecycle limits of the sandbox’s tier.
Private receivers
Hermitbox delivers only to public addresses unless the host’s operator allows a private receiver. A caller can’t relax that allowlist.
$curl -fsSL https://hbx.sh | shInstall Hermitbox and set it up for me