For the complete Render documentation index, fetch https://render.com/llms.txt. Every docs page is also available as Markdown at https://render.com/docs/{slug}.md.

  • Docs
  • Changelog
Sign in
Get started

Sandboxes SDK for Python

Usage and symbol reference

View as Markdown
Open in ChatGPT
Open in Claude

Render Sandboxes is in public beta.

APIs, defaults, and limits might change during the beta period.

Render SDK for Pythonv1.12.0

Setup

1. Install the SDK

From your Python project directory:

If you already have the SDK installed, make sure you're using version 1.10.0 or later:

After installing, make sure to add render>=1.10.0 as a dependency in your application's requirements.txt, pyproject.toml, or equivalent.

Version 1.9.0 and later require Python 3.11 or later.

2. Import the client (sync or async)

The Python SDK provides separate classes for synchronous (Render) and asynchronous (RenderAsync) usage. Both clients support the methods in this reference.

The method examples below use the sync client. With RenderAsync, await each method call except exec, which returns an async iterator to use with async for.

Import sandbox-specific types and errors from render.sandbox.

Initializes a synchronous Render SDK client.

Raises: ValueError

ParameterDescription
token

The Render API key to use for authentication.

If omitted, the client uses the value of the RENDER_API_KEY environment variable. If that variable is not set, the constructor raises a ValueError.

owner_id

The default workspace ID to use for sandbox operations.

Override this default by setting owner_id when calling individual sandbox methods.

If omitted, the client uses the value of the RENDER_WORKSPACE_ID environment variable. If that variable is not set, no default is set.

region

A compatibility parameter that does not affect sandbox placement. The sandbox group determines the region. Currently, all sandboxes run in the Oregon region.

If omitted, the client uses the value of the RENDER_REGION environment variable.

Initializes an asynchronous Render SDK client.

Raises: ValueError

ParameterDescription
token

The Render API key to use for authentication.

If omitted, the client uses the value of the RENDER_API_KEY environment variable. If that variable is not set, the constructor raises a ValueError.

owner_id

The default workspace ID to use for sandbox operations.

Override this default by setting owner_id when calling individual sandbox methods.

If omitted, the client uses the value of the RENDER_WORKSPACE_ID environment variable. If that variable is not set, no default is set.

region

A compatibility parameter that does not affect sandbox placement. The sandbox group determines the region. Currently, all sandboxes run in the Oregon region.

If omitted, the client uses the value of the RENDER_REGION environment variable.

Sandbox lifecycle

Creates a new sandbox with the specified configuration.

  • To restore from a snapshot:

    • Provide one of snapshot_id or snapshot_name (not both).
    • Set sandbox_group_id to the snapshot's group ID (cross-group restores are not supported).
    • For details, see Restoring from a snapshot.
  • To use a custom image:

    • Set image to the ID or name of the image to use. The image must have been previously imported.
    • Set sandbox_group_id to the image's group ID (cross-group image use is not supported).
    • For details, see Docker images.

By default, this method does not wait for the sandbox to become ready before returning. Pass the wait option to customize wait behavior.

On success: Returns a Sandbox object. Check its status field to determine whether it's currently running or creating.

Raises: SandboxCreateWaitError, ValueError (invalid wait options, network policy, or conflicting image/snapshot parameters), SnapshotNotFoundError, SnapshotNotReadyError, SnapshotPlanMismatchError, ImageNotFoundError, ImageNotReadyError, RateLimitError, ClientError, ServerError, RenderError

With RenderAsync, canceling the task while this method is waiting attempts to terminate the created sandbox before propagating cancellation.

Supported parameters include:

ParameterDescription
owner_id

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

name

An optional, case-sensitive name for the sandbox. This value cannot exceed 64 characters or begin with sbx-.

Names are not required to be unique. Use the sandbox's ID when calling methods that operate on a specific sandbox.

sandbox_group_id

The ID of the sandbox group to create the sandbox in.

If omitted, defaults to the workspace's default sandbox group. If the workspace does not have any sandbox groups, this method creates a new group and adds the sandbox to it.

plan

The ID of the compute plan to use for the sandbox. One of the following:

CPURAMPlan ID
1 CPU2 GB

1c-2g

2 CPU4 GB

2c-4g

4 CPU8 GB

4c-8g

8 CPU16 GB

8c-16g

For pricing details, see Compute plans and billing.

Omit this value if restoring from a runtime snapshot. In this case, the new sandbox must use the same compute plan as the source sandbox (which is the default behavior). You can provide this value if restoring from a filesystem snapshot.

If you omit this field:

  • If restoring from a snapshot, inherits the source sandbox's compute plan.
  • Otherwise, defaults to 1c-2g.
timeout_seconds

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

If you omit this field:

  • If restoring from a snapshot, inherits the source sandbox's runtime timeout, including if disabled.
    • The timeout restarts for the restored sandbox.
  • Otherwise, 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 idle_timeout_seconds.

idle_timeout_seconds

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

If you omit this field:

  • If restoring from a snapshot, inherits the source sandbox's idle timeout, including if disabled.
  • Otherwise, 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).

network_policy

A NetworkPolicy object specifying the sandbox's outbound network policy.

If you omit this field:

  • If restoring from a snapshot, the sandbox inherits the source sandbox's network policy.
  • Otherwise, the sandbox defaults to NetworkPolicy(type="allow-all").
env

A dictionary containing key-value pairs to add to the sandbox as environment variables. For example:

All values must be strings.

These values override any matching ENV values from the sandbox's image.

See Environment variable limits. The API does not return these values in sandbox details.

snapshot_id

The ID of the snapshot to restore from. The snapshot must have status available and be in the same sandbox group as the sandbox.

If you provide this value, do not provide snapshot_name or image.

snapshot_name

The name of the snapshot to restore from (case-sensitive). The snapshot must have status available and be in the same sandbox group as the sandbox.

If multiple snapshots match the provided name, Render uses the most recently created snapshot with a status of available.

If you provide this value, do not provide snapshot_id or image.

image

The ID or name of an image that was previously imported into the same sandbox group using images.import_.

  • An image ID, such as sbb-cph1rs3idesc73a2b2mg, selects that specific version.
  • A name selects the newest version with a status of succeeded in the group.

If omitted, the sandbox uses the default image unless you provide a snapshot.

If you provide this value, do not provide snapshot_id or snapshot_name.

wait

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

Provide one of the following:

  • A SandboxWaitOptions object containing wait settings.
  • True to wait with the default settings.
  • False to return without waiting.

Defaults to False. When enabled, the default wait timeout is 60 seconds.

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

region

Deprecated. Do not provide this field.

A sandbox's sandbox group determines its region. Currently, all sandboxes run in the Oregon region.

Waits for the specified sandbox to reach a status of running and then returns its details.

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

To create a sandbox and wait for it in a single call, provide wait options to create.

On success: Returns a Sandbox object with a status of running.

Raises: SandboxNotFoundError, SandboxNotRunningError, SandboxWaitTimeoutError, ValueError (invalid wait options), RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_id

Required. The ID of the sandbox to wait for.

timeout_seconds

The maximum total time to wait, in seconds.

If this timeout is reached, the method raises a SandboxWaitTimeoutError.

Defaults to 60 (60 seconds).

interval_seconds

The initial delay between status checks, in seconds. Must be greater than 0.

  • If you provide a value less than 2 seconds, the delay doubles with each attempt up to 2 seconds.
  • If you provide a value of 2 seconds or more, the delay remains constant between attempts.

Defaults to 0.25.

owner_id

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

Retrieves the details of the sandbox with the specified ID.

On success: Returns a Sandbox object.

Raises: SandboxNotFoundError, RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_id

Required. The ID of the sandbox to retrieve.

owner_id

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

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 a SandboxList containing a page of sandboxes and a cursor for the next page.

Raises: RateLimitError, ClientError, ServerError, RenderError

Supported parameters include:

ParameterDescription
owner_id

The ID of the workspace to list sandboxes for. Defaults to the client configuration.

If this value is not set here, it must be set in the client configuration. Otherwise, this method raises RenderError.

name

The sandbox name to filter results by. Matches must be exact and are case-sensitive. Multiple sandboxes can have the same name.

Omit to include sandboxes with any name.

status

A status string or sequence of statuses to filter results by:

StatusDescription

creating

Creation is in progress. The sandbox is not yet ready to execute commands or transfer files.

running

The sandbox is ready. You can execute commands and transfer files.

suspending

Suspension is in progress. Render is saving the sandbox's state.

suspended

The sandbox is suspended. Executing a command or transferring files resumes it automatically.

resuming

Resumption is in progress. Render is restoring the sandbox's saved state.

errored

The sandbox encountered an error. It can no longer execute commands or transfer files.

terminated

The sandbox has been terminated. It can no longer execute commands or transfer files.

cursor

The next_cursor from 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.

sandbox_group_id

The ID of a sandbox group to filter results by. Omit to list sandboxes across the workspace.

Terminates the sandbox with the specified ID and releases its compute resources. Terminating an already-terminated sandbox succeeds.

On success: Returns None.

Raises: SandboxNotFoundError, RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_id

Required. The ID of the sandbox to terminate.

owner_id

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

Runtime execution

Executes the specified command in the specified sandbox and streams its output. If the sandbox is currently suspended, this method resumes it before executing the command.

By default, sandboxes execute commands using bash -c. Sandboxes using a custom image that does not include Bash fall back to sh -c.

  • Sandboxes using a custom image execute each command from the image's specified WORKDIR if it exists, falling back to the sandbox's home directory.
  • All other sandboxes execute each command from the sandbox's home directory.

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 raise an error.

On success: Returns an iterator of SandboxExecEvent values: a regular iterator with Render, or an async iterator with RenderAsync.

Raises: SandboxNotFoundError, SandboxEndedError, SandboxExecStreamError, SandboxExecError, RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_id

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

command

Required. The shell command to run.

owner_id

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

Streams a local file or directory to the specified path in the specified sandbox, without loading the entire file into memory. If the sandbox is suspended, this method resumes it before transferring data.

For directories, the SDK transfers the directory's contents to remote_path. Symlinks are preserved, and sockets, FIFOs, and other special files are skipped.

Passing a local path that is neither a regular file nor a directory raises ValueError.

On success: Returns None.

Raises: ValueError (invalid path), SandboxNotFoundError, SandboxEndedError, SandboxFileNotFoundError, RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_id

Required. The ID of the destination sandbox.

local_path

Required. The local file or directory to upload, as a string or os.PathLike object.

remote_path

Required. The destination path in the sandbox.

  • Relative paths resolve from the image's WORKDIR if it exists as a directory, or the sandbox's home directory otherwise.
  • Absolute paths resolve from the sandbox's filesystem root.
owner_id

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

Streams a file or directory from the specified path in the specified sandbox to a local disk path, without loading the entire file into memory. If the sandbox is suspended, this method resumes it before transferring data.

If a file already exists at the specified local path, this method attempts to overwrite it after the download succeeds.

If a local filesystem error prevents saving the download, the method raises SandboxDownloadError.

Directories are extracted into local_path. For an individual file, local_path can be either the destination filename or an existing directory to save the file in.

If a directory download fails during extraction, partially extracted files can remain at the local path.

This method does not enforce a download size limit.

On success: Returns the local path of the downloaded file or directory, as a string.

Raises: ValueError (invalid path), SandboxNotFoundError, SandboxEndedError, SandboxFileNotFoundError, SandboxDownloadError, RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_id

Required. The ID of the source sandbox.

remote_path

Required. The path of the file or directory in the sandbox.

  • Relative paths resolve from the image's WORKDIR if it exists as a directory, or the sandbox's home directory otherwise.
  • Absolute paths resolve from the sandbox's filesystem root.
local_path

Required. The local destination path, as a string or os.PathLike object.

owner_id

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

Snapshots

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 it or restore from it, and snapshot lists omit it.

Initiates a snapshot capture of the specified sandbox, which must have status running.

Capturing a snapshot temporarily interrupts the sandbox's operation. The details of this interruption depend on the kind of snapshot:

Kind of snapshotEffect
runtimeThe sandbox is fully paused while RAM, CPU, and disk state are captured.
filesystemFilesystem writes are blocked while the filesystem is captured. The sandbox remains running.

This temporary interruption ends before the snapshot becomes available.

By default, this method does not wait for the snapshot to become available before returning. Pass the wait option to customize wait behavior.

On success: Returns a Snapshot object.

Raises: SnapshotCreateWaitError, ValueError (invalid wait options), SandboxNotFoundError, RateLimitError, ClientError, ServerError

Supported parameters include:

ParameterDescription
sandbox_id

Required. The ID of the running sandbox to capture.

kind

The kind of snapshot to create:

ValueDescription
runtimeCaptures the writable filesystem, along with memory and CPU state.
filesystemCaptures the writable filesystem only.

Defaults to runtime.

For details, see Kinds of snapshots.

name

An optional, case-sensitive name for the snapshot, with a maximum of 64 characters.

Names are scoped to the sandbox group, can be reused, and cannot begin with snp-.

ttl_seconds

The snapshot's time-to-live (TTL), in seconds. When the TTL expires, the snapshot is deleted.

Each time you restore from the snapshot, its TTL refreshes. Set to 0 to retain the snapshot indefinitely until you delete it.

Defaults to 30 days.

This option replaced the expires_at option in SDK version 1.9.0.

For details, see Snapshot retention.

owner_id

The ID of the workspace that owns the source sandbox. Defaults to the client configuration. If neither is set, the API determines the workspace from the source sandbox.

wait

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

Provide one of the following:

  • A SandboxWaitOptions object containing wait settings.
  • True to wait with the default settings.
  • False (default) to return without waiting.

When enabled, the default wait timeout is 300 seconds (five minutes).

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

Waits for the specified snapshot to complete its capture and then returns its details.

Raises SnapshotFailedError if the snapshot's status becomes failed. If the wait times out or is canceled, snapshot capture continues.

To create a snapshot and wait for it in a single call, provide wait options to snapshots.create.

On success: Returns a Snapshot object with a status of available.

Raises: SnapshotFailedError, SnapshotWaitTimeoutError, SnapshotNotFoundError, ValueError (invalid wait options), RateLimitError, ClientError, ServerError

ParameterDescription
sandbox_group_id

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

snapshot_id

Required. The ID of the snapshot to wait for.

timeout_seconds

The maximum total time to wait, in seconds.

If this timeout is reached, the method raises a SnapshotWaitTimeoutError.

Defaults to 300 (five minutes).

interval_seconds

The initial delay between status checks, in seconds. Must be greater than 0.

  • If you provide a value less than 2 seconds, the delay doubles with each attempt up to 2 seconds.
  • If you provide a value of 2 seconds or more, the delay remains constant between attempts.

Defaults to 0.25.

owner_id

The ID of the workspace that owns the sandbox group. Defaults to the client configuration. If neither is set, the API determines the workspace from the sandbox group.

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

To wait until a snapshot is available, use snapshots.wait_until_available.

On success: Returns a Snapshot object.

Raises: SnapshotNotFoundError, RateLimitError, ClientError, ServerError

ParameterDescription
sandbox_group_id

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

snapshot_id

Required. The ID of the snapshot to retrieve.

owner_id

The ID of the workspace that owns the sandbox group. Defaults to the client configuration. If neither is set, the API determines the workspace from the sandbox group.

Lists snapshots in the specified sandbox group, newest first. Deleted and expired snapshots are excluded.

On success: Returns a SnapshotList containing a page of snapshots and a cursor for the next page.

Raises: RateLimitError, ClientError, ServerError, RenderError

Supported parameters include:

ParameterDescription
sandbox_group_id

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

status

A status string or sequence of statuses to filter results by:

StatusDescription

creating

Capture is in progress. New sandboxes cannot yet be restored from the snapshot.

available

Capture succeeded. New sandboxes can now be restored from the snapshot.

failed

Capture failed. Check the snapshot's error field for details.

cursor

The next_cursor from 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.

owner_id

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

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

Raises: SnapshotNotFoundError, SnapshotNotReadyError, RateLimitError, ClientError, ServerError

Supported parameters include:

ParameterDescription
sandbox_group_id

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

snapshot_id

Required. The ID of the snapshot to delete.

owner_id

The ID of the workspace that owns the sandbox group. Defaults to the client configuration. If neither is set, the API determines the workspace from the sandbox group.

Docker images

Import a Docker image from a registry to use as the base image for sandboxes. For image requirements and runtime behavior, see Providing a custom image.

Imports the specified Docker image from its registry for use in the specified sandbox group.

This method does not wait for the image to become ready before returning. Use images.wait_until_ready to wait until the image is ready for use in a sandbox.

On success: Returns an Image object.

Raises: RateLimitError, ClientError, ServerError. HTTP 429 indicates a request rate limit or too many imports in progress.

Supported parameters include:

ParameterDescription
sandbox_group_id

Required. The ID of the sandbox group to import into.

name

Required. A case-sensitive name to associate with the imported image. This value cannot exceed 255 characters or begin with sbb-.

You can reuse a given name to import updated versions of the same image. When you provide an image name to create (e.g., my-image-latest), Render uses the most recently created import in the sandbox group with that name and a status of succeeded.

source

Required. An image reference identifying the image to import, such as docker.io/library/python:latest.

Docker image reference format

You can reference a Docker image by tag or digest:

Examples:

Render uses the following defaults when you omit parts of the reference:

ComponentDefault

Registry host

docker.io

Repository path

library (if host is docker.io)

Tag

latest (if you omit both the tag and digest)

For example, the following references all resolve to docker.io/library/alpine:latest:

  • docker.io/library/alpine
  • library/alpine
  • alpine:latest
  • alpine
registry_credentials

Required for private images, omit otherwise.

A dictionary containing credentials for pulling the image from its registry. Credentials are used only for this single import.

FieldDescription
usernameRequired. The registry username.
passwordRequired. The registry password or access token.

Do not hardcode sensitive credentials in your application code. Use environment variables or a secrets manager instead.

Waits for the specified Docker image to complete its import and then returns its details.

Raises ImageFailedError if the image's status becomes failed. If the wait times out or is canceled, the image import continues.

On success: Returns an Image object with a status of succeeded.

Raises: ImageFailedError, ImageWaitTimeoutError, ImageNotFoundError, ValueError (invalid wait options), RateLimitError, ClientError, ServerError

ParameterDescription
sandbox_group_id

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

image_id

Required. The ID of the image to wait for.

timeout_seconds

The maximum total time to wait, in seconds.

If this timeout is reached, the method raises an ImageWaitTimeoutError.

Defaults to 600 (ten minutes).

interval_seconds

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

Defaults to 0.25. Must be greater than 0.

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

To wait until an image has completed its import, instead use images.wait_until_ready.

On success: Returns an Image object.

Raises: ImageNotFoundError, RateLimitError, ClientError, ServerError

ParameterDescription
sandbox_group_id

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

image_id

Required. The ID of the image to retrieve.

Lists images in the specified sandbox group, newest first.

Each imported version is returned as a separate result. Multiple results can have the same image name.

On success: Returns an ImageList containing a page of images and a cursor for the next page.

Raises: RateLimitError, ClientError, ServerError

Supported parameters include:

ParameterDescription
sandbox_group_id

Required. The ID of the sandbox group to list images from.

name

The case-sensitive image name to filter results by. Omit to include images with any name.

status

A status string or sequence of import statuses to filter results by. Omit to include all statuses.

StatusDescription

pending

Import is queued. The image is not yet ready to create sandboxes.

running

Import is in progress. The image is not yet ready to create sandboxes.

succeeded

Import succeeded. You can create sandboxes from the image.

failed

Import failed. Check the image's failure details.

cursor

The next_cursor from a previous response. Use this to retrieve the next page of results.

limit

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

Deletes the image with the specified ID in the specified sandbox group. Deleting an already-deleted image succeeds.

If at least one sandbox or snapshot depends on the image (such as to resume or restore), this method raises ImageInUseError.

On success: Returns None.

Raises: ImageNotFoundError, ImageInUseError, RateLimitError, ClientError, ServerError

Supported parameters include:

ParameterDescription
sandbox_group_id

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

image_id

Required. The ID of the image to delete.

Sandbox groups

Lists sandbox groups in the specified workspace.

To paginate, use next_cursor from the previous response to retrieve the next page. Continue until a page contains no groups.

On success: Returns a SandboxGroupList containing a page of sandbox groups and a cursor for the next page.

Raises: RateLimitError, ClientError, ServerError, RenderError

Supported parameters include:

ParameterDescription
owner_id

The ID of the workspace to list sandbox groups for.

Defaults to the client configuration.

If this value is not set here, it must be set in the client configuration. Otherwise, this method raises RenderError.

cursor

The next_cursor from 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.

Creates a sandbox group in the specified workspace.

On success: Returns a SandboxGroup object.

Raises: RateLimitError, ClientError, ServerError, RenderError

Supported parameters include:

ParameterDescription
name

Required. The name of the sandbox group.

owner_id

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

region

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

Defaults to oregon.

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

On success: Returns a SandboxGroup object.

Raises: RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_group_id

Required. The ID of the sandbox group to retrieve.

Sets the specified sandbox group's concurrency limit. The returned group includes the new effective limit, which might be lower than the requested limit if capped by your workspace's concurrency limit.

On success: Returns a SandboxGroup object.

Raises: RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_group_id

Required. The ID of the sandbox group to update.

concurrency_limit

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.

Deletes the specified sandbox group and initiates termination of its sandboxes. Snapshots in the group are also deleted as part of cleanup.

You cannot delete a workspace's default sandbox group. First use set_default_group to make another group the default.

On success: Returns None.

Raises: SandboxGroupDefaultNotDeletableError, RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_group_id

Required. The ID of the sandbox group to delete.

Sets the specified sandbox group as the workspace's default group. If you create a sandbox without specifying a sandbox_group_id, it belongs to the default group.

On success: Returns a SandboxGroup object.

Raises: RateLimitError, ClientError, ServerError, RenderError

ParameterDescription
sandbox_group_id

Required. The ID of the sandbox group to make the default.

Error types

All SDK-specific errors inherit from RenderError. Import common errors from render.client.errors and sandbox-specific errors from render.sandbox.

The SDK can also raise standard Python exceptions, such as ValueError for invalid parameter values.

Sandbox errors

These errors pertain to sandbox operations that cannot resolve required client configuration or encounter an unexpected response.

The base class for SDK-specific errors. Raised when an operation cannot resolve a required owner ID or encounters an unexpected sandbox response.

Raised when the sandbox does not exist or is no longer retrievable.

Raised when command execution or file transfer is attempted on a sandbox with a status of terminated or errored. Includes the status in sandbox_status.

Sandbox group errors

These errors pertain to deleting sandbox groups and changing the workspace's default group.

Raised when delete_group attempts to delete the workspace's default sandbox group. Use set_default_group to make another group the default before deleting it.

Command execution errors

These errors pertain to running commands in a sandbox.

Raised when the event stream for the exec method ends with a terminal error. Includes status and message properties.

Raised when the command event stream ends without a final exit event or contains invalid event data.

File transfer errors

Raised when the requested path does not exist in the sandbox.

Raised when copy_from encounters a local filesystem error while saving a download or cannot safely extract a downloaded directory.

Readiness errors

These errors pertain to waiting for a sandbox or snapshot to be ready.

Raised when wait_until_running detects that the specified sandbox has a status of errored, terminated, suspending, or suspended. Includes sandbox_id and sandbox_status.

Raised when snapshots.wait_until_available detects that the specified snapshot has a status of failed. Includes snapshot_id and the capture error in snapshot_error, if available.

Raised when a sandbox does not reach a status of running within the specified wait timeout. Includes sandbox_id, timeout_seconds, and last_status (or None if no status check completed).

Raised when a snapshot does not reach a status of available within the specified wait timeout. Includes snapshot_id, timeout_seconds, and last_status (or None if no status check completed).

Raised when create reaches a failure state while waiting for a created sandbox to reach a status of running.

Common failure states include:

  • The wait timeout passed to create was reached.
  • The sandbox reached a non-running status (errored, terminated, suspending, or suspended).

Includes sandbox_id and the underlying error in cause.

The created sandbox still exists. Use from_id to retrieve its details, including its current status.

Raised when snapshots.create reaches a failure state while waiting for a created snapshot to reach a status of available.

Common failure states include:

  • The wait timeout passed to snapshots.create was reached.
  • The snapshot capture failed.

Includes snapshot_id, sandbox_group_id, and the underlying error in cause.

The created snapshot still exists. Use snapshots.from_id to retrieve its details, including its current status.

Snapshot errors

These errors pertain to creating snapshots, restoring from snapshots, and managing snapshots.

Raised when a specified snapshot cannot be found in the specified sandbox group.

Common causes include:

  • The snapshot was deleted.
  • The snapshot expired.
  • The snapshot belongs to a different sandbox group.

Raised when a sandbox attempts to restore from a snapshot with a non-available status, or when attempting to delete a snapshot with a status of creating.

Raised when a sandbox attempts to restore from a runtime snapshot if its compute plan does not match the plan of the snapshot's source sandbox.

Image errors

These errors pertain to importing and managing Docker images and creating sandboxes from them.

Raised when a specified image cannot be found in the specified sandbox group by ID or name.

Common causes include:

  • The image was deleted.
  • The image belongs to a different sandbox group.

Raised when create attempts to use an image with a non-succeeded status. The import might still be in progress or have failed.

Raised when images.delete attempts to delete an image that at least one sandbox or snapshot depends on (such as to resume or restore). The error message identifies dependent sandboxes and snapshots.

Raised when images.wait_until_ready detects that the specified image has a status of failed. Includes image_id and the API's failure_reason, if available.

Raised when the specified image does not reach a status of succeeded within the timeout for images.wait_until_ready. Includes image_id, timeout_seconds, and last_status (or None if no status check completed).

The image import continues and might still succeed.

API errors

These errors pertain to responses from the Render API.

Raised when the API returns a 4xx response, including HTTP 429 for either the request rate or concurrency cap (see Sandbox limits).

Includes code when the API provides an error code.

Raised when the API returns HTTP 429 because of a request rate or concurrency limit. See Sandbox limits.

Raised when the API returns a 5xx response.

Raised when an API request times out. Also the parent class of SandboxWaitTimeoutError, SnapshotWaitTimeoutError, and ImageWaitTimeoutError. This is the SDK's TimeoutError, imported from render.client.errors.

Additional types

Represents a single sandbox on Render. Returned by methods such as create, from_id, and wait_until_running.

PropertyDescription
id

The sandbox's ID.

name

The sandbox's name, or None if no name was provided when it was created.

status

The sandbox's current status:

StatusDescription

creating

Creation is in progress. The sandbox is not yet ready to execute commands or transfer files.

running

The sandbox is ready. You can execute commands and transfer files.

suspending

Suspension is in progress. Render is saving the sandbox's state.

suspended

The sandbox is suspended. Executing a command or transferring files resumes it automatically.

resuming

Resumption is in progress. Render is restoring the sandbox's saved state.

errored

The sandbox encountered an error. It can no longer execute commands or transfer files.

terminated

The sandbox has been terminated. It can no longer execute commands or transfer files.

plan

The sandbox's compute plan.

network_policy

The sandbox's outbound network policy, as a NetworkPolicy object.

region

The region that the sandbox runs in.

This value is currently always oregon.

timeout_seconds

The sandbox's runtime timeout, in seconds.

A value of 0 indicates that this timeout is disabled.

This timeout restarts if the sandbox is suspended and later resumed.

idle_timeout_seconds

The sandbox's idle timeout, in seconds.

A value of 0 indicates that this timeout is disabled.

This timeout restarts if the sandbox is suspended and later resumed.

sandbox_group_id

The ID of the sandbox group that contains the sandbox.

created_at

The time when the sandbox was created, as a datetime.

terminated_at

For a terminated sandbox, the time when it was terminated, as a datetime.

This also applies to termination caused by an error, in which case the sandbox has a status of errored instead of terminated.

For sandboxes with any other status, this value is None.

Specifies a sandbox's outbound network policy. Provide this object as network_policy to create.

PropertyDescription
type

Required. The sandbox's outbound network policy. One of the following:

ValueDescription
allow-allAllows the sandbox to make outbound connections to any destination over any protocol.
deny-allBlocks all outbound traffic from the sandbox.
allow-listAllows the sandbox to make outbound HTTPS connections to the destinations specified in rules. All other outbound traffic is blocked.
rules

Required when type is allow-list, omit otherwise. A list of EgressRule objects specifying destinations the sandbox can access over HTTPS. All other outbound traffic from the sandbox is blocked.

You can define a maximum of 100 rules for a given sandbox.

Specifies a destination allowed by a NetworkPolicy with a type of allow-list.

PropertyDescription
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

Defaults to https. Currently, only https is supported.

Specifies wait settings for create and snapshots.create. Provide this object as the method's wait parameter.

PropertyDescription
timeout_seconds

The maximum total time to wait, in seconds.

Defaults to None, which uses the method's default: 60 (60 seconds) for create or 300 (five minutes) for snapshots.create.

interval_seconds

The initial delay between status checks, in seconds. Must be greater than 0.

  • If you provide a value less than 2 seconds, the delay doubles with each attempt up to 2 seconds.
  • If you provide a value of 2 seconds or more, the delay remains constant between attempts.

Defaults to 0.25.

Represents one page of sandboxes returned by list.

PropertyDescription
sandboxes

A list of Sandbox objects in this page.

next_cursor

The cursor to pass on the next request. None when the current page is empty.

Represents an output event received while streaming command output from the exec method.

PropertyDescription
stream

The output stream that the command wrote to: stdout or stderr.

data

The string that the command wrote to the specified stream.

Represents the final exit event received from the exec method.

PropertyDescription
exit_code

The command's exit code, as an integer.

Conventionally, a value of 0 indicates success, and a non-zero value indicates failure.

The SandboxExecEvent type is a SandboxExecOutput or SandboxExecExit object received while streaming command output from exec.

Represents a single sandbox group on Render. Returned by methods such as get_group or included in a SandboxGroupList page.

PropertyDescription
id

The sandbox group's ID.

owner_id

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.

is_default

Whether this is the workspace's default sandbox group.

concurrency_limit

The maximum number of sandboxes that can run concurrently in this group.

Suspended sandboxes do not count toward the limit. For details, see Concurrency per group.

created_at

The time when the sandbox group was created, as a datetime.

updated_at

The time when the sandbox group was last updated, as a datetime.

environment_id

The ID of the group's associated environment.

This value is None if the group does not belong to a specific environment.

Represents one page of sandbox groups returned by list_groups.

PropertyDescription
groups

A list of SandboxGroup objects in this page.

next_cursor

The cursor to pass on the next request. None when the current page is empty.

Represents a single imported Docker image. Returned by methods such as images.import_ and images.from_id or included in an ImageList page.

PropertyDescription
id

The image's ID, starting with sbb-.

Provide this value as image to create to select this specific imported version.

sandbox_group_id

The ID of the sandbox group that contains the image.

name

The name associated with the imported image. Multiple imported versions can share the same name.

source

An ImageSource object identifying the Docker image in the source registry.

source_digest

The resolved digest of the source image. Starts with sha256:.

status

The image's current import status:

StatusDescription

pending

Import is queued. The image is not yet ready to create sandboxes.

running

Import is in progress. The image is not yet ready to create sandboxes.

succeeded

Import succeeded. You can create sandboxes from the image.

failed

Import failed. Check the image's failure details.

failure_reason

If status is failed, details about the import failure, if available. These can include error text from the source registry.

For images with any other status, this value is None.

created_at

The time when the import was created, as a datetime.

finished_at

If status is succeeded or failed, the time when the import completed, as a datetime.

For images with any other status, this value is None.

Represents the source Docker image identified by the source property of an Image object.

PropertyDescription
repository

The registry host and repository path, such as index.docker.io/library.

image

The source image's name within the repository, such as python.

reference

The source image's tag or digest, such as 3.13 or sha256:....

Represents one page of imported Docker images returned by images.list.

PropertyDescription
images

A list of Image objects in this page.

next_cursor

The cursor to pass on the next request. None when the current page is empty.

Represents a single sandbox snapshot. Returned by methods such as snapshots.from_id or included in a SnapshotList page.

PropertyDescription
id

The snapshot's ID.

sandbox_group_id

The ID of the sandbox group that contains the snapshot.

source_sandbox_id

The ID of the snapshot's source sandbox.

name

The snapshot's name.

This value is None if the snapshot has no name.

kind

The kind of snapshot: filesystem or runtime.

For details, see Snapshot kinds.

status

The snapshot's current status:

StatusDescription

creating

Capture is in progress. New sandboxes cannot yet be restored from the snapshot.

available

Capture succeeded. New sandboxes can now be restored from the snapshot.

failed

Capture failed. Check the snapshot's error field for details.

plan

The compute plan of the snapshot's source sandbox.

requested_at

The time when snapshot capture was requested, as a datetime.

captured_at

The time when capture completed, as a datetime.

This value is None while the snapshot is still being created.

expires_at

The snapshot's current expiration time, as a datetime. Restoring from the snapshot refreshes its TTL and updates this time accordingly.

For a snapshot with TTL disabled, this value has a year of 9999.

ttl_seconds

The snapshot's total time-to-live (TTL), in seconds.

This value does not dynamically decrement to reflect the current amount of time until expiration. Use the expires_at property instead.

For a snapshot with TTL disabled, this value is 0.

size_bytes

The snapshot's size, in bytes.

This value is None while the snapshot is still being created.

error

If status is failed, the error message describing the capture failure.

For snapshots with any other status, this value is None.

Represents one page of snapshots returned by snapshots.list.

PropertyDescription
snapshots

A list of Snapshot objects in this page.

next_cursor

The cursor to pass on the next request. None when the current page is empty.

View as Markdown
Open in ChatGPT
Open in Claude
  • Setup
    • 1. Install the SDK
    • 2. Import the client (sync or async)
      • Render
      • RenderAsync
  • Sandbox lifecycle
    • create
    • wait_until_running
    • from_id
    • list
    • terminate
  • Runtime execution
    • exec
    • copy_to
    • copy_from
  • Snapshots
    • snapshots.create
    • snapshots.wait_until_available
    • snapshots.from_id
    • snapshots.list
    • snapshots.delete
  • Docker images
    • images.import_
    • images.wait_until_ready
    • images.from_id
    • images.list
    • images.delete
  • Sandbox groups
    • list_groups
    • create_group
    • get_group
    • update_group
    • delete_group
    • set_default_group
  • Error types
    • Sandbox errors
      • RenderError
      • SandboxNotFoundError
      • SandboxEndedError
    • Sandbox group errors
      • SandboxGroupDefaultNotDeletableError
    • Command execution errors
      • SandboxExecStreamError
      • SandboxExecError
    • File transfer errors
      • SandboxFileNotFoundError
      • SandboxDownloadError
    • Readiness errors
      • SandboxNotRunningError
      • SnapshotFailedError
      • SandboxWaitTimeoutError
      • SnapshotWaitTimeoutError
      • SandboxCreateWaitError
      • SnapshotCreateWaitError
    • Snapshot errors
      • SnapshotNotFoundError
      • SnapshotNotReadyError
      • SnapshotPlanMismatchError
    • Image errors
      • ImageNotFoundError
      • ImageNotReadyError
      • ImageInUseError
      • ImageFailedError
      • ImageWaitTimeoutError
    • API errors
      • ClientError
      • RateLimitError
      • ServerError
      • TimeoutError
  • Additional types
    • Sandbox
    • NetworkPolicy
    • EgressRule
    • SandboxWaitOptions
    • SandboxList
    • SandboxExecOutput
    • SandboxExecExit
    • SandboxExecEvent
    • SandboxGroup
    • SandboxGroupList
    • Image
    • ImageSource
    • ImageList
    • Snapshot
    • SnapshotList
    • Home
    • Your first deploy
    • Free instances
    • Platform features by plan
    • Use with coding agents
    • FAQ
    • Templates
      • Migrate from…
        • Heroku
        • Railway
    • Compute plans
    • SandboxesBeta
      • Service types
        • Which to use?
        • Static sites
        • Web services
        • Private services
        • Background workers
        • Cron jobs
        • Workflows
        • Multi-service architectures
      • Data storage
        • Render Postgres
        • Render Key Value (Redis®-compatible)
        • Persistent disks
    • How deploys work
    • Supported languages
    • Git providers (GitHub, etc.)
    • Build pipeline
    • Deploy hooks
    • Monorepo support
    • Troubleshooting deploys
      • Previewing changes
        • Single-service previews
        • Preview environments (multi-service)
      • Docker deploys
        • Overview
        • Deploy a registered image
        • Using secrets
      • Runtime
        • Native runtimes
        • Environment variables & secrets
        • Default environment variables
    • Intro to sandboxes
    • Limits & pricing
      • How to…
        • Create & configure sandboxes
        • Execute commands
        • Upload & download files
        • Manage snapshots
      • Use with…
        • Claude Managed Agents
        • Cursor Cloud Agents
        • OpenAI Agents API
      • SDK/CLI reference
        • TypeScript SDK
        • Python SDK
        • CLI commands
    • Intro to workflows
    • Tutorial
    • Limits & pricing
      • How to…
        • Define tasks
        • Define flowsNew
        • Trigger runs
        • Develop locally
      • SDK/CLI reference
        • TypeScript SDK
        • Python SDK
        • CLI commands
      • Example workflows
        • TypeScript examples
        • Python examples
    • Overview
    • Create & connect
    • Database credentials
    • Extensions
    • Version upgrades
    • Logical replication
    • Legacy instance types
      • Database recovery
        • Recovery & backups
        • High availability
      • Database performance
        • Read replicas
        • Connection pooling
        • Admin apps
        • Repacking tables
        • Troubleshooting performance
    • Regions
    • Inbound IP rules
    • Edge caching
    • WebSockets
    • TLS certificates
      • Custom domains
        • Overview
        • Cloudflare
        • Namecheap
        • Other DNS providers
      • Internal traffic
        • Private network
        • Private links
      • Outbound traffic
        • Default IP ranges
        • Dedicated IP addresses
        • Outbound bandwidth
        • Handling network changes
      • Static site config
        • Custom response headers
        • Redirects & rewrites
    • The Render Dashboard
    • SSH / Shell access
    • Projects & environments
      • Service actions
        • Scaling
        • Rollbacks
        • Maintenance mode
        • One-off jobs
      • Infrastructure as code
        • Blueprints overview
        • render.yaml reference
        • Terraform provider
    • In-dashboard metrics
    • Health checks
    • Uptime best practices
      • Logging
        • In-dashboard logs
        • Log streams (syslog/HTTPS)
      • OpenTelemetry (OTel) metrics
        • Provider setup
        • Metrics reference
      • Notifications
        • Webhooks
        • Email / Slack
    • API keys
    • MCP Server
      • Render CLI
        • Overview
        • Command reference
      • REST API
        • Overview
        • API reference
      • Third-party connections
        • OIDC support
        • Datadog
    • Workspaces, members, & roles
    • Login settings
    • Audit logs
      • Organizations
        • Overview
        • SAML SSO
    • DDoS protection
    • Platform maintenance
      • Compliance
        • Overview
        • HIPAA (US health data)
        • HIPAA best practices
        • Shared responsibility model
        • Pentest policy
    • Heroku vs Render
    • Vercel vs Render
All Systems Operational
© Render Inc. All rights reserved.
shell
$ pip install render
shell
$ pip install --upgrade render
python
from render import Render
sandboxes = Render().sandboxes
sandbox = sandboxes.create(wait=True)
for event in sandboxes.exec(sandbox.id, "echo hello"):
print(event)
python
import asyncio
from render import RenderAsync
async def main():
sandboxes = RenderAsync().sandboxes
sandbox = await sandboxes.create(wait=True)
async for event in sandboxes.exec(sandbox.id, "echo hello"):
print(event)
asyncio.run(main())
python
sandbox = sandboxes.create(
plan="2c-4g",
idle_timeout_seconds=1800,
wait=True,
)
python
from render.sandbox import EgressRule, NetworkPolicy
sandbox = sandboxes.create(
network_policy=NetworkPolicy(
type="allow-list",
rules=[EgressRule(domain="api.example.com")],
),
)
python
{
"PYTHONUNBUFFERED": "1",
"REQUEST_TIMEOUT_SECONDS": "30",
}
python
sandbox = sandboxes.wait_until_running("sbx-abc123")
print(sandbox.status)
python
from render.sandbox import SandboxExecExit, SandboxExecOutput
for event in sandboxes.exec("sbx-abc123", "echo hello"):
if isinstance(event, SandboxExecOutput):
print(event.data, end="")
elif isinstance(event, SandboxExecExit):
print(f"Exit code: {event.exit_code}")
python
sandboxes.copy_to("sbx-abc123", "./inputs", "/home/render/inputs")
python
path = sandboxes.copy_from(
"sbx-abc123",
remote_path="output.json",
local_path="./output.json",
)
print(path)
python
snapshot = sandboxes.snapshots.create(
sandbox_id="sbx-abc123",
name="python-ready",
wait=True,
)
python
snapshot = sandboxes.snapshots.wait_until_available(
sandbox_group_id="sbg-abc123",
snapshot_id="snp-abc123",
)
print(snapshot.status)
python
image = sandboxes.images.import_(
sandbox_group_id="sbg-abc123",
name="python",
source="python:3.13",
)
print(image.id, image.status)
plaintext
[REGISTRY_HOST]/[REPOSITORY_PATH]/[IMAGE_NAME]:[TAG]
[REGISTRY_HOST]/[REPOSITORY_PATH]/[IMAGE_NAME]@[DIGEST]
plaintext
docker.io/library/alpine:latest
docker.io/library/alpine@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf
python
image = sandboxes.images.wait_until_ready(
sandbox_group_id="sbg-abc123",
image_id="sbb-cph1rs3idesc73a2b2mg",
)
print(image.status)
python
image = sandboxes.images.from_id(
sandbox_group_id="sbg-abc123",
image_id="sbb-cph1rs3idesc73a2b2mg",
)
print(image.status, image.failure_reason)
python
images = sandboxes.images.list(
sandbox_group_id="sbg-abc123",
name="python",
status=["succeeded"],
limit=20,
)
python
sandboxes.images.delete(
sandbox_group_id="sbg-abc123",
image_id="sbb-cph1rs3idesc73a2b2mg",
)
python
group = sandboxes.create_group("agents", region="oregon")
print(group.id)
python
group = sandboxes.get_group("sbg-abc123")
print(group.concurrency_limit)
python
group = sandboxes.update_group("sbg-abc123", concurrency_limit=10)
print(group.concurrency_limit)
python
sandboxes.delete_group("sbg-abc123")
python
group = sandboxes.set_default_group("sbg-abc123")
print(group.is_default)
python
from render.sandbox import EgressRule, NetworkPolicy
policy = NetworkPolicy(
type="allow-list",
rules=[EgressRule(domain="api.example.com")],
)
python
from render.sandbox import EgressRule
rule = EgressRule(domain="api.example.com")
python
from render.sandbox import SandboxWaitOptions
options = SandboxWaitOptions(timeout_seconds=120, interval_seconds=0.5)