Daytona
Section titled “Daytona”class Daytona()Main class for interacting with the Daytona API.
This class provides methods to create, manage, and interact with Daytona Sandboxes. It can be initialized either with explicit configuration or using environment variables.
Attributes:
volumeVolumeService - Service for managing volumes.snapshotSnapshotService - Service for managing snapshots.
Example:
Using environment variables:
daytona = Daytona() # Uses DAYTONA_API_KEY, DAYTONA_API_URLsandbox = daytona.create()Using explicit configuration:
config = DaytonaConfig( api_key="your-api-key", api_url="https://your-api.com", target="us")daytona = Daytona(config)sandbox = daytona.create()Using OpenTelemetry tracing:
config = DaytonaConfig( api_key="your-api-key", experimental={"otelEnabled": True} # Enable OpenTelemetry tracing through experimental config)async with Daytona(config) as daytona: sandbox = daytona.create() # All SDK operations will be traced# OpenTelemetry traces are flushed on closeDaytona.__init__
Section titled “Daytona.__init__”def __init__(config: DaytonaConfig | None = None)Initializes Daytona instance with optional configuration.
If no config is provided, reads from environment variables:
DAYTONA_API_KEY: Required API key for authenticationDAYTONA_API_URL: Required api URLDAYTONA_TARGET: Optional target environment (if not provided, default region for the organization is used)
Arguments:
configDaytonaConfig | None - Object containing api_key, api_url, and target.
Raises:
DaytonaError- If API key is not provided either through config or environment variables
Example:
from daytona import Daytona, DaytonaConfig# Using environment variablesdaytona1 = Daytona()
# Using explicit configurationconfig = DaytonaConfig( api_key="your-api-key", api_url="https://your-api.com", target="us")daytona2 = Daytona(config)Daytona.create
Section titled “Daytona.create”@overloaddef create(params: CreateSandboxFromSnapshotParams | None = None, *, timeout: float = 60) -> SandboxCreates Sandboxes from specified or default snapshot. You can specify various parameters, including language, image, environment variables, and volumes.
Arguments:
paramsCreateSandboxFromSnapshotParams | None - Parameters for Sandbox creation. If not provided, defaults to default Daytona snapshot and Python language.timeoutfloat - Timeout (in seconds) for sandbox creation. 0 means no timeout. Default is 60 seconds.
Returns:
Sandbox- The created Sandbox instance.
Raises:
DaytonaError- If timeout, auto_stop_interval or auto_archive_interval is negative; If sandbox fails to start or times out
Example:
Create a default Python Sandbox:
sandbox = daytona.create()Create a custom Sandbox:
params = CreateSandboxFromSnapshotParams( language="python", snapshot="my-snapshot-id", env_vars={"DEBUG": "true"}, auto_stop_interval=0, auto_archive_interval=60, auto_delete_interval=120)sandbox = daytona.create(params, timeout=40)Daytona.create
Section titled “Daytona.create”@overloaddef create( params: CreateSandboxFromImageParams | None = None, *, timeout: float = 60, on_snapshot_create_logs: Callable[[str], None] | None = None) -> SandboxCreates Sandboxes from specified image available on some registry or declarative Daytona Image. You can specify various parameters, including resources, language, image, environment variables, and volumes. Daytona creates snapshot from provided image and uses it to create Sandbox.
Arguments:
paramsCreateSandboxFromImageParams | None - Parameters for Sandbox creation from image.timeoutfloat - Timeout (in seconds) for sandbox creation. 0 means no timeout. Default is 60 seconds.on_snapshot_create_logsCallable[[str], None] | None - This callback function handles snapshot creation logs.
Returns:
Sandbox- The created Sandbox instance.
Raises:
DaytonaError- If timeout, auto_stop_interval or auto_archive_interval is negative; If sandbox fails to start or times out
Example:
Create a default Python Sandbox from image:
sandbox = daytona.create(CreateSandboxFromImageParams(image="debian:12.9"))Create a custom Sandbox from declarative Image definition:
declarative_image = ( Image.base("alpine:3.18") .pipInstall(["numpy", "pandas"]) .env({"MY_ENV_VAR": "My Environment Variable"}))params = CreateSandboxFromImageParams( language="python", image=declarative_image, env_vars={"DEBUG": "true"}, resources=Resources(cpu=2, memory=4), auto_stop_interval=0, auto_archive_interval=60, auto_delete_interval=120)sandbox = daytona.create( params, timeout=40, on_snapshot_create_logs=lambda chunk: print(chunk, end=""),)Daytona.delete
Section titled “Daytona.delete”@with_instrumentation()def delete(sandbox: Sandbox, timeout: float = 60) -> NoneDeletes a Sandbox.
Arguments:
sandboxSandbox - The Sandbox instance to delete.timeoutfloat - Timeout (in seconds) for sandbox deletion. 0 means no timeout. Default is 60 seconds.
Raises:
DaytonaError- If sandbox fails to delete or times out
Example:
sandbox = daytona.create()# ... use sandbox ...daytona.delete(sandbox) # Clean up when doneDaytona.get
Section titled “Daytona.get”@intercept_errors(message_prefix="Failed to get sandbox: ")@with_instrumentation()def get(sandbox_id_or_name: str) -> SandboxGets a Sandbox by its ID or name.
Arguments:
sandbox_id_or_namestr - The ID or name of the Sandbox to retrieve.
Returns:
Sandbox- The Sandbox instance.
Raises:
DaytonaError- If sandbox_id_or_name is not provided.
Example:
sandbox = daytona.get("my-sandbox-id-or-name")print(sandbox.state)Daytona.list
Section titled “Daytona.list”@intercept_errors(message_prefix="Failed to list sandboxes: ")@with_instrumentation()def list(query: ListSandboxesQuery | None = None) -> Iterator[Sandbox]Iterates over Sandboxes matching the given query.
Arguments:
query- Optional filters, sorting, and per-page size.
Yields:
Sandbox- Each Sandbox matching the query.
Example:
from daytona import ListSandboxesQuery
for sandbox in daytona.list(ListSandboxesQuery(labels={"env": "dev"})): print(sandbox.id)Daytona.start
Section titled “Daytona.start”@with_instrumentation()def start(sandbox: Sandbox, timeout: float = 60) -> NoneStarts a Sandbox and waits for it to be ready.
Arguments:
sandboxSandbox - The Sandbox to start.timeoutfloat - Optional timeout in seconds to wait for the Sandbox to start. 0 means no timeout. Default is 60 seconds.
Raises:
DaytonaError- If timeout is negative; If Sandbox fails to start or times out
Daytona.stop
Section titled “Daytona.stop”@with_instrumentation()def stop(sandbox: Sandbox, timeout: float = 60) -> NoneStops a Sandbox and waits for it to be stopped.
Arguments:
sandboxSandbox - The sandbox to stoptimeoutfloat - Optional timeout (in seconds) for sandbox stop. 0 means no timeout. Default is 60 seconds.
Raises:
DaytonaError- If timeout is negative; If Sandbox fails to stop or times out
CodeLanguage
Section titled “CodeLanguage”class CodeLanguage(str, Enum)Programming languages supported by Daytona
Enum Members:
PYTHON(“python”)TYPESCRIPT(“typescript”)JAVASCRIPT(“javascript”)
DaytonaConfig
Section titled “DaytonaConfig”class DaytonaConfig(BaseModel)Configuration options for initializing the Daytona client.
Attributes:
api_keystr | None - API key for authentication with the Daytona API. If not set, it must be provided via the environment variableDAYTONA_API_KEY, or a JWT token must be provided instead.jwt_tokenstr | None - JWT token for authentication with the Daytona API. If not set, it must be provided via the environment variableDAYTONA_JWT_TOKEN, or an API key must be provided instead.organization_idstr | None - Organization ID used for JWT-based authentication. Required if a JWT token is provided, and must be set either here or in the environment variableDAYTONA_ORGANIZATION_ID.api_urlstr | None - URL of the Daytona API. Defaults to'https://app.daytona.io/api'if not set here or in the environment variableDAYTONA_API_URL.server_urlstr | None - Deprecated. Useapi_urlinstead. This property will be removed in a future version.targetstr | None - Target runner location for the Sandbox. Default region for the organization is used if not set here or in the environment variableDAYTONA_TARGET.connection_pool_maxsizeint | None - Maximum number of simultaneous HTTP connections the SDK will open. Defaults to 250. Set toNoneto remove the limit, which is recommended when running many concurrent long-lived operations likeprocess.exec.otel_enabledbool | None - Enable OpenTelemetry tracing for SDK operations. Defaults toNone, which falls back to theDAYTONA_OTEL_ENABLEDenvironment variable._experimentaldict[str, any] | None - Configuration for experimental features.
Example:
config = DaytonaConfig(api_key="your-api-key")config = DaytonaConfig(jwt_token="your-jwt-token", organization_id="your-organization-id")CreateSandboxBaseParams
Section titled “CreateSandboxBaseParams”class CreateSandboxBaseParams(BaseModel)Base parameters for creating a new Sandbox.
Attributes:
namestr | None - Name of the Sandbox.languageCodeLanguage | CodeLanguageLiteral | None - Programming language for the Sandbox. Defaults to “python”.os_userstr | None - OS user for the Sandbox.env_varsdict[str, str] | None - Environment variables to set in the Sandbox.labelsdict[str, str] | None - Custom labels for the Sandbox.publicbool | None - Whether the Sandbox should be public.timeoutfloat | None - Timeout in seconds for Sandbox to be created and started.auto_stop_intervalint | None - Interval in minutes after which Sandbox will automatically stop if no Sandbox event occurs during that time. Default is 15 minutes. 0 means no auto-stop.auto_archive_intervalint | None - Interval in minutes after which a continuously stopped Sandbox will automatically archive. Default is 7 days. 0 means the maximum interval will be used.auto_delete_intervalint | None - Interval in minutes after which a continuously stopped Sandbox will automatically be deleted. By default, auto-delete is disabled. Negative value means disabled, 0 means delete immediately upon stopping.volumeslist[VolumeMount] | None - List of volumes mounts to attach to the Sandbox.network_block_allbool | None - Whether to block all network access for the Sandbox.network_allow_liststr | None - Comma-separated list of allowed CIDR network addresses for the Sandbox.ephemeralbool | None - Whether the Sandbox should be ephemeral. If True, auto_delete_interval will be set to 0.linked_sandboxstr | None - ID or name of an existing Sandbox to link the new Sandbox to. The new Sandbox will be scheduled on the same runner as the linked Sandbox so a local network can be established between them. Linked Sandboxes must be ephemeral (auto_delete_interval=0) and cannot themselves be linked to another Sandbox.
CreateSandboxFromImageParams
Section titled “CreateSandboxFromImageParams”class CreateSandboxFromImageParams(CreateSandboxBaseParams)Parameters for creating a new Sandbox from an image.
Attributes:
imagestr | Image - Custom Docker image to use for the Sandbox. If an Image object is provided, the image will be dynamically built.resourcesResources | None - Resource configuration for the Sandbox. If not provided, sandbox will have default resources.
CreateSandboxFromSnapshotParams
Section titled “CreateSandboxFromSnapshotParams”class CreateSandboxFromSnapshotParams(CreateSandboxBaseParams)Parameters for creating a new Sandbox from a snapshot.
Attributes:
snapshotstr | None - Name of the snapshot to use for the Sandbox.