Skip to main content
All SDK errors inherit from SandboxError.
from porter_sandbox import (
    AuthenticationError,
    NotFoundError,
    RateLimitError,
    SandboxError,
    ServerError,
)

Error classes

ErrorRaised when
SandboxErrorBase class for SDK-raised API errors.
AuthenticationErrorThe API rejects credentials.
NotFoundErrorA sandbox, volume, or other resource cannot be found.
RateLimitErrorThe API returns a rate limit response.
ServerErrorThe API returns a server-side error.
Each SandboxError includes:
AttributeTypeDescription
messagestrHuman-readable error message.
status_codeint | NoneHTTP status code, when available.
bodyobject | NoneParsed response body, when available.

Handle errors

from porter_sandbox import Porter, SandboxError

with Porter() as porter:
    sandbox = porter.sandboxes.create(image="python:3.12-slim")

    try:
        result = sandbox.exec(["python", "-c", "raise SystemExit(2)"])
        if result.exit_code != 0:
            print(result.stderr)
    except SandboxError as exc:
        print(f"Sandbox API error: {exc.message}")
    finally:
        sandbox.terminate()
Non-zero command exit codes are returned in the exec response. They are normal command results, not SDK exceptions.