Skip to content

Exceptions

The exceptions of fastsandbox.

Every failure of the daemon, of the library and of the framework derives from SandboxError. The native extension builds them by class name with the message of docker-sandbox and its details as keyword arguments, so they carry typed attributes and can be caught without importing the extension.

Some classes also derive from the matching built-in exception (ConnectionError, TimeoutError, ValueError, OSError), so that generic handlers keep working.

A misuse of the API raises a built-in exception, not a SandboxError: RuntimeError for the standard input of an interactive session, a tunnel or a lease used once it is closed, shut down or detached; ValueError for an argument that is not one (a duration, a mixin form, an MCP server description); IndexError for an image a kit package does not have (KitPackage.image_archive).

SandboxError

SandboxError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: Exception

Base of every fastsandbox error.

Attributes:

Name Type Description
message

The message of the error.

operation

The operation that failed, e.g. sandbox start, when known.

transient

Whether retrying the same call may succeed (a timeout, a dropped connection, a 5xx answer of the daemon).

DaemonUnavailableError

DaemonUnavailableError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError, ConnectionError

The daemon cannot be reached.

No socket, a refused connection, a broken HTTP exchange or interactive connection.

Attributes:

Name Type Description
path str | None

The socket path that could not be connected to, when known.

SandboxTimeoutError

SandboxTimeoutError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError, TimeoutError

An operation got no outcome in time.

Attributes:

Name Type Description
after float | None

How long it waited, in seconds.

ApiError

ApiError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

The daemon answered with an error status.

Attributes:

Name Type Description
status int

The HTTP status of the answer.

code str | None

The error code of the daemon, when it gives one.

detail str

The message of the daemon.

NotFoundError

NotFoundError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: ApiError

The sandbox, image, rule or execution does not exist (HTTP 404).

ConflictError

ConflictError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: ApiError

The request conflicts with the current state, e.g. a name already in use (HTTP 409).

InvalidInputError

InvalidInputError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: ApiError

The daemon rejected the request as invalid (HTTP 400).

OperationFailedError

OperationFailedError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

The daemon reported the failure of an operation in a successful answer.

E.g. in the progress stream of a creation.

ProtocolError

ProtocolError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

An answer of the daemon could not be decoded.

UnsupportedVersionError

UnsupportedVersionError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

The daemon reports an API version this release was not audited on.

Attributes:

Name Type Description
found str

The version the daemon reports.

supported str

The range this release supports.

InvalidRequestError

InvalidRequestError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError, ValueError

A request was rejected before being sent.

InvalidHostPatternError

InvalidHostPatternError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError, ValueError

A text given to HostPattern(...) names no host a network rule can name.

Raised by HostPattern and HostPattern.parse() alone. The same text in a rule elsewhere raises another class: InvalidRequestError from the client (client.policy.apply(), Sandbox.allow_hosts(), …), InvalidSpecError from a sandbox spec or a task.

Attributes:

Name Type Description
pattern str | None

The text that was given.

reason str | None

Why it names no host, e.g. a host, not a URL: leave the scheme out.

HostFileError

HostFileError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError, OSError

A file or directory of the host could not be accessed.

Attributes:

Name Type Description
path str | None

The path on the host.

ArchiveError

ArchiveError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A tar archive could not be built or extracted.

CommandFailedError

CommandFailedError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A command ran to completion with a non-zero exit code.

Attributes:

Name Type Description
exit_code int

The exit code of the command.

stdout str

Its standard output.

stderr str

Its standard error.

KitPackageError

KitPackageError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A kit package directory is missing or invalid.

Attributes:

Name Type Description
path str | None

The directory of the package.

KitCompileError

KitCompileError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A kit could not be compiled with the sbx CLI.

InvalidKitError

InvalidKitError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A kit the forge refuses, before anything is sent to the daemon.

A kit not named as sbx create names one (a name without a slash that is not an agent, a mixin that names no directory), a mixin only the CLI resolves (an image, a ZIP file, a Git repository), a descriptor the forge cannot take (a spec.yaml that is not in the JSON subset of YAML, a capability a mixin may not declare), or a kit argument the kit does not declare or whose value it refuses.

Attributes:

Name Type Description
kit str | None

The kit refused, e.g. docker.io/sbx/claude:latest or a mixin.

reason str | None

Why it is refused.

KitForgeError

KitForgeError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A kit could not be forged without the sbx CLI.

The kit policy of the daemon forbids it (signed kits required, local kits forbidden, a source not allowed), or the base kit is one only the CLI builds: a directory, a ZIP file or a Git repository. Give the kit cache the CLI (KitCache(sbx="sbx")) to compile such a kit.

InvalidSpecError

InvalidSpecError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError, ValueError

A sandbox spec breaks a rule of a launch, which the message names with its field.

Raised by SandboxSpec.from_json() and with_key() for a form that is not one of a spec or of a key, and by check(), check_keys(), launch() and launch_package() before anything is created: no base kit or two, a host that is not a host pattern, a refusal that covers the host of a key or of an MCP server, a variable set twice, a relative path, mounts without a workspace, a key without a value, or a value no key reads. A task whose spec breaks a rule fails its run with it.

LaunchError

LaunchError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A launch failed once its sandbox existed.

The sandbox was removed, unless kept says it stays: kept by the spec (keep_on_failure()) or because it could not be removed. Its id then removes it, and no other sandbox of its name. The error of the daemon is its __cause__.

Attributes:

Name Type Description
sandbox str | None

The name of the sandbox.

id str | None

The identifier the daemon gave the sandbox at its creation.

step str | None

The step that failed, in the order of a launch: network (its HTTP rules), keys (pushing its keys) or start (its startup commands included).

kept bool

Whether the sandbox stays.

TaskError

TaskError(message: str, *, operation: str | None = None, transient: bool = False, **details: Any)

Bases: SandboxError

A task of a FastSandbox application failed or is misdeclared.