Source: src/cwsandbox/_session.py:38Documentation Index
Fetch the complete documentation index at: https://docs.coreweave.com/llms.txt
Use this file to discover all available pages before exploring further.
- Creating multiple sandboxes with shared configuration
- Executing Python functions in sandboxes
- You want automatic cleanup of orphaned sandboxes
Properties
sandbox_count
Methods
log_metrics
step(int | None): Training step to associate with metrics. If provided, metrics are logged at this step number in wandb.reset(bool): If True (default), reset accumulated metrics after a successful log. Metrics are preserved if log() fails (no active wandb run). Set to False to keep accumulating regardless.
bool: True if metrics were logged, False if no reporter configuredbool: or no active wandb run.
get_metrics
dict[str, Any]: Dictionary with cwsandbox/* prefixed metric names and values.dict[str, Any]: Empty dict if no reporter is configured.
close
OperationRef[None]: OperationRef[None]: Use .result() to block until all sandboxes stopped.
SandboxError: If one or more running sandboxes failed to stop.
sandbox
command(str | None): Command to run in sandboxargs(list[str] | None): Arguments for the commandcontainer_image(str | None): Container image to usetags(list[str] | None): Tags for the sandbox (merged with session defaults)profile_ids(list[str] | None): Optional list of profile IDs for infrastructure selection. See SandboxDefaults.profile_ids for semantics. Preferprofile_nameswhen selecting by name.profile_names(list[str] | None): Optional list of profile names for infrastructure selection (preferred over profile_ids). See SandboxDefaults.profile_names for semantics.runner_ids(list[str] | None): Optional list of runner IDsresources(ResourceOptions | dict[str, Any] | None): Resource configuration. Accepts ResourceOptions for separate requests/limits, or a flat dict for backward-compatible Guaranteed QoS.mounted_files(list[dict[str, Any]] | None): Files to mount into the sandboxs3_mount(dict[str, Any] | None): S3 bucket mount configurationports(list[dict[str, Any]] | None): Port mappings for the sandboxnetwork(NetworkOptions | dict[str, Any] | None): Network configuration (NetworkOptions dataclass)max_timeout_seconds(int | None): Maximum timeout for sandbox operationsenvironment_variables(dict[str, str] | None): Environment variables to inject into the sandbox. Merges with and overrides matching keys from the session defaults. Use for non-sensitive config only.annotations(dict[str, str] | None): Kubernetes pod annotations for the sandbox. Merges with and overrides matching keys from the session defaults. Use for non-sensitive metadata only.secrets(Sequence[Secret | dict[str, Any]] | None): Secrets to inject as environment variables. Merged with session defaults (defaults first, then this list).
Sandbox: An unstarted Sandbox registered with the session.
SandboxError: If the session has been closed.
list
include_stopped=True to widen the search to include terminal
sandboxes (completed, failed, terminated).
A terminal status filter (e.g. status="completed") also widens
the search automatically.
Parameters
tags(list[str] | None): Additional tags to filter by (merged with session’s default tags)status(str | None): Filter by statusprofile_ids(list[str] | None): Optional list of profile IDs for infrastructure selection (defaults to session’s profile_ids if set). See SandboxDefaults.profile_ids for semantics. Preferprofile_nameswhen selecting by name.profile_names(list[str] | None): Optional list of profile names for infrastructure selection (preferred over profile_ids). Defaults to session’s profile_names if set. See SandboxDefaults.profile_names for semantics.runner_ids(list[str] | None): Filter by runner IDs (defaults to session’s runner_ids if set)include_stopped(bool): If True, include terminal sandboxes (completed, failed, terminated). Defaults to False.adopt(bool): If True, register discovered sandboxes with this session so they are stopped when the session closes
OperationRef[list[Sandbox]]: OperationRef[list[Sandbox]]: Use .result() to block for results,OperationRef[list[Sandbox]]: or await directly in async contexts.
from_id
sandbox_id(str): The ID of the existing sandboxadopt(bool): If True (default), register the sandbox with this session
OperationRef[Sandbox]: OperationRef[Sandbox]: Use .result() to block for the Sandbox instance,OperationRef[Sandbox]: or await directly in async contexts.
adopt
sandbox(Sandbox): A Sandbox instance to track
SandboxError: If the session is closedValueError: If the sandbox has no sandbox_id
function
container_image(str | None): Override session’s default image for this functionserialization(Serialization): How to serialize arguments and return values. Defaults to JSON for safety. Use PICKLE for complex types, but only in trusted environments.temp_dir(str | None): Override temp directory for payload/result files in sandbox. Defaults to session default. Created if missing.profile_ids(list[str] | None): Optional list of profile IDs for infrastructure selection. See SandboxDefaults.profile_ids for semantics. Preferprofile_nameswhen selecting by name.profile_names(list[str] | None): Optional list of profile names for infrastructure selection (preferred over profile_ids). See SandboxDefaults.profile_names for semantics.runner_ids(list[str] | None): Optional list of runner IDsresources(ResourceOptions | dict[str, Any] | None): Resource configuration. Accepts ResourceOptions for separate requests/limits, or a flat dict for backward-compatible Guaranteed QoS.mounted_files(Sequence[dict[str, Any]] | None): Files to mount into the sandboxs3_mount(dict[str, Any] | None): S3 bucket mount configurationports(Sequence[dict[str, Any]] | None): Port mappings for the sandboxnetwork(NetworkOptions | dict[str, Any] | None): Network configuration (NetworkOptions dataclass)max_timeout_seconds(int | None): Maximum timeout for sandbox operationsenvironment_variables(dict[str, str] | None): Environment variables to inject into the sandbox. Merges with and overrides matching keys from the session defaults. Use for non-sensitive config only.annotations(dict[str, str] | None): Kubernetes pod annotations for the sandbox. Merges with and overrides matching keys from the session defaults. Use for non-sensitive metadata only.
Callable[[Callable[P, R]], RemoteFunction[P, R]]: A decorator that wraps a function as a RemoteFunction