SandboxPreviews

class baseten.sandbox.SandboxPreviews

Bases: object

A sandbox’s previews, which expose its ports on HTTPS URLs.

Obtained from Sandbox.previews. Previews need the sandbox’s name, so every call fails on a sandbox from SandboxClient.sandbox_from_url().

Parameters:

context (SandboxContext)

create(*, port, name=None, create_if_not_exists=None, public=None, response_headers=None, request_headers=None, ttl=None, expires_at=None)

Create a preview exposing a sandbox port.

Parameters:
  • port (int) – Sandbox port to expose.

  • name (str | None) – Name of the preview, unique within the sandbox. Assigned by the server when None.

  • create_if_not_exists (bool | None) – When true, return the existing preview with this name, unchanged, instead of failing.

  • public (bool | None) – Make the URL reachable without a token. Defaults to false, a private preview.

  • response_headers (Mapping[str, str] | None) – Headers added to every response the preview serves, such as CORS headers.

  • request_headers (Mapping[str, str] | None) – Headers added to every request forwarded to the sandbox, such as an Authorization header the application expects.

  • ttl (timedelta | None) – Delete the preview this long after the request. Cannot be combined with expires_at.

  • expires_at (datetime | None) – Delete the preview at this time. Cannot be combined with ttl.

Return type:

SandboxPreviewInfo

create_token(*, preview_name, expires_at, create_if_not_exists=None)

Create a token granting access to a private preview.

Parameters:
  • preview_name (str) – Name of the private preview.

  • expires_at (datetime) – When the token stops working.

  • create_if_not_exists (bool | None) – When true, return an existing unexpired token of the preview that stays valid at least until expires_at, instead of creating one. A token created moments before may not be found yet, so a new one may be created anyway.

Return type:

SandboxPreviewTokenInfo

delete(*, name)

Delete a preview and its tokens, returning its record.

The URL stops serving at once, but the record may show the preview as deleting while the server finishes; this does not wait for that.

Parameters:

name (str) – Name of the preview.

Return type:

SandboxPreviewInfo

delete_token(*, preview_name, token_name)

Revoke a preview token. Requests using it are rejected at once.

Parameters:
  • preview_name (str) – Name of the private preview.

  • token_name (str) – Name of the token.

Return type:

None

get_info(*, name, show_secrets=None)

Get a preview’s current record.

Parameters:
  • name (str) – Name of the preview.

  • show_secrets (bool | None) – Reveal request header values for workspace administrators. Defaults to false. Callers without the admin role receive masked values even when true.

Return type:

SandboxPreviewInfo

list(*, page_size=None)

List the sandbox’s previews, fetching further pages as iteration reaches them.

Parameters:

page_size (int | None) – How many previews to fetch per underlying request.

Return type:

Iterator[SandboxPreviewInfo]

list_tokens(*, preview_name, page_size=None)

List a private preview’s tokens, fetching further pages as iteration reaches them.

Expired tokens are included until the server removes them. A public preview has no tokens, and the server rejects the call.

Parameters:
  • preview_name (str) – Name of the private preview.

  • page_size (int | None) – How many tokens to fetch per underlying request.

Return type:

Iterator[SandboxPreviewTokenInfo]

update(*, name, public=None, response_headers=None, request_headers=None, ttl=None, expires_at=None)

Update a preview, returning its record after the change.

Arguments left None stay unchanged. The URL does not change, and the name and port cannot be changed.

Parameters:
  • name (str) – Name of the preview.

  • public (bool | None) – Whether the URL is reachable without a token.

  • response_headers (Mapping[str, str] | None) – Headers added to every response, replacing the whole set: headers left out are removed, and an empty mapping removes them all.

  • request_headers (Mapping[str, str] | None) – Headers added to every forwarded request, replacing the whole set: headers left out are removed, and an empty mapping removes them all. Sending back a "****" value from SandboxPreviewInfo.request_headers is rejected, so to change one header, get the others with show_secrets and send them all.

  • ttl (timedelta | None) – Delete the preview this long after the request, replacing any previous expiration. Cannot be combined with expires_at.

  • expires_at (datetime | None) – Delete the preview at this time, replacing any previous expiration. Cannot be combined with ttl.

Return type:

SandboxPreviewInfo