Sandboxes SDK for TypeScript
Usage and symbol reference
Render Sandboxes is in public beta.
APIs, defaults, and limits might change during the beta period.
Render SDK for TypeScriptv1.7.0
Setup
1. Install the SDK
From your TypeScript project directory:
(Or pnpm install, bun add, etc.)
If you already have the SDK installed, make sure you're using version 1.5.0 or later:
After installing, make sure @renderinc/sdk is listed as a dependency in your package.json file at version ^1.5.0 or later.
2. Import the client
The TypeScript SDK uses the asynchronous Render client. All sandbox methods return Promises.
The Render client constructor accepts an optional configuration object:
Render(options?)
Initializes a Render SDK client.
Throws: RenderError if no API key is provided.
| Option | Description |
|---|---|
|
The API key to use for authentication. Defaults to the |
|
The default workspace ID for sandbox operations. Defaults to the |
|
The default region to use when creating sandbox groups. Currently, only Defaults to the |
|
The base URL of the Render API. Defaults to |
Sandbox lifecycle
create(input)
Creates a sandbox in the specified workspace. By default, this method returns before the sandbox is running. Pass wait: true to wait until it's running.
To restore from a snapshot, provide either snapshotId or snapshotName, but not both. Set sandboxGroupId to the snapshot's group ID. Restoring into a different group is not supported. See Restoring a snapshot.
On success: Returns a Sandbox object. If wait is enabled, the returned sandbox has a status of running.
Throws: SandboxCreateWaitError, AbortError, SandboxSnapshotNotFoundError, SandboxSnapshotNotReadyError, SandboxSnapshotPlanMismatchError, ClientError, ServerError, RenderError
Supported fields on input include:
| Field | Description |
|---|---|
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
The ID of the sandbox group to create the sandbox in. Defaults to the workspace's default group. See Sandbox groups. |
|
The compute plan to use for the sandbox: Defaults to The SDK also accepts other plan strings supported by the API. |
|
The maximum time the sandbox can run continuously, in seconds. The sandbox terminates when this time elapses. If the sandbox is suspended and later resumed, this timeout resets. Defaults to Automatic idle suspension is configured separately with |
|
The number of seconds of inactivity before the sandbox is automatically suspended. See Idle suspension. Defaults to |
|
An object specifying the sandbox's outbound network policy. See all supported options below. Defaults to |
|
Deprecated. This field does not affect sandbox placement. The sandbox group determines the region. Currently, sandboxes run in Oregon. |
|
An object of environment variables to inject into the sandbox at creation, with variable names as keys and string values. See Environment variable limits. The API does not return these values in sandbox details. |
|
The ID of an available snapshot in the same sandbox group to restore from. If you provide this value, do not provide |
|
The name of an available snapshot to restore from (case-sensitive). Resolves to the most recently available snapshot with that name in the sandbox group. If you provide this value, do not provide |
|
Controls how the method waits for the sandbox to become ready before returning. Provide one of the following:
The wait begins after the create request returns. If it fails, this method throws |
|
Supported | |
|
Required. The outbound network policy: |
|
Required for Each entry is an object with these fields:
Provide between 1 and 100 rules. Other outbound traffic is blocked. |
|
Supported | |
|
The maximum time to wait, in milliseconds, including status requests. Defaults to |
|
The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds. Defaults to |
|
An optional |
waitUntilRunning(sandboxId, options)
Waits for the sandbox with the specified ID to become ready and returns its details.
To create a sandbox and wait for it in a single call, use create with wait: true.
On success: Returns a Sandbox object with a status of running.
Throws: SandboxNotRunningError, SandboxWaitTimeoutError, AbortError, ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the sandbox to wait for. |
|
An optional object containing wait settings. See all supported options below. |
|
Supported | |
|
The maximum time to wait, in milliseconds, including status requests. Defaults to |
|
The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds. Defaults to |
|
An optional |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. This value must be set here or in the client configuration. |
Throws SandboxNotRunningError if the sandbox is errored, terminated, suspending, or suspended. If the wait times out or is canceled, the sandbox continues to exist. Use terminate to stop it.
get(sandboxId, ownerId, signal)
Retrieves the details of the sandbox with the specified ID, including whether it's terminated.
To wait until a sandbox is running, use waitUntilRunning.
On success: Returns a Sandbox object.
Throws: ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the sandbox to retrieve. |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
An optional |
list(options)
Lists sandboxes in the specified workspace, newest first.
Terminated sandboxes are excluded by default. Include terminated in the status filter to retrieve them.
On success: Returns an array of objects with sandbox and cursor fields. Each sandbox is a Sandbox object.
Throws: ClientError, ServerError, RenderError
Supported fields on options include:
| Option | Description |
|---|---|
|
The ID of the workspace whose sandboxes to list. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
An array of statuses to filter results by: |
|
The cursor from the last entry in a previous response. Use this to retrieve the next page of results. |
|
The maximum number of sandboxes to return per page. Defaults to |
|
The ID of a sandbox group to filter results by. Omit to list sandboxes across the workspace. |
terminate(sandboxId, ownerId)
Terminates the sandbox with the specified ID and releases its compute resources. Terminating an already-terminated sandbox succeeds.
On success: Returns void.
Throws: ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the sandbox to terminate. |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
Runtime execution
exec(sandboxId, command, ownerId, signal)
Runs the specified command in a sandbox and streams its output. Commands run through bash -c.
Output events identify the stream (stdout or stderr) and include a chunk of output. The final event includes the command's exit code. A nonzero exit code does not throw an error.
If the sandbox is suspended, this operation resumes it before running the command.
On success: Returns an async generator of SandboxExecEvent values.
Throws: SandboxEndedError, SandboxExecStreamError, AbortError, ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the sandbox in which to run the command. |
|
Required. The command to run through |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
An optional |
upload(sandboxId, path, data, ownerId, options)
Uploads data to the specified path in a sandbox.
To upload a directory, provide a tar archive and set options.contentType to application/x-tar. The sandbox extracts the archive at the specified path.
If the sandbox is suspended, this operation resumes it before transferring data.
On success: Returns void.
Throws: SandboxEndedError, AbortError, ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the destination sandbox. |
|
Required. The destination path in the sandbox. Relative paths resolve from the sandbox's home directory. Absolute paths resolve from its filesystem root. |
|
Required. The data to upload: a |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
An optional object containing upload settings. See all supported options below. |
|
Supported | |
|
The content type of the uploaded data: |
|
An optional |
download(sandboxId, path, ownerId, signal)
Downloads a file or directory from the specified path in a sandbox. Directories are returned as tar archives.
The SDK reads the entire download into memory. It does not write to the local filesystem or extract archives.
If the sandbox is suspended, this operation resumes it before transferring data.
On success: Returns a SandboxDownload object containing the downloaded bytes and metadata.
Throws: SandboxEndedError, AbortError, ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the source sandbox. |
|
Required. The path of the file or directory to download. Relative paths resolve from the sandbox's home directory. Absolute paths resolve from its filesystem root. |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
An optional |
Snapshot management
Access snapshot methods through render.sandboxes.snapshots.
Snapshot results include the snapshot ID, optional name, source sandbox ID, sandbox group ID, kind, status, plan, capture and expiration times, size in bytes, and any capture error.
Deleting a snapshot prevents future restores but does not affect sandboxes already restored from it. After a snapshot expires, you can no longer retrieve or restore it, and snapshot lists omit it.
snapshots.create(input)
Creates a snapshot of the specified running sandbox. By default, this method returns before capture completes. Pass wait: true to wait until the snapshot is available. The source sandbox keeps running after capture.
On success: Returns a SandboxSnapshot object. If wait is enabled, the returned snapshot has a status of available.
Throws: SandboxSnapshotCreateWaitError, AbortError, SandboxSnapshotNotReadyError, ClientError, ServerError
Supported fields on input include:
| Option | Description |
|---|---|
|
Required. The ID of the running sandbox to capture. |
|
The snapshot type: Defaults to |
|
An optional, case-sensitive name for the snapshot, between 1 and 64 characters. Names are scoped to the sandbox group, can be reused, and cannot begin with |
|
A future ISO 8601 timestamp when the snapshot expires. Defaults to 30 days after the snapshot creation request. |
|
The ID of the workspace that owns the sandbox. Defaults to the client configuration. |
|
Controls how the method waits for the snapshot to be available before returning. Provide one of the following:
If the wait fails, this method throws |
|
Supported | |
|
The maximum time to wait, in milliseconds, including status requests. Defaults to |
|
The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds. Defaults to |
|
An optional |
snapshots.waitUntilAvailable(input, options)
Waits for the specified snapshot to be available and returns its details.
To create a snapshot and wait for it in a single call, use snapshots.create with wait: true.
On success: Returns a SandboxSnapshot object with a status of available.
Throws: SandboxSnapshotFailedError, SandboxSnapshotWaitTimeoutError, SandboxSnapshotNotFoundError, AbortError, ClientError, ServerError
| Parameter | Description |
|---|---|
|
Required. An object with the following supported fields:
|
|
An optional object containing wait settings. See all supported options below. |
|
Supported | |
|
The maximum time to wait, in milliseconds, including status requests. Defaults to |
|
The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds. Defaults to |
|
An optional |
Throws SandboxSnapshotFailedError if the snapshot's status becomes failed. If the wait times out or is canceled, snapshot capture continues.
snapshots.get(input, signal)
Retrieves the details of the snapshot with the specified ID in the specified sandbox group.
To wait until a snapshot is available, use snapshots.waitUntilAvailable.
On success: Returns a SandboxSnapshot object.
Throws: SandboxSnapshotNotFoundError, ClientError, ServerError
| Parameter | Description |
|---|---|
|
Required. An object identifying the snapshot. See all supported fields below. |
|
An optional |
|
Supported | |
|
Required. The ID of the sandbox group that contains the snapshot. |
|
Required. The ID of the snapshot to retrieve. |
|
The ID of the workspace that owns the sandbox group. Defaults to the client configuration. |
snapshots.list(input)
Lists snapshots in the specified sandbox group, newest first. Deleted and expired snapshots are excluded.
On success: Returns an array of SandboxSnapshotWithCursor entries.
Throws: ClientError, ServerError, RenderError
Supported fields on input include:
| Option | Description |
|---|---|
|
Required. The ID of the sandbox group whose snapshots to list. |
|
An array of statuses to filter results by: |
|
The cursor from the last entry in a previous response. Use this to retrieve the next page of results. |
|
The maximum number of snapshots to return per page. Defaults to |
|
The ID of the workspace that owns the sandbox group. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
snapshots.delete(input)
Deletes the snapshot with the specified ID in the specified sandbox group. You cannot delete a snapshot while its status is creating. Sandboxes already restored from the snapshot are unaffected.
On success: Returns void.
Throws: SandboxSnapshotNotFoundError, SandboxSnapshotNotReadyError, ClientError, ServerError
Supported fields on input include:
| Option | Description |
|---|---|
|
Required. The ID of the sandbox group that contains the snapshot. |
|
Required. The ID of the snapshot to delete. |
|
The ID of the workspace that owns the sandbox group. Defaults to the client configuration. |
Sandbox groups
listGroups(options)
Lists sandbox groups in the specified workspace. Use a group's ID when creating sandboxes or managing snapshots.
To paginate, use the cursor from the last entry to retrieve the next page. Continue until a page contains no groups.
On success: Returns an array of SandboxGroupWithCursor entries.
Throws: ClientError, ServerError, RenderError
Supported fields on options include:
| Option | Description |
|---|---|
|
The ID of the workspace whose sandbox groups to list. Defaults to the client configuration. If this value is not set here, it must be set in the client configuration. Otherwise, this method throws |
|
The cursor from the last entry in a previous response. Use this to retrieve the next page of results. |
|
The maximum number of groups to return per page. Defaults to |
createGroup(input)
Creates a sandbox group in the specified workspace.
On success: Returns a SandboxGroup object.
Throws: ClientError, ServerError, RenderError
Supported fields on input include:
| Field | Description |
|---|---|
|
Required. The name of the sandbox group. |
|
The ID of the workspace that owns the sandbox group. Defaults to the client configuration. This value must be set here or in the client configuration. |
|
The region for the sandbox group. Currently, only Defaults to the client configuration, then |
getGroup(sandboxGroupId)
Retrieves the details of the sandbox group with the specified ID.
On success: Returns a SandboxGroup object.
Throws: ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the sandbox group to retrieve. |
updateGroup(sandboxGroupId, concurrencyLimit)
Updates the sandbox group's concurrency limit. The returned group includes the effective limit after Render applies its cap. Lowering the limit does not stop existing sandboxes.
On success: Returns a SandboxGroup object.
Throws: ClientError, ServerError, RenderError
| Parameter | Description |
|---|---|
|
Required. The ID of the sandbox group to update. |
|
Required. The maximum number of active sandboxes in the group. Must be at least |
Error types
Sandbox errors
These errors pertain to sandbox operations that cannot resolve required client configuration or encounter an unexpected response.
RenderError
Raised when an operation cannot resolve a required owner ID or encounters an unexpected sandbox response.
SandboxEndedError extends ClientError
Thrown when command execution or file transfer encounters a sandbox that is terminated or errored. Includes the status in sandboxStatus.
Command execution errors
These errors pertain to running commands in a sandbox.
SandboxExecStreamError
Raised when the exec stream ends with a terminal error. Carries status and message properties.
Readiness errors
These errors pertain to waiting for a sandbox or snapshot to be ready.
SandboxNotRunningError extends RenderError
Thrown when waitUntilRunning encounters a sandbox with status errored, terminated, suspending, or suspended. Includes sandboxId and sandboxStatus.
SandboxSnapshotFailedError extends RenderError
Thrown when snapshots.waitUntilAvailable encounters a failed snapshot. Includes snapshotId and the capture error in snapshotError, if available.
TimeoutError extends RenderError
The parent class for SDK timeout errors.
SandboxWaitTimeoutError extends TimeoutError
Thrown when a sandbox does not reach running within the specified wait timeout. Includes sandboxId, timeoutMs, and lastStatus if a status check completed.
SandboxSnapshotWaitTimeoutError extends TimeoutError
Thrown when a snapshot does not reach available within the specified wait timeout. Includes snapshotId, timeoutMs, and lastStatus if a status check completed.
SandboxCreateWaitError extends RenderError
SandboxSnapshotCreateWaitError extends RenderError
Thrown when snapshots.create creates a snapshot but its wait fails. Includes snapshotId, sandboxGroupId, and the underlying error in cause.
The snapshot still exists. You can delete it once capture finishes.
Cancellation errors
These errors pertain to an AbortSignal that cancels an operation.
AbortError
Raised when an operation is aborted.
Snapshot errors
These errors pertain to creating, restoring, and managing sandbox snapshots.
SandboxSnapshotNotFoundError
Raised when the snapshot cannot be found in the specified group, including after deletion or expiration.
SandboxSnapshotNotReadyError
Raised when restore requires an available snapshot, or deletion was attempted while capture was still creating.
SandboxSnapshotPlanMismatchError
Raised when a runtime snapshot is restored onto a different plan.
API errors
These errors pertain to responses from the Render API.
ClientError
Raised when the API returns a 4xx response, including HTTP 429 for either the request rate or concurrency cap (see Sandbox limits).
ServerError
Raised when the API returns a 5xx response.
Additional types
Sandbox
Represents a sandbox returned by create(), get(), or waitUntilRunning(), or included in a list result.
| Property | Description |
|---|---|
|
The sandbox's ID. |
|
The sandbox's current status. |
|
The sandbox's compute plan. |
|
The sandbox's outbound network policy. |
|
The Render region in which the sandbox runs. |
|
The sandbox's runtime timeout, in seconds. |
|
The number of seconds of inactivity before automatic suspension. |
|
The ID of the sandbox group that contains the sandbox. |
|
The time when the sandbox was created. |
|
The time when the sandbox was terminated, or |
SandboxDownload
Represents the data returned by download.
| Property | Description |
|---|---|
|
The downloaded bytes as a |
|
The number of downloaded bytes. |
|
The response content type, if provided. |
SandboxExecEvent
Represents an event yielded by exec().
An output event has type: 'output', stream: 'stdout' | 'stderr', and a data string. The final exit event has type: 'exit' and an exit_code number.
SandboxGroup
Represents a sandbox group returned by a group method or included in a SandboxGroupWithCursor entry.
| Property | Description |
|---|---|
|
The sandbox group's ID. |
|
The ID of the workspace that owns the sandbox group. |
|
The sandbox group's name. |
|
The Render region that the sandbox group belongs to. |
|
Whether this is the workspace's default sandbox group. |
|
The effective limit on active sandboxes in this group. Suspended sandboxes do not count toward the limit. See Concurrency. |
|
The time when the sandbox group was created. |
|
The time when the sandbox group was last updated. |
|
The ID of the associated environment, or |
SandboxGroupWithCursor
Represents one sandbox group in a listGroups() result.
| Property | Description |
|---|---|
|
The |
|
The cursor for this entry. |
SandboxSnapshot
Represents a snapshot returned by a snapshots method or included in a list result.
| Property | Description |
|---|---|
|
The snapshot's ID. |
|
The ID of the sandbox group that contains the snapshot. |
|
The ID of the sandbox from which the snapshot was captured. |
|
The optional name assigned when the snapshot was created, or |
|
The snapshot type: |
|
The snapshot's current status. |
|
The compute plan of the source sandbox. |
|
The time when snapshot capture was requested. |
|
The time when capture completed, or |
|
The time when the snapshot expires. |
|
The snapshot's size in bytes, or |
|
The capture error message, if capture failed; otherwise |
SandboxSnapshotWithCursor
Represents one snapshot in a snapshots.list() result.
| Property | Description |
|---|---|
|
The |
|
The cursor for this entry. |