Cubicle

SDK reference

The Cubicle and error classes, and every type the @cubicle/sdk package exports.

Classes

Type Aliases

ApiKeyScope

type ApiKeyScope = "read" | "write";

read keys may only make GET requests; write keys may use every route that takes keys.


BoxInfo

type BoxInfo = object;

A Box as the Cubicle API reported it when it was fetched. It does not update itself: call Boxes.get or BoxRef.info again for current values.

Properties

PropertyTypeDescription
baseImagestringThe base image ID, such as default or omarchy. A snapshot's Box keeps its source's.
connectionGenerationnumberAdvances with every start, stop, hibernation (automatic ones too), deletion and restore, and when the Box's host restarts, but not when a failed hibernation returns the Box to running. Host keys, guest accounts and private-network access from an earlier value no longer apply, so SSH and private-network traffic reaches the Box only once it runs at the new value.
consoleReadinessWhether the desktop console can be opened now.
createdAtstringWhen the Box was created, as an ISO 8601 timestamp.
deletion"pending" | "complete" | nullpending from an accepted delete until its Node has removed the Box, after which listings no longer show it; otherwise null. complete appears only when a create repeated with the same idempotencyKey returns a Box that has been removed since.
desiredobjectWhat the Box was last asked to be. generation advances with every accepted change.
desired.generationnumber-
desired.stateDesiredState-
expiresAtstring | nullWhen a stopped or hibernated free Box is deleted unless it is started again.
hibernateAtstring | nullWhen a running Box hibernates automatically, 60 minutes after its current start first reported running. Activity does not extend it. null when none is scheduled.
hibernationRetryAtstring | nullWhen Cubicle retries a hibernation that failed, or null.
idstringThe Box's ID, a UUID. It never changes and is never reused.
namestringUnique among the organization's Boxes that are not deleted. Freed when the Box is deleted.
nodeobjectThe Node (host) the Box lives on for its whole life. healthy: it reported recently.
node.healthyboolean-
node.idstring-
node.namestring-
observed| { ageSeconds: number | null; error: string | null; fresh: boolean; generation: number | null; observedAt?: string; state: string; } | nullThe Node's last report about the Box, or null before its first report: the state it observed, the desired generation it had applied, its last error for the Box, when it reported (observedAt, ageSeconds), and whether the report is fresh.
orgobjectThe organization that owns the Box.
org.idstring-
org.namestring-
pooledbooleanA free Box: its CPU and memory are reserved only while it runs.
privateIpstring | nullGuest address on its Node's Box subnet, reached through Gateway.
restartRequiredbooleanThe Box's host restarted while the Box was running. It stays down until started again.
specResourcesThe Box's size.
sshReadinessWhether exec and new SSH connections can be used now: the Box runs at its current generation. It does not check the caller's own access or SSH key.
stateBoxStateThe Box's state, from its Node's last report. It may predate your latest request. unknown means the Node has not reported recently: neither running nor stopped.

BoxState

type BoxState = 
  | "pending"
  | "unknown"
  | "deleted"
  | "absent"
  | "provisioning"
  | "starting"
  | "running"
  | "stopping"
  | "stopped"
  | "hibernating"
  | "hibernated"
  | "deleting"
  | "failed";

A Box's state, as BoxInfo.state reports it: the state its Node last observed, or one Cubicle derives. pending means a new Box has no report yet. unknown means its Node has not reported recently, so the Box is neither known to be running nor stopped. Current Nodes never report absent.


CreateBoxOptions

type CreateBoxOptions = LifecycleOptions & object;

Options for Boxes.create.

Type Declaration

NameTypeDescription
idempotencyKey?stringMakes the create safe to repeat: a second create with the same key and parameters returns the same Box. A new key is generated per call when omitted. Keys are 1 to 200 characters and are kept for 7 days. Reusing one with different parameters rejects with idempotency_conflict.

CreateBoxParams

type CreateBoxParams = object;

What Boxes.create creates. Every field is optional.

Properties

PropertyTypeDescription
baseImage?stringA base image ID: default (the default) or omarchy; see Cubicle.listBases. Exclusive with snapshotId.
diskGiB?numberDisk in GiB, 1 to 2048. Defaults like vcpus. With snapshotId, it may grow the source Box's disk but not shrink it.
memoryMiB?numberMemory in MiB, 256 to 262144. Defaults like vcpus.
name?stringUnique in its organization: 1 to 63 lowercase letters, digits and dashes, starting with a letter or digit. Generated (box- and six hex digits) when omitted.
org?stringOrganization name or ID. Defaults to the client's org, then the API key's organization.
snapshotId?stringCreate from a completed snapshot, by its ID; see Cubicle.listSnapshots. The Box is placed on the snapshot's Node and keeps its source's base image.
start?booleanfalse creates the Box stopped; create then returns without waiting. Default true.
vcpus?numberVirtual CPUs, 1 to 64. Defaults to the base image's size, or the source Box's for snapshotId.

CreationBase

type CreationBase = object;

A base image and whether any Node can place it: available is true when a healthy Node has the image. It does not consider free capacity.

Properties

PropertyType
availableboolean
idstring
namestring
specResources

CreationSnapshot

type CreationSnapshot = object;

A completed snapshot the caller may create a Box from.

Properties

PropertyTypeDescription
boxobjectThe Box it was taken from.
box.idstring-
box.namestring-
createdAtstringWhen it was requested, as an ISO 8601 timestamp.
idstringThe snapshot's ID, for create's snapshotId.
namestringThe snapshot's name.
nodeobjectThe Node that holds it. A Box created from it is placed on this Node.
node.idstring-
node.namestring-
specResourcesThe source Box's size, which a Box created from it defaults to.

CubicleOptions

type CubicleOptions = object;

Options for Cubicle. Every field is optional; apiUrl and apiKey fall back to environment variables. A value out of range throws invalid_option.

Properties

PropertyTypeDescription
apiKey?stringA service account API key (cbk_…). Defaults to CB_SDK_API_KEY.
apiUrl?stringThe Cubicle API URL, such as https://api.cubicle.sh; it must use http or https. Defaults to CB_SDK_API_URL.
fetch?FetchReplaces the global fetch, for proxies or tests.
maxPollsPerSecond?numberThe most polls per second across all of this client's waits: 0.001 to 1000. Default 5, which keeps many concurrent waits inside the API's rate limit of 600 requests a minute per user or service account. Every API key of one service account shares that limit. See Rate limits
maxRetries?numberRetries for rate limits, transient failures and connection failures: 0 to 100. Default 3. Waits ignore it: they retry their reads until their own timeout.
org?stringOrganization name or ID for boxes.create, boxes.list, listBases and listSnapshots, and for narrowing bare Box names. An API key belongs to one organization, which is used when this is omitted.
pollIntervalMs?numberHow often each wait polls the API, in ms. Default 1 s.
requestTimeoutMs?numberTimeout for each attempt of a request, in ms. Default 30 s.

DesiredState

type DesiredState = "running" | "stopped" | "hibernated" | "deleted";

The state a Box was last asked to reach, as BoxInfo.desired reports it.


ExecOptions

type ExecOptions = object;

Options for Boxes.exec.

Properties

PropertyTypeDescription
cwd?stringAbsolute working directory in the guest. Defaults to the guest account's home directory.
idempotencyKey?stringMakes the request safe to repeat. A new key is generated per call when omitted.
maxOutputBytes?numberCuts stdout and stderr, counted together, at this many bytes. Defaults to 64 KiB, at most 1 MiB.
signal?AbortSignalStops waiting for the result; the command keeps running.
timeoutMs?numberStops the command after this many ms, at least 100. Defaults to 60 s; larger values are lowered to 10 min. exec waits for the result this long plus 2 minutes.
wake?booleanStart a stopped or hibernated Box, and wait until it is ready, before running. A running Box is never restarted.

ExecOutput

type ExecOutput = object;

The result of a completed exec operation.

Properties

PropertyTypeDescription
exitCodenumberThe command's exit code. A command stopped at its timeout reports 124.
stderrstringStandard error, decoded as UTF-8.
stdoutstringStandard output, decoded as UTF-8.
timedOutbooleanThe command ran past its timeoutMs and was stopped.
truncatedbooleanOutput was cut at maxOutputBytes.

ExecResult

type ExecResult = ExecOutput & object;

A finished command. A non-zero exitCode is a result, not an error. operationId is the exec operation's ID.

Type Declaration

NameType
operationIdstring

Fetch

type Fetch = (input, init) => Promise<Response>;

A fetch-compatible function, for CubicleOptions.fetch.

Parameters

ParameterType
inputstring
initRequestInit

Returns

Promise<Response>


LifecycleOptions

type LifecycleOptions = WaitOptions & object;

Options for Boxes.start, Boxes.stop, Boxes.hibernate and Boxes.delete.

Type Declaration

NameTypeDescription
wait?booleanWait until the Box reaches the requested state. Default true. false resolves as soon as Cubicle accepts the request.

Me

type Me = object;

The caller, as Cubicle.me returns it.

Properties

PropertyTypeDescription
apiKey?objectPresent when an API key authenticated; orgs then holds only its organization. A key issued to a connected application has the application scope and lists its permissions.
apiKey.connection?object-
apiKey.connection.applicationIdstring-
apiKey.connection.idstring-
apiKey.connection.permissionsstring[]-
apiKey.idstring-
apiKey.orgIdstring-
apiKey.scopeApiKeyScope | "application"-
idstringThe user or service account ID.
identitystringAn email address, or ORG/NAME for a service account.
operator?booleantrue for platform operators.
orgsobject[]The organizations the caller belongs to, with its role in each.

Operation

type Operation = object;

A durable exec, snapshot or restore request, as Operations.get returns it.

Properties

PropertyTypeDescription
attemptnumberHow many times a Node has started it.
boxIdstringThe ID of the Box it acts on.
completedAtstring | nullWhen it finished, or null.
createdAtstringWhen it was requested, as an ISO 8601 timestamp.
errorstring | nullWhy the operation failed, or null.
idstringThe operation's ID, a UUID.
progressstring | nullA short progress note from the Node while it runs, or null.
resultunknownFor exec, an ExecOutput; null for another member's exec.
startedAtstring | nullWhen a Node started it, or null.
stateOperationStateWhere the operation is; see OperationState.
type"exec" | "snapshot" | "restore"What was requested.

OperationOptions

type OperationOptions = WaitOptions & object;

Options for Boxes.snapshot and Boxes.restore.

Type Declaration

NameTypeDescription
idempotencyKey?stringMakes the request safe to repeat. A new key is generated per call when omitted.

OperationState

type OperationState = "pending" | "running" | "done" | "failed" | "unknown";

An operation's progress: pending, then running, then done, failed or unknown. unknown means its Node lost track of it, so it may or may not have run.


Readiness

type Readiness = object;

Whether SSH or the console can be used now. When ready is false, reason is the first check that failed, such as not_running or generation_pending; it is null when ready.

Properties

PropertyType
readyboolean
reasonstring | null

Resources

type Resources = object;

A Box's size: vcpus virtual CPUs, memoryMiB of memory and diskGiB of disk.

Properties

PropertyType
diskGiBnumber
memoryMiBnumber
vcpusnumber

Snapshot

type Snapshot = object;

A snapshot of one Box's disk, as Boxes.listSnapshots returns it.

Properties

PropertyTypeDescription
completedAtstring | nullWhen it completed, or null.
createdAtstringWhen it was requested, as an ISO 8601 timestamp.
idstringThe snapshot's ID, a UUID. Pass it to restore, or to create as snapshotId.
namestringThe name given when it was taken. Names need not be unique.
operationIdstringThe snapshot operation that takes it.
status"pending" | "complete" | "failed"complete once its operation is done, failed if the operation failed.

WaitOptions

type WaitOptions = object;

How long to wait, and how to stop waiting. Every call that waits takes these, except exec, whose timeoutMs is the command's own timeout. The default timeout depends on the call.

See

Waiting

Properties

PropertyTypeDescription
signal?AbortSignalStops waiting; the server keeps doing what was requested. The call rejects with the signal's reason.
timeoutMs?numberHow long to wait before rejecting with CubicleTimeoutError. Capped at 2^31 − 1 ms (24.8 days). In ms. A negative value rejects with invalid_option when the wait begins.

WaitTarget

type WaitTarget = "ready" | "stopped" | "hibernated";

What waitUntil waits for. ready means SSH and exec can be used now.

On this page