Serverless Webhook Reference

Use this reference to implement a webhook endpoint for a serverless agent pool. The endpoint receives a request from Scalr, asks your container platform to start an agent for the requested task, and responds once the launch request is accepted.

For a complete AWS example, follow Serverless Agent Pool on AWS Fargate.

Request body

When a run reaches a stage that needs an agent, Scalr sends an HTTP POST request to the pool's webhook URL with this JSON body:

{
  "task_id": "{agent_task_id}",
  "action": "{action}",
  "run_id": "{run_id}",
  "workspace_id": "{workspace_id}",
  "environment_id": "{environment_id}",
  "created_at": "{created_at}"
}
FieldDescription
task_idID of the agent task assigned to the container.
actionTask type, such as plan, apply, policy.check, or checkov.
run_idID of the run that the agent task belongs to.
workspace_idID of the workspace.
environment_idID of the environment.
created_atTask creation time, such as 2026-11-02T10:15:00+0000.

Headers

HeaderValue
Content-Typeapplication/json
Idempotency-KeyThe agent task ID. The value stays the same across delivery retries.
Custom headersValues configured on the agent pool, such as an endpoint's x-api-key.

Response and retries

The webhook handler must request an agent container launch from the container platform. Once the platform accepts the launch request, the handler must return an HTTP 2xx response to Scalr without waiting for the agent to connect or complete its task. If the launch request fails, the handler must return a non-2xx response.

BehaviorContract
Connection timeout3 seconds.
Response timeout15 seconds.
Successful deliveryAny HTTP 2xx status. No specific response body is required.
Failed deliveryA non-2xx status, timeout, or connection failure. Scalr retries, up to 3 attempts in total.
Retry delay2 seconds before the second attempt, then 4 seconds before the third.

Scalr stops retrying if the agent task is no longer pending, for example because it was acquired or the run was canceled. Your endpoint can therefore receive fewer than 3 attempts.

A 2xx response stops webhook retries, even if the container later fails to start.

A request can be delivered more than once, including when Scalr times out after your endpoint has already started a container. Use Idempotency-Key to recognize retries and avoid launching another container for a request already accepted. If your container platform supports idempotent launches, pass a stable token derived from this header.

Endpoint reachability

The webhook endpoint must be publicly reachable. Agent containers can run in a private network with the required outbound access.

Endpoint access controls

Under Headers on the agent pool, add the header names and credential values your endpoint requires. Scalr sends those header values with each request. A configured header is a static value, not a signature calculated from the request body.

Use separate credentials for the endpoint and the agent. The agent pool token belongs in the container's SCALR_AGENT_TOKEN environment variable. It authenticates the agent to Scalr and is not a webhook credential.

Agent container settings

Use the scalr/agent image, or a custom agent image with the tools your runs need.

Environment variableValuePurpose
SCALR_AGENT_TOKENThe agent pool token, injected from a secret storeConnects the agent to its pool.
SCALR_AGENT_SINGLEtrueRuns one agent task, then exits.
SCALR_AGENT_DRIVERlocalOptional override of automatic driver selection. Executes the task inside the agent container.
SCALR_URLYour Scalr account URLSets the Scalr API endpoint. Optional.
SCALR_AGENT_LOG_FORMATjsonEnables structured logs for troubleshooting. Optional.

On Fargate, the agent selects local automatically. On other Linux container platforms, it also selects local when neither a Docker connection nor Kubernetes access is configured. If your platform provides either connection, set SCALR_AGENT_DRIVER=local to keep task execution inside the agent container.

Configure the container platform to launch a standalone task or job. A service that maintains a desired number of containers can restart an agent after it exits.


Did this page help you?