API keys and webhooks
Create scoped API keys for CI pipelines and verify HMAC-signed webhooks delivered when labs pass, candidates complete assessments, or security probes expose canaries.
Managing API keys
Open Settings (/settings) and create a key under API keys. New tokens begin with sg_live_ and are displayed once; ServerGym stores only the SHA-256 digest and a short prefix in SQLite.
Keys default to the eval:run, sessions:write, and twins:scan scopes. Send keys as Authorization: Bearer sg_live_... on Eval API calls, and revoke compromised keys at any time from Settings.
Signed webhook events
Register an HTTPS endpoint under Event webhooks in Settings and subscribe to one or more events:
session.passed— fired when a user’s lab session passes verification.hiring.completed— fired when a candidate passes a timed assessment.pentest.critical— fired when a security twin probe exposes one or more synthetic canaries.battle.finished— fired when a Human vs. AI match completes.
To prevent SSRF, live webhook URLs must use HTTPS and cannot target loopback, RFC 1918/ULA private IPs, or .local / .internal addresses. For safe testing, URLs on *.fake or example.com run in simulated delivery mode so you can trigger Send test and inspect signed deliveries directly in Settings.
Webhook headers and payload
Every delivery sends a JSON body with two ServerGym headers: X-ServerGym-Event (the event name) and X-ServerGym-Signature (sha256=<hex> computed as HMAC-SHA256 over the raw JSON body using your endpoint’s whsec_* secret):
{
"id": "evt_1a2b3c4d5e",
"event": "hiring.completed",
"platform": "servergym",
"timestamp": "2026-04-01T14:20:00.000Z",
"data": {
"inviteId": "inv-12345678",
"scenarioSlug": "wp-multitenant-500",
"sessionId": "sess-abcdef1234",
"score": 100,
"passed": true,
"durableFix": true,
"blastRadiusIntact": true
}
}
Verifying X-ServerGym-Signature
Compute the expected HMAC-SHA256 digest over the exact raw request bytes and compare with a constant-time equality check:
import crypto from 'node:crypto';
export function verifyWebhook(rawBody, headerSig, signingSecret) {
if (typeof headerSig !== 'string') return false;
const expected =
'sha256=' +
crypto.createHmac('sha256', signingSecret).update(rawBody).digest('hex');
const expectedBuf = Buffer.from(expected, 'utf8');
const actualBuf = Buffer.from(headerSig, 'utf8');
if (expectedBuf.length !== actualBuf.length) return false;
return crypto.timingSafeEqual(expectedBuf, actualBuf);
}