SandboxClient¶
- class baseten.sandbox.SandboxClient(*, api_key, team_id=None, token_provider=None, base_url_override=None, headers=None, retry=None, http2=None, http_client_override=None, close_http_client_on_close=None, executor=None)¶
Bases:
objectClient for Baseten sandboxes.
Creates, finds, and deletes sandboxes, and gets a
Sandboxto work in one. Can be used as a context manager to ensure the underlying HTTP client is closed on exit.- Parameters:
- close()¶
Close the client, optionally closing the underlying HTTP client.
- Return type:
None
- create(*, name=None, create_if_not_exists=None, image=None, memory=None, region=None, envs=None, labels=None, external_id=None, lifecycle=None, ports=None, network=None, filesystem=None)¶
Create a sandbox.
- Parameters:
name (str | None) – Unique name of the sandbox. Assigned by the server when
None.create_if_not_exists (bool | None) – When true, return the existing live sandbox with this name, or recreate it if it is failed, terminated, or being deleted. Requires name. Existing configuration is preserved.
image (str | None) – Image reference including its tag. Defaults to
baseten/base-image:latest.memory (int | None) – Memory in megabytes, which also sets the CPU allocation. Defaults to 4096.
region (str | None) – Region to run in.
Nonepicks the closest one.envs (Mapping[str, SandboxEnvValue] | None) – Environment variables, by name.
external_id (str | None) – Caller-owned identifier for external lookups.
lifecycle (SandboxLifecycle | None) – When the sandbox is deleted automatically.
ports (Sequence[SandboxPort] | None) – Ports the sandbox exposes.
network (SandboxNetwork | None) – Network configuration, which cannot be changed after creation.
filesystem (SandboxFileSystemOptions | None) – Filesystem configuration, which cannot be changed after creation.
- Return type:
- delete(*, name)¶
Delete a sandbox.
Deletion continues after this returns, so the returned record usually shows it as still deleting.
- Parameters:
name (str) – Name of the sandbox.
- Return type:
- get(*, name: str) Sandbox¶
- get(*, info: SandboxInfo) Sandbox
Get a
Sandboxto work in.Fetches the sandbox’s record when given a name, and makes no call when given the record.
- Parameters:
name (str | None) – Name of the sandbox.
info (SandboxInfo | None) – The sandbox’s record, already in hand.
- Return type:
- get_info(*, name, show_secrets=None)¶
Get a sandbox’s current record.
- Parameters:
- Return type:
- property http_client: Client¶
The underlying HTTP client.
- property images: ImageClient¶
Images that sandboxes are created from.
- list(*, query=None, statuses=None, external_id=None, page_size=None)¶
List sandboxes, fetching further pages as iteration reaches them.
- Parameters:
query (str | None) – Searches sandbox names and labels.
statuses (Sequence[Literal['DEPLOYING', 'DEPLOYED', 'FAILED', 'DEACTIVATING', 'DEACTIVATED', 'DELETING', 'TERMINATED', 'ARCHIVING', 'ARCHIVED', 'UNARCHIVING', 'BUILDING', 'UPLOADING'] | str] | None) – Only sandboxes with one of these statuses. Cannot be combined with external_id.
external_id (str | None) – Only the sandbox with this external identifier. Cannot be combined with statuses.
page_size (int | None) – How many sandboxes to fetch per underlying request.
- Return type:
- property options: SandboxClientOptions¶
Client options.
- property raw_api: ApiClient¶
The generated management API client, authenticated for sandboxes.
For operations this SDK does not wrap. The generated API surface is not covered by stability guarantees and may change between versions.
- sandbox_from_url(*, url)¶
Get a
Sandboxfor a sandbox’s execution API URL, making no call.Its
Sandbox.nameis empty.- Parameters:
url (str) – Base URL of the sandbox’s execution API, as reported in
SandboxInfo.url.- Return type:
- update(*, name, lifecycle=None, envs=None, external_id=None, labels=None)¶
Update a sandbox’s configuration, returning its record after the change.
Arguments left
Nonestay unchanged, and set ones replace their previous values, including every entry of envs, labels, and the lifecycle’s expiration policies. Other lifecycle fields change only when set. At least one argument besides name must be set. Other settings cannot be changed after creation.- Parameters:
name (str) – Name of the sandbox.
lifecycle (SandboxLifecycle | None) – When the sandbox is deleted automatically.
envs (Mapping[str, SandboxEnvValue] | None) – Environment variables, by name.
external_id (str | None) – Caller-owned identifier for external lookups.
- Return type: