AsyncSandbox | Daytona

AsyncSandbox

@with_events

class AsyncSandbox(SandboxDto)

Represents a Daytona Sandbox.

Attributes:

env: dict[str, str] | None
env = None
network_block_all: bool | None
network_block_all = None
kvm: bool | None
kvm = None

AsyncSandbox.init

def __init__(sandbox_dto: SandboxDto | SandboxListItem,
             toolbox_api: ApiClient,
             sandbox_api: SandboxApi,
             language: str,
             subscription_manager: AsyncEventSubscriptionManager,
             pool_tracker: AsyncPoolSaturationTracker | None = None,
             analytics_api_url_provider: Callable[[], Awaitable[str | None]] | None = None)

Initialize a new Sandbox instance.

Arguments:

AsyncSandbox.refresh_data

@intercept_errors(message_prefix="Failed to refresh sandbox data: ")
@with_instrumentation()
async def refresh_data(request_timeout: float | None = None) -> None

Refreshes the Sandbox data from the API.

Arguments:

Example:

await sandbox.refresh_data()

print(f"Sandbox {sandbox.id}:")

print(f"State: {sandbox.state}")

print(f"Resources: {sandbox.cpu} CPU, {sandbox.memory} GiB RAM")

AsyncSandbox.get_user_home_dir

@intercept_errors(message_prefix="Failed to get user home directory: ")
@with_instrumentation()
async def get_user_home_dir() -> str

Gets the user’s home directory path inside the Sandbox.

Returns:

Example:

user_home_dir = await sandbox.get_user_home_dir()

print(f"Sandbox user home: {user_home_dir}")

AsyncSandbox.get_work_dir

@intercept_errors(message_prefix="Failed to get working directory path: ")
@with_instrumentation()
async def get_work_dir() -> str

Gets the working directory path inside the Sandbox.

Returns:

Example:

work_dir = await sandbox.get_work_dir()

print(f"Sandbox working directory: {work_dir}")

AsyncSandbox.get_metrics_latest

@intercept_errors(message_prefix="Failed to get sandbox metrics: ")
@with_instrumentation()
async def get_metrics_latest() -> SandboxMetrics

Gets the most recent resource usage sample directly from the Sandbox daemon.

Unlike :meth:get_metrics, which returns aggregated historical samples, this returns the single current reading without going through the telemetry backend.

Returns:

AsyncSandbox.get_metrics

@intercept_errors(message_prefix="Failed to get sandbox metrics: ")
@with_instrumentation()
async def get_metrics(start: datetime | None = None,
                      end: datetime | None = None) -> list[SandboxMetrics]

Gets historical time-series resource usage metrics for the Sandbox.

When the deployment runs a dedicated Analytics API, metrics are fetched from it directly; otherwise they are fetched through the control-plane telemetry proxy.

Arguments:

Returns: