Skip to Content
API reference

Errors

Stable error codes, AlineoError, and the CommandError, SandboxError, ExecConnectionError, WorkflowError and SandboxClientError classes.

import {
  CommandError,
  SandboxError,
  ExecConnectionError,
  WorkflowError,
  SandboxClientError,
} from "@alineo-labs/sandbox";

Error codes

Every error alineo raises on purpose carries a stable code. Branch on the code, not on the class name or the message text. The classes below all carry one.

import { errorCodeOf, isRetryable } from "@alineo-labs/sandbox";

try {
  await sb.exec("true");
} catch (e) {
  const code = errorCodeOf(e); // "SANDBOX_NOT_FOUND", or undefined for a foreign error
  if (code === "SANDBOX_NOT_FOUND") await client.sandbox({ image, resources });
  else if (isRetryable(e))
    await sleep(1000); // the same call may succeed later
  else throw e;
}
ExportWhat it does
AlineoErrorBase class. Has code, category, retryable, hint and details.
errorCodeOf(value)The code behind a thrown value, or undefined. Reads the cause chain, and a code that crossed a JSON boundary.
isAlineoError(value)True for an AlineoError, including one made by another copy of the package.
isRetryable(value)True when the same call, unchanged, may succeed on a later attempt. A hint, not proof.

hint says what to do next, for example "Call resume() first." The CLI prints it on a Hint: line. details holds scalars only (ids, counts, durations), never a secret.

Categories

CategoryMeaning
transientA later attempt of the same call may succeed.
permanentThe same call will fail again. Change the call.
configConfiguration, credentials or the environment is wrong.
capabilityThe sandbox provider does not support what was asked.
internalA bug, or a failure with no better code.

All codes

CodeCategoryRetryableHTTPMeaning
SANDBOX_NOT_FOUNDpermanentno404The sandbox does not exist on the server (deleted, expired, or never created).
SANDBOX_NOT_RUNNINGpermanentno409The sandbox exists but is not in the Running state (for example Terminated or Failed).
SANDBOX_PAUSEDpermanentno409The sandbox is paused, so the operation cannot run.
SANDBOX_START_FAILEDpermanentno502The sandbox entered Failed or Terminated while starting.
SANDBOX_START_TIMEOUTtransientyes504The sandbox did not reach Running within the allowed time.
SESSION_NOT_FOUNDpermanentno404No session with that id exists in the ledger.
CHECKPOINT_NOT_FOUNDpermanentno404The session has no checkpoint to restore from.
SNAPSHOT_FAILEDpermanentno502The server reported the snapshot as Failed.
SNAPSHOT_TIMEOUTtransientyes504The snapshot did not become ready within the allowed time.
EXEC_NOT_READYtransientyes503The sandbox is Running, but the exec daemon (execd) inside it never accepted a connection.
COMMAND_FAILEDpermanentno422A command in the sandbox exited with a non-zero code.
STEP_TIMEOUTtransientyes504A workflow step exceeded its time limit.
INVALID_ARGUMENTpermanentno400An argument or option was rejected before any request was sent.
SPEC_INVALIDconfigno400An agent spec failed validation.
CAPABILITY_UNSUPPORTEDcapabilityno501The sandbox substrate or its configuration does not support this operation.
CREDENTIAL_UNRESOLVEDconfigno422A credential binding could not be resolved from its source.
PROVIDER_AUTHconfigno502The sandbox provider rejected the credentials (401 or 403).
PROVIDER_RATE_LIMITEDtransientyes429The sandbox provider rate-limited the request (429).
PROVIDER_UNAVAILABLEtransientyes503The sandbox provider answered with a server error (5xx).
PROVIDER_MISMATCHconfigno409The session was created on a different sandbox provider than the one this client is configured for.
PROVIDER_ERRORinternalno502The sandbox provider rejected the request with an error that has no better code.
MODEL_RATE_LIMITEDtransientyes429The model provider rate-limited the request (429) and ended the turn.
MODEL_UNAVAILABLEtransientyes503The model provider was overloaded or unavailable (5xx) and ended the turn.
PROMPT_TIMEOUTtransientyes504A prompt produced no activity within the inactivity window.
BRIDGE_DISCONNECTEDtransientyes502The agent bridge closed its connection before it signalled the turn was done.
AGENT_NOT_FOUNDpermanentno404The daemon has no agent with that id.
RUN_NOT_FOUNDpermanentno404The daemon has no run with that id.
AGENT_NOT_LIVEpermanentno409The agent exists but is not live in this daemon, so it cannot take the call.
AGENT_BUSYtransientyes409The agent is still finishing its previous turn.
LIMIT_EXCEEDEDtransientyes429A per-tenant limit set by the daemon's operator stops this request.
TENANT_SUSPENDEDpermanentno403The daemon's operator has suspended this tenant. New work is refused.
INTERNALinternalno500A failure with no more specific code.

The same codes appear in the code field of an alineod HTTP error. A failure from the execd client (a command or file call) is an OpenSandboxError, an AlineoError that also keeps the server's own code in .upstreamCode.

Error hierarchy

Error
├── WorkflowError            — base class for Sandbox-level errors
│   ├── SandboxError        — sandbox lifecycle failure: create/boot/Running, paused, unsupported fork(), or snapshot
│   ├── ExecConnectionError — execd not ready after retry window
│   └── CommandError        — non-zero exit code in strict mode
└── SandboxClientError                — client-level errors from Sandbox itself (not a WorkflowError)

SandboxError, ExecConnectionError, and CommandError all extend WorkflowError, which extends Error — catch all three with e instanceof WorkflowError. SandboxClientError is a separate, sibling class thrown by Sandbox client methods (sandbox(), resume(), sandboxes.*, environment()) rather than by Sandbox methods — see SandboxClientError below.

WorkflowError

Base class. Has message and name properties. name is always "WorkflowError".

import { WorkflowError } from "@alineo-labs/sandbox";

try {
  await sb.exec("cmd");
} catch (e) {
  if (e instanceof WorkflowError) {
    console.error("alineo error:", e.message);
  } else {
    throw e;
  }
}

CommandError

Thrown when sb.exec() exits with a non-zero code and strict: true (the default).

import { CommandError } from "@alineo-labs/sandbox";

try {
  await sb.exec("exit 42");
} catch (e) {
  if (e instanceof CommandError) {
    console.error(`exit ${e.exitCode}`); // 42
    console.error(`command: ${e.command}`); // "exit 42"
    console.error(`sandbox: ${e.sandboxId}`);
  }
}

Properties

PropertyTypeDescription
exitCodenumberThe process exit code
commandstringThe command string that was run
sandboxIdstringThe sandbox ID where it ran
stdoutstringAll the output the command wrote to stdout
stderrstringAll the output the command wrote to stderr
messagestring"Command exited with code N: <cmd>", then a new line and the last 2000 characters of stderr (of stdout when stderr is empty)
namestring"CommandError"

Avoiding CommandError

Pass { strict: false } to get the exit code in the result:

const { exitCode } = await sb.exec("test -f /etc/hosts", { strict: false });

SandboxError

Thrown by methods on SandboxHandle itself: resume() if the container never reaches Running (or enters Failed/Terminated), an exec call while the sandbox is paused, fork() when the deps don't support it, or a failed snapshot wait.

A failure during client.sandbox()'s own initial creation throws SandboxClientError, not SandboxError — see below.

import { SandboxError } from "@alineo-labs/sandbox";

try {
  await sb.resume(); // sandbox previously pause()d, now stuck
} catch (e) {
  if (e instanceof SandboxError) {
    console.error(e.message); // e.g. "Sandbox entered Failed: ..." or "sandbox is paused — call resume() first"
    console.error(e.sandboxId ?? ""); // sandbox ID if assigned before failure
  }
}

Properties

PropertyTypeDescription
sandboxIdstring | undefinedContainer ID if one was assigned before the failure
messagestringDescribes what failed
namestring"SandboxError"

ExecConnectionError

Thrown when the execd daemon inside the container never becomes ready within the retry window (~15 seconds). The container is Running from OpenSandbox's perspective, but the exec daemon isn't accepting connections.

import { ExecConnectionError } from "@alineo-labs/sandbox";

try {
  await sb.exec("echo test");
} catch (e) {
  if (e instanceof ExecConnectionError) {
    console.error(e.message); // "execd not ready for sandbox <id>"
    console.error(e.sandboxId); // the sandbox ID
  }
}

Properties

PropertyTypeDescription
sandboxIdstringThe sandbox ID
messagestring"execd not ready for sandbox <id>"
namestring"ExecConnectionError"

This usually means the container image doesn't include execd, or the container started but the execd process crashed.

SandboxClientError

Thrown by the Sandbox client for API-level errors (404 not found, timeouts waiting for Running state):

import { SandboxClientError } from "@alineo-labs/sandbox";

try {
  await client.resume("nonexistent-id");
} catch (e) {
  if (e instanceof SandboxClientError) {
    console.error(e.message); // "Session nonexistent-id not found"
    console.error(e.status); // 404
  }
}

SandboxClientError is not a WorkflowError — it's a separate class for client-level errors.