SandboxError, which extends the built-in Error. You can catch SandboxError to handle any Declaw-specific failure, or catch a specific subclass for granular control.
Error hierarchy
SandboxError
Base class for all Declaw errors.
Branch on
code, not on the message. Messages are prose and change between
releases; codes are contract. It matters most where one status means several
unrelated things — a 409 from sandbox creation is either
CODE_IDEMPOTENCY_IN_PROGRESS (the original create is still running) or
CODE_TEMPLATE_NOT_READY (the template needs a rebuild), and only the first is
worth retrying.TimeoutError
Thrown when an operation exceeds its configured timeout.
NotFoundError
Thrown when the sandbox or a requested resource does not exist (HTTP 404).
AuthenticationError
Thrown when the API key is missing or invalid (HTTP 401/403).
InvalidArgumentError
Thrown when a method receives an argument that fails validation. For example,
createTransformationRule() throws this for invalid regex patterns or
disallowed sandbox IDs containing special characters.
NotEnoughSpaceError
Thrown when the sandbox filesystem is full and a write fails.
CommandExitError
Thrown by CommandHandle.wait() when the process exits with a non-zero code.
Contains the full stdout, stderr, and exit code.
CommandExitError is thrown only by handle.wait(). The foreground
sbx.commands.run() (without background: true) returns a CommandResult
with a non-zero exitCode rather than throwing. Check result.exitCode
manually in foreground mode.TemplateError
Base class for template-related errors.
BuildError
Thrown when Template.build() fails.
FileUploadError
Thrown when a file upload fails (e.g. a network error during a write operation).
GitAuthError
Thrown when git operations inside the sandbox fail due to authentication errors.
GitUpstreamError
Thrown when git operations fail due to upstream repository errors.
Catching all Declaw errors
Using error.name for discrimination
Because name is set on every subclass, you can discriminate without instanceof:
Idempotent sandbox creation
Sandbox.create sends an Idempotency-Key automatically. A create that times
out or is retried will not leave a second running, billable sandbox behind: the
key is generated once per logical create and reused across that call’s retries,
so the server replays the original response instead of starting a new sandbox.
The SDK also retries a 409 carrying CODE_IDEMPOTENCY_IN_PROGRESS on your
behalf, honoring Retry-After. That is how the sandbox ID is recovered when the
original response was lost — you do not need to write that loop.