sandpi/ platform

Observe & control

Events & results

Stream execution, reconnect and inspect output, diffs and usage.

On this page

Stream a Run

Replay Run events over SSE

GET /v1/environments/{environmentId}/sessions/{sessionId}/runs/{runId}/events

Authentication: Platform API bearer token

Parameters and headers
FieldType and constraintsRequiredDescription
query: afterinteger · ≥ 0; ≤ 9007199254740991NoLast processed event ID or pagination cursor. Return only subsequent records; retain it when reconnecting or fetching another page.
path: environmentIdstring · min length 1YesEnvironment identifier. It must belong to the caller’s account or Project.
path: sessionIdstring · min length 1YesExisting Session identifier within the named Environment.
path: runIdstring · min length 1YesRun identifier within the named Environment and, where applicable, Session.
header: last-event-idstring
Validation pattern^[0-9]+$
NoLast received event ID for replay.

Request example

sh
curl -N \
    "https://api.sandpi.ai/v1/environments/$ENVIRONMENT_ID/sessions/$SESSION_ID/runs/$RUN_ID/events" \
    -H "Authorization: Bearer $SANDPI_API_TOKEN" \
    -H "last-event-id: 42"

No request body.

Responses

200 Successful response.
Response body text/event-stream
FieldType and constraintsRequiredDescription
bodystringYes—
Example
Example
id: 42
event: run.output
data: {"id":42,"type":"run.output"}

Stream event names
run.queuedrun.runningrun.nativerun.outputrun.completedrun.failedrun.stoppedrun.stop_requestedrun.revertingrun.revertedrun.file_diff_readyrun.file_diff_failedrun.checkpoint_readyrun.message.queuedrun.message.acceptedrun.message.rejectedrun.message.unconfirmedrun.native_finishedrun.runtime_unavailablerun.runtime_recoveredrun.resource_observation
Error responses
400 Invalid request.

application/json

401 Missing or invalid Platform API token.

application/json

404 Resource not found or outside token scope.

application/json

default Sandpi error.
Error body application/json

Standard error envelope containing a stable code, diagnostic message and request identity.

FieldType and constraintsRequiredDescription
errorobject · extra fields rejectedYesStructured failure information. Inspect the stable code and retain the request ID for investigation.
error.codestringYeswithin errorStable error code used to distinguish failures programmatically.
error.messagestringYeswithin errorHuman-readable diagnostic text.
error.requestIdstringYeswithin errorRequest identifier for correlating diagnostics and support investigations.
error.detailsanyNowithin errorOptional structured error context. Its shape is specific to the service failure.
error.loginUrlstringNowithin errorAuthentication URL supplied when a browser login is required.
error.registrationOpenbooleanNowithin errorWhether new account registration is enabled for this deployment.
Example
Example
{
  "error": {
    "code": "platform_balance_insufficient",
    "message": "Top up Platform credits before submitting a Run.",
    "requestId": "req_example"
  }
}

Run events use Server-Sent Events. Each durable event has an ID; store the last processed ID together with your application’s processing progress. Native payloads remain harness-specific. Use normalized Run state for application status, and preserve native payloads when inspecting detailed execution.

Reconnect without repeating work

Send Last-Event-ID or after with the last received ID to replay later events. The tutorial’s generated example shows the replay header; omit it for a first connection. Heartbeats keep an idle observer active, but proxies and networks can still disconnect.

Closing the stream does not stop the Run. Keep the existing Run ID and reconnect. Use the Run detail API to reconcile state independently of the stream connection.

Get Run state and Sandbox usage

GET /v1/environments/{environmentId}/sessions/{sessionId}/runs/{runId}

Authentication: Platform API bearer token

Parameters and headers
FieldType and constraintsRequiredDescription
path: environmentIdstring · min length 1YesEnvironment identifier. It must belong to the caller’s account or Project.
path: sessionIdstring · min length 1YesExisting Session identifier within the named Environment.
path: runIdstring · min length 1YesRun identifier within the named Environment and, where applicable, Session.

Request example

sh
curl \
    "https://api.sandpi.ai/v1/environments/$ENVIRONMENT_ID/sessions/$SESSION_ID/runs/$RUN_ID" \
    -H "Authorization: Bearer $SANDPI_API_TOKEN"

No request body.

Responses

200 Successful response.
Response body application/json
FieldType and constraintsRequiredDescription
dataobject · extra fields rejectedYesRun details with posted Sandbox runtime and retained historical managed-model settlement; BYOK model costs are billed by your provider.
data.idstringYeswithin dataResource identifier used to read or manage this resource.
data.environmentIdstringYeswithin dataEnvironment identifier. It must belong to the caller’s account or Project.
data.sessionIdstringYeswithin dataExisting Session identifier within the named Environment.
data.environmentSequenceinteger · ≥ -9007199254740991; ≤ 9007199254740991Yeswithin dataEnvironment-wide Run ordering across all Sessions; rollback uses this ordering.
data.modelstringYeswithin dataExact native model ID served by your provider or gateway.
data.inputstringYeswithin dataInstructions supplied to the agent for this task.
data.filesarrayYeswithin dataFiles associated with this resource; each item is described below.
data.files[]object · extra fields rejectedYeseach array itemReference to an existing regular workspace file checked before execution.
data.files[].pathstringYeseach array itemCanonical absolute path inside /workspace. Protected state, Git metadata and symlinks are not accepted file targets.
data.files[].sha256string
Validation pattern^[a-f0-9]{64}$
Noeach array itemLowercase hexadecimal SHA-256 digest of the file bytes.
data.statusstring · values: "queued" | "running" | "completed" | "failed" | "stopped" | "reverting" | "reverted"Yeswithin dataCurrent resource state; inspect the allowed values and the operation’s lifecycle notes.
data.stopRequestedbooleanYeswithin dataWhether a client has requested that the native task stop.
data.outputstringNowithin dataFinal agent output when available. Content retention may erase this field.
data.fileDiffarrayYeswithin dataManifest of added, modified and deleted regular workspace files. It does not contain file bytes.
data.fileDiff[]object · extra fields rejectedYeseach array itemRegular workspace file change with before and after content digests.
data.fileDiff[].pathstringYeseach array itemCanonical absolute path inside /workspace. Protected state, Git metadata and symlinks are not accepted file targets.
data.fileDiff[].kindstring · values: "added" | "modified" | "deleted"Yeseach array itemWhether the Run added, modified or deleted the regular file.
data.fileDiff[].beforeSha256string
Validation pattern^[a-f0-9]{64}$
Noeach array itemContent digest before the Run; absent for a newly added file.
data.fileDiff[].afterSha256string
Validation pattern^[a-f0-9]{64}$
Noeach array itemContent digest after the Run; absent for a deleted file.
data.fileDiffStatusstring · values: "pending" | "ready" | "failed"Yeswithin dataFile-diff computation state, separate from execution and checkpoint state.
data.fileDiffErrorstringNowithin dataDiagnostic text when file-diff computation fails.
data.checkpointobject · extra fields rejectedYeswithin dataRootFS checkpoint state and identifier, tracked separately from native execution.
data.checkpoint.statusstring · values: "pending" | "ready" | "failed" | "skipped"Yeswithin dataCurrent resource state; inspect the allowed values and the operation’s lifecycle notes.
data.checkpoint.snapshotIdstringNowithin dataSandbox0 checkpoint identifier. Use a returned initial or Run checkpoint when pinning a fork.
data.checkpoint.errorstringNowithin dataStructured failure information. Inspect the stable code and retain the request ID for investigation.
data.createdAtstring · format: date-time
Validation pattern^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
Yeswithin dataCreation time as a UTC date-time string.
data.startedAtstring · format: date-time
Validation pattern^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
Nowithin dataExecution start time as a UTC date-time string.
data.finishedAtstring · format: date-time
Validation pattern^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
Nowithin dataTerminal execution time as a UTC date-time string.
data.usageobject · extra fields rejectedYeswithin dataPosted Sandbox runtime usage and retained historical managed-model settlement. New BYOK Runs have no rated model-call ledger; provider usage and cost are recorded by the customer’s provider or gateway.
data.usage.callsarrayYeswithin dataHistorical rated managed-model calls only. Empty for new BYOK Runs; does not measure native model requests.
data.usage.calls[]object · extra fields rejectedYeseach array item—
data.usage.calls[].idstringYeseach array itemResource identifier used to read or manage this resource.
data.usage.calls[].providerstring · values: "openai" | "anthropic" | "kimi" | "zai" | "deepseek"Yeseach array itemNative model family associated with this Harness; not a Sandpi Token supplier.
data.usage.calls[].modelstringYeseach array itemExact native model ID served by your provider or gateway.
data.usage.calls[].priceVersionstringYeseach array itemHistorical managed-model settlement only. Immutable version of the published price captured for rating.
data.usage.calls[].priceSourceUrlstring · format: uriYeseach array itemHistorical managed-model settlement only. Official provider pricing reference captured with the immutable price version.
data.usage.calls[].usageCategoriesobjectYeseach array itemHistorical managed-model settlement only. Provider-reported usage by category, such as uncached input, cached input and output tokens.
data.usage.calls[].usageCategories.{key}numberNoadditional keys—
data.usage.calls[].ratedLinesarrayYeseach array itemHistorical managed-model settlement only. Rated accounting line items for the provider call.
data.usage.calls[].ratedLines[]anyYeseach array item—
data.usage.calls[].upstreamAmountUsdstringYeseach array itemHistorical managed-model settlement only. Published base-rate usage amount in USD, represented as a decimal string.
data.usage.calls[].serviceFeeUsdstringYeseach array itemHistorical managed-model settlement only. Itemized service fee in USD, represented as a decimal string.
data.usage.calls[].totalAmountUsdstringYeseach array itemHistorical managed-model settlement only. Total rated charge in USD, represented as a decimal string.
data.usage.calls[].createdAtstring · format: date-time
Validation pattern^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
Yeseach array itemCreation time as a UTC date-time string.
data.usage.calls[].serviceFeePercentnumber · values: 0 | 5 | 10 | 15Yeseach array itemHistorical managed-model settlement only. Service fee captured by this call’s immutable price version; zero for legacy calls.
data.usage.serviceFeePercentnumber · values: 0 | 5 | 10 | 15 | nullYeswithin dataHistorical managed-model fee shared by all calls, or null for mixed historical tiers. Zero for new BYOK Runs; Sandpi adds no model service fee.
data.usage.upstreamAmountUsdstringYeswithin dataHistorical managed-model base charges in USD. Zero for new BYOK Runs; excludes charges billed directly by your model provider.
data.usage.serviceFeeUsdstringYeswithin dataHistorical managed-model service fees in USD. Zero for new BYOK Runs.
data.usage.totalAmountUsdstringYeswithin dataPosted Sandbox runtime plus retained historical managed-model charges in USD. Excludes model charges billed directly by your provider or gateway.
data.usage.sandboxAmountUsdstringYeswithin dataPosted Sandbox runtime charge attributed to this Run. Environment initialization and file access may incur separate Environment charges.
data.usage.sandboxRuntimeSecondsnumber · ≥ 0Nowithin dataAuthoritative billed Sandbox time attributed to this Run.
Example
Example
{
  "data": {
    "id": "",
    "environmentId": "",
    "sessionId": "",
    "environmentSequence": -9007199254740991,
    "model": "",
    "input": "",
    "files": [
      {
        "path": ""
      }
    ],
    "status": "queued",
    "stopRequested": false,
    "fileDiff": [
      {
        "path": "",
        "kind": "added"
      }
    ],
    "fileDiffStatus": "pending",
    "checkpoint": {
      "status": "pending"
    },
    "createdAt": "2026-10-12T01:00:00Z",
    "usage": {
      "calls": [],
      "serviceFeePercent": 0,
      "upstreamAmountUsd": "",
      "serviceFeeUsd": "",
      "totalAmountUsd": "",
      "sandboxAmountUsd": ""
    }
  }
}
Error responses
400 Invalid request.

application/json

401 Missing or invalid Platform API token.

application/json

404 Resource not found or outside token scope.

application/json

default Sandpi error.
Error body application/json

Standard error envelope containing a stable code, diagnostic message and request identity.

FieldType and constraintsRequiredDescription
errorobject · extra fields rejectedYesStructured failure information. Inspect the stable code and retain the request ID for investigation.
error.codestringYeswithin errorStable error code used to distinguish failures programmatically.
error.messagestringYeswithin errorHuman-readable diagnostic text.
error.requestIdstringYeswithin errorRequest identifier for correlating diagnostics and support investigations.
error.detailsanyNowithin errorOptional structured error context. Its shape is specific to the service failure.
error.loginUrlstringNowithin errorAuthentication URL supplied when a browser login is required.
error.registrationOpenbooleanNowithin errorWhether new account registration is enabled for this deployment.
Example
Example
{
  "error": {
    "code": "platform_balance_insufficient",
    "message": "Top up Platform credits before submitting a Run.",
    "requestId": "req_example"
  }
}

Separate completion from checkpoint readiness

A terminal execution event means the native task ended. Output can be available while the file diff, checkpoint or accounting is still settling. checkpoint.status and fileDiffStatus are separate from Run status. Watch checkpoint events or poll the Run before accessing files or forking.

Transient Sandbox0 conflicts, rate limits and service errors can leave checkpoints pending with diagnostic text. The worker retries with backoff; checkpoint recovery does not execute the model task again.

Inspect changed files

The Run diff lists added, modified and deleted regular files under /workspace with before/after SHA-256 identities. Sandpi-managed state, Git metadata and generated caches are excluded. Diff computation can fail on a large workspace while Run output and the checkpoint remain valid.

Retrieve actual file content through the file API; the diff is a manifest, not a patch download.

Interpret usage evidence

Run usage reports posted Sandbox runtime charges. The model-call and service-fee fields are retained for historical managed-model settlement; new BYOK Runs do not populate that ledger. Model token usage and cost must come from native Harness events where available and your provider or gateway records. See billing for attribution and settlement timing. Record commands, exit codes and validation results in a workspace artifact when your Controller requires a reproducible execution report.

Account for retention

Content retention can clear output and replayable content events while leaving minimal Run identity and settlement facts. Check contentDeletedAt when historical content is missing. See retention and deletion and billing.

Runtime availability

When Sandbox execution or observation times out, the Run exposes error.code = platform_runtime_unavailable and emits run.runtime_unavailable. The console displays this diagnostic even while the Run remains running: the native task may still be executing. High CPU or memory load is one possible cause; a timeout alone does not establish OOM.

Keep the same Run ID. Reconciliation retries with backoff and reconnects to the original execution. Successful runtime access clears the transient error and emits run.runtime_recovered. These events do not stop, restart or duplicate the task. Use the Environment's Settings to check Sandbox health and resource usage; release unused browser tabs or processes before retrying access.

Runtime warnings appear before any optional resource query. A background telemetry-only query has a shared two-second deadline and is limited to once per Environment every 30 seconds. If supported, run.resource_observation adds timestamped CPU and memory samples to the existing warning. The same observations appear after a TUI connection error. Normal connections issue no additional diagnostic requests.

Only fresh, continuous samples from the current runtime are shown. A single spike, missing bucket, collector reset, stale/partial response, changed generation or mismatched memory limit does not establish sustained load. “Near its allocated limit” requires every sample in a sequence spanning at least 15 seconds to be at least 95%. This describes quota utilization, not an abnormal task, an OOM event, or proof that resource use caused the timeout. Missing or slow telemetry leaves the cause unconfirmed.