Daytona API Client (Async)
The `daytona-api-client-async` library provides an asynchronous Python client for interacting with the Daytona platform. Daytona offers a secure and elastic infrastructure for running AI-generated code within isolated development environments called sandboxes. This client enables programmatic management of these sandboxes, including creation, code execution, and lifecycle operations. The library is part of the larger Daytona SDK ecosystem, which receives frequent updates, often multiple times a week.
Warnings
- breaking Major breaking changes were introduced in v0.21.0 (released January 15, 2026). This update refactored the architecture around 'snapshots' instead of legacy pre-built images. Key changes include new parameter types for sandbox creation, a new `SnapshotService`, removal of deprecated Sandbox methods, and flattening of Sandbox instance information. Users on `v0.20.2` or earlier must update their integration.
- gotcha The PyPI package `daytona-api-client-async` is a low-level API client. However, the high-level Python SDK, which includes asynchronous capabilities, is typically installed via `pip install daytona` and its main classes (`AsyncDaytona`, `DaytonaConfig`) are imported from the `daytona` namespace. Direct installation of `daytona-api-client-async` may lead to incorrect import attempts like `from daytona_api_client_async import AsyncDaytona`.
- gotcha The client requires an API key for authentication. If `DAYTONA_API_KEY` is not provided either via an environment variable or explicitly through `DaytonaConfig`, the SDK will raise a `DaytonaError`.
- deprecated The `server_url` parameter within `DaytonaConfig` is deprecated and will be removed in a future version.
Install
-
pip install daytona-api-client-async
Imports
- AsyncDaytona
from daytona import AsyncDaytona
- DaytonaConfig
from daytona import DaytonaConfig
Quickstart
import asyncio
import os
from daytona import AsyncDaytona, DaytonaConfig
async def main():
# API key can also be set via DAYTONA_API_KEY environment variable
# For this example, we fetch it from env or use a placeholder if not set.
api_key = os.environ.get('DAYTONA_API_KEY', 'YOUR_API_KEY_HERE')
if api_key == 'YOUR_API_KEY_HERE':
print("WARNING: DAYTONA_API_KEY environment variable not set. Using placeholder.")
config = DaytonaConfig(api_key=api_key)
try:
async with AsyncDaytona(config) as daytona:
# Create a new sandbox
print("Creating a new Daytona sandbox...")
sandbox = await daytona.create()
print(f"Sandbox '{sandbox.name}' created with ID: {sandbox.id}")
# Execute a command in the sandbox
command = "echo 'Hello from Daytona Sandbox!'"
print(f"Executing command: '{command}'...")
response = await sandbox.process.exec(command)
print("Command output:")
print(response.result)
# Clean up: delete the sandbox
print(f"Deleting sandbox '{sandbox.name}'...")
await daytona.delete(sandbox.id)
print(f"Sandbox '{sandbox.name}' deleted.")
except Exception as e:
print(f"An error occurred: {e}")
if __name__ == "__main__":
asyncio.run(main())