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.

OptionDescription
token

The API key to use for authentication.

Defaults to the RENDER_API_KEY environment variable. You must provide an API key here or in that environment variable.

ownerId

The default workspace ID for sandbox operations.

Defaults to the RENDER_WORKSPACE_ID environment variable.

region

The default region to use when creating sandbox groups. Currently, only oregon is supported. This value does not affect the placement of sandboxes created in an existing group.

Defaults to the RENDER_REGION environment variable.

baseUrl

The base URL of the Render API. Defaults to https://api.render.com.

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:

FieldDescription
ownerId

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 RenderError.

sandboxGroupId

The ID of the sandbox group to create the sandbox in. Defaults to the workspace's default group. See Sandbox groups.

plan

The compute plan to use for the sandbox: 1c-2g, 2c-4g, 4c-8g, or 8c-16g. The name indicates the CPU count and amount of RAM in GB.

Defaults to 1c-2g. When restoring from a snapshot, defaults to the source sandbox's plan. A runtime snapshot requires the same plan. A filesystem snapshot can be restored onto a different plan.

The SDK also accepts other plan strings supported by the API.

timeoutSeconds

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 86400 (24 hours). Set to 0 to disable the runtime timeout and let the sandbox run indefinitely. Other values must be between 60 and 2592000 (30 days).

Automatic idle suspension is configured separately with idleTimeoutSeconds.

idleTimeoutSeconds

The number of seconds of inactivity before the sandbox is automatically suspended. See Idle suspension.

Defaults to 900 (15 minutes). Set to 0 to disable automatic idle suspension. Other values must be between 300 (five minutes) and 86400 (24 hours).

networkPolicy

An object specifying the sandbox's outbound network policy. See all supported options below.

Defaults to { type: 'allow-all' }.

region

Deprecated. This field does not affect sandbox placement. The sandbox group determines the region. Currently, sandboxes run in Oregon.

env

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.

snapshotId

The ID of an available snapshot in the same sandbox group to restore from.

If you provide this value, do not provide snapshotName.

snapshotName

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 snapshotId.

wait

Controls how the method waits for the sandbox to become ready before returning.

Provide one of the following:

  • An object containing wait settings. See all supported options below.
  • true to wait with the default settings listed below.
  • false (default) to return without waiting.

The wait begins after the create request returns. If it fails, this method throws SandboxCreateWaitError, which includes the new sandbox's ID.

Supported networkPolicy options

type

Required. The outbound network policy: allow-all, deny-all, or allow-list.

rules

Required for allow-list. An array of destinations the sandbox can access over HTTPS. Do not provide this field for allow-all or deny-all.

Each entry is an object with these fields:

  • domain (required): A lowercase hostname such as api.example.com, or a wildcard such as *.example.com. Do not include a scheme, port, or path. An exact hostname does not include its subdomains.
  • protocol: Must be https if provided. Defaults to https.

Provide between 1 and 100 rules. Other outbound traffic is blocked.

Supported wait options

timeoutMs

The maximum time to wait, in milliseconds, including status requests.

Defaults to 60000 (60 seconds).

intervalMs

The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds.

Defaults to 250. Must be greater than 0.

signal

An optional AbortSignal used to cancel the wait.

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

ParameterDescription
sandboxId

Required. The ID of the sandbox to wait for.

options

An optional object containing wait settings. See all supported options below.

Supported options

timeoutMs

The maximum time to wait, in milliseconds, including status requests.

Defaults to 60000 (60 seconds).

intervalMs

The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds.

Defaults to 250. Must be greater than 0.

signal

An optional AbortSignal used to cancel the wait.

ownerId

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

ParameterDescription
sandboxId

Required. The ID of the sandbox to retrieve.

ownerId

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 RenderError.

signal

An optional AbortSignal used to cancel the request.

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:

OptionDescription
ownerId

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 RenderError.

status

An array of statuses to filter results by: creating, running, suspending, suspended, resuming, errored, or terminated.

cursor

The cursor from the last entry in a previous response. Use this to retrieve the next page of results.

limit

The maximum number of sandboxes to return per page. Defaults to 20. Must be between 1 and 100.

sandboxGroupId

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

ParameterDescription
sandboxId

Required. The ID of the sandbox to terminate.

ownerId

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 RenderError.

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

ParameterDescription
sandboxId

Required. The ID of the sandbox in which to run the command.

command

Required. The command to run through bash -c.

ownerId

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 RenderError.

signal

An optional AbortSignal used to cancel the request or stream.

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

ParameterDescription
sandboxId

Required. The ID of the destination sandbox.

path

Required. The destination path in the sandbox. Relative paths resolve from the sandbox's home directory. Absolute paths resolve from its filesystem root.

data

Required. The data to upload: a Buffer, Uint8Array, string, or Node.js Readable stream.

ownerId

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 RenderError.

options

An optional object containing upload settings. See all supported options below.

Supported options

contentType

The content type of the uploaded data: application/octet-stream (default) or application/x-tar.

signal

An optional AbortSignal used to cancel the upload.

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

ParameterDescription
sandboxId

Required. The ID of the source sandbox.

path

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.

ownerId

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 RenderError.

signal

An optional AbortSignal used to cancel the request.

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:

OptionDescription
sandboxId

Required. The ID of the running sandbox to capture.

kind

The snapshot type: filesystem to capture the writable filesystem, or runtime to also capture memory and CPU state.

Defaults to runtime.

name

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 snp-.

expiresAt

A future ISO 8601 timestamp when the snapshot expires.

Defaults to 30 days after the snapshot creation request.

ownerId

The ID of the workspace that owns the sandbox.

Defaults to the client configuration.

wait

Controls how the method waits for the snapshot to be available before returning.

Provide one of the following:

  • An object containing wait settings. See all supported options below.
  • true to wait with the default settings listed below.
  • false (default) to return without waiting.

If the wait fails, this method throws SandboxSnapshotCreateWaitError, which includes the new snapshot's ID and sandbox group ID.

Supported wait options

timeoutMs

The maximum time to wait, in milliseconds, including status requests.

Defaults to 300000 (five minutes).

intervalMs

The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds.

Defaults to 250. Must be greater than 0.

signal

An optional AbortSignal used to cancel the wait.

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

ParameterDescription
input

Required. An object with the following supported fields:

  • sandboxGroupId (required): The ID of the sandbox group that contains the snapshot.
  • snapshotId (required): The ID of the snapshot to wait for.
  • ownerId: The ID of the workspace that owns the sandbox group. Defaults to the client configuration.
options

An optional object containing wait settings. See all supported options below.

Supported options

timeoutMs

The maximum time to wait, in milliseconds, including status requests.

Defaults to 300000 (five minutes).

intervalMs

The initial delay between status checks, in milliseconds. The delay doubles with each attempt until reaching at least 2000 milliseconds.

Defaults to 250. Must be greater than 0.

signal

An optional AbortSignal used to cancel the wait.

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

ParameterDescription
input

Required. An object identifying the snapshot. See all supported fields below.

signal

An optional AbortSignal used to cancel the request.

Supported input fields

sandboxGroupId

Required. The ID of the sandbox group that contains the snapshot.

snapshotId

Required. The ID of the snapshot to retrieve.

ownerId

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:

OptionDescription
sandboxGroupId

Required. The ID of the sandbox group whose snapshots to list.

status

An array of statuses to filter results by: creating, available, or failed.

cursor

The cursor from the last entry in a previous response. Use this to retrieve the next page of results.

limit

The maximum number of snapshots to return per page. Defaults to 20. Must be between 1 and 100.

ownerId

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 RenderError.

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:

OptionDescription
sandboxGroupId

Required. The ID of the sandbox group that contains the snapshot.

snapshotId

Required. The ID of the snapshot to delete.

ownerId

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:

OptionDescription
ownerId

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 RenderError.

cursor

The cursor from the last entry in a previous response. Use this to retrieve the next page of results.

limit

The maximum number of groups to return per page. Defaults to 20. Must be between 1 and 100.

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:

FieldDescription
name

Required. The name of the sandbox group.

ownerId

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.

region

The region for the sandbox group. Currently, only oregon is supported.

Defaults to the client configuration, then oregon.

getGroup(sandboxGroupId)

Retrieves the details of the sandbox group with the specified ID.

On success: Returns a SandboxGroup object.

Throws: ClientError, ServerError, RenderError

ParameterDescription
sandboxGroupId

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

ParameterDescription
sandboxGroupId

Required. The ID of the sandbox group to update.

concurrencyLimit

Required. The maximum number of active sandboxes in the group. Must be at least 1. Setting a higher value does not raise Render's cap. See Concurrency.

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

Thrown when create creates a sandbox but its wait fails. Includes sandboxId and the underlying error in cause.

The sandbox still exists. Use terminate if you want to stop it.

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.

PropertyDescription
id

The sandbox's ID.

status

The sandbox's current status.

plan

The sandbox's compute plan.

networkPolicy

The sandbox's outbound network policy.

region

The Render region in which the sandbox runs.

timeoutSeconds

The sandbox's runtime timeout, in seconds. 0 indicates that the timeout is disabled. This timeout resets if the sandbox is suspended and later resumed.

idleTimeoutSeconds

The number of seconds of inactivity before automatic suspension. 0 disables automatic idle suspension. See Idle suspension.

sandboxGroupId

The ID of the sandbox group that contains the sandbox.

createdAt

The time when the sandbox was created.

terminatedAt

The time when the sandbox was terminated, or null if it has not been terminated.

SandboxDownload

Represents the data returned by download.

PropertyDescription
data

The downloaded bytes as a Buffer. For a directory, this contains a tar archive.

size

The number of downloaded bytes.

contentType

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.

PropertyDescription
id

The sandbox group's ID.

ownerId

The ID of the workspace that owns the sandbox group.

name

The sandbox group's name.

region

The Render region that the sandbox group belongs to.

isDefault

Whether this is the workspace's default sandbox group.

concurrencyLimit

The effective limit on active sandboxes in this group. Suspended sandboxes do not count toward the limit. See Concurrency.

createdAt

The time when the sandbox group was created.

updatedAt

The time when the sandbox group was last updated.

environmentId

The ID of the associated environment, or null if the group has none.

SandboxGroupWithCursor

Represents one sandbox group in a listGroups() result.

PropertyDescription
sandboxGroup

The SandboxGroup in this entry.

cursor

The cursor for this entry.

SandboxSnapshot

Represents a snapshot returned by a snapshots method or included in a list result.

PropertyDescription
id

The snapshot's ID.

sandboxGroupId

The ID of the sandbox group that contains the snapshot.

sourceSandboxId

The ID of the sandbox from which the snapshot was captured.

name

The optional name assigned when the snapshot was created, or null.

kind

The snapshot type: filesystem or runtime.

status

The snapshot's current status.

plan

The compute plan of the source sandbox.

requestedAt

The time when snapshot capture was requested.

capturedAt

The time when capture completed, or null while the snapshot is still being created.

expiresAt

The time when the snapshot expires.

sizeBytes

The snapshot's size in bytes, or null until capture completes.

error

The capture error message, if capture failed; otherwise null.

SandboxSnapshotWithCursor

Represents one snapshot in a snapshots.list() result.

PropertyDescription
snapshot

The SandboxSnapshot in this entry.

cursor

The cursor for this entry.