Skip to main content

Daytona Python SDK

The official Python SDK for Daytona, a secure and elastic infrastructure for running AI-generated code. Daytona provides full composable computers — sandboxes — that you can manage programmatically using the Daytona SDK.

The SDK provides an interface for sandbox management, file system operations, Git operations, language server protocol support, process and code execution, and computer use. For more information, see the documentation.

Installation

Install the package using pip:

pip install daytona

Get API key

Generate an API key from the Daytona Dashboard ↗ to authenticate SDK requests and access Daytona services. For more information, see the API keys documentation.

Configuration

Configure the SDK using environment variables or by passing a configuration object:

  • DAYTONA_API_KEY: Your Daytona API key
  • DAYTONA_API_URL: The Daytona API URL
  • DAYTONA_TARGET: Your target region environment (e.g. us, eu)
from daytona import Daytona, DaytonaConfig

# Initialize with environment variables
daytona = Daytona()

# Initialize with configuration object
config = DaytonaConfig(
    api_key="YOUR_API_KEY",
    api_url="YOUR_API_URL",
    target="us"
)

Create a sandbox

Create a sandbox to run your code securely in an isolated environment.

from daytona import Daytona, DaytonaConfig

config = DaytonaConfig(api_key="YOUR_API_KEY")
daytona = Daytona(config)
sandbox = daytona.create()
response = sandbox.process.code_run('print("Hello World")')

Examples and guides

Daytona provides examples and guides for common sandbox operations, best practices, and a wide range of topics, from basic usage to advanced topics, showcasing various types of integrations between Daytona and other tools.

Create a sandbox with custom resources

Create a sandbox with custom resources (CPU, memory, disk).

from daytona import Daytona, CreateSandboxFromImageParams, Image, Resources

daytona = Daytona()
sandbox = daytona.create(
    CreateSandboxFromImageParams(
        image=Image.debian_slim("3.12"),
        resources=Resources(cpu=2, memory=4, disk=8)
    )
)

Create an ephemeral sandbox

Create an ephemeral sandbox that is automatically deleted when stopped.

from daytona import Daytona, CreateSandboxFromSnapshotParams

daytona = Daytona()
sandbox = daytona.create(
    CreateSandboxFromSnapshotParams(ephemeral=True, auto_stop_interval=5)
)

Create a sandbox from a snapshot

Create a sandbox from a snapshot.

from daytona import Daytona, CreateSandboxFromSnapshotParams

daytona = Daytona()
sandbox = daytona.create(
    CreateSandboxFromSnapshotParams(
        snapshot="my-snapshot-name",
        language="python"
    )
)

Execute Commands

Execute commands in the sandbox.

# Execute a shell command
response = sandbox.process.exec('echo "Hello, World!"')
print(response.result)

# Run Python code
response = sandbox.process.code_run('''
x = 10
y = 20
print(f"Sum: {x + y}")
''')
print(response.result)

File Operations

Upload, download, and search files in the sandbox.

# Upload a file
sandbox.fs.upload_file(b'Hello, World!', 'path/to/file.txt')

# Download a file
content = sandbox.fs.download_file('path/to/file.txt')

# Search for files
matches = sandbox.fs.find_files(root_dir, 'search_pattern')

Git Operations

Clone, list branches, and add files to the sandbox.

# Clone a repository
sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')

# List branches
branches = sandbox.git.branches('path/to/repo')

# Add files
sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])

Language Server Protocol

Create and start a language server to get code completions, document symbols, and more.

# Create and start a language server
lsp = sandbox.create_lsp_server('python', 'path/to/project')
lsp.start()

# Notify the lsp for the file
lsp.did_open('path/to/file.py')

# Get document symbols
symbols = lsp.document_symbols('path/to/file.py')

# Get completions
completions = lsp.completions('path/to/file.py', {"line": 10, "character": 15})

Code in _sync directory shouldn't be edited directly. It should be generated from the corresponding async code in the _async directory using the SDK generation scripts in the scripts directory.

List method return shapes

Each list method returns a different shape depending on the resource. The table below shows the exact return type and how to access the elements.

Method Return type (sync) Return type (async) Shape Access elements
daytona.snapshot.list(page?, limit?) PaginatedSnapshots PaginatedSnapshots Paginated wrapper result.items
daytona.secret.list(cursor?, limit?, ...) ListSecretsResponse ListSecretsResponse Cursor-paginated wrapper page.items
daytona.volume.list() list[Volume] list[Volume] Bare list iterate directly
daytona.list(query?) Iterator[Sandbox] AsyncIterator[Sandbox] Lazy iterator for sandbox in daytona.list()

PaginatedSnapshots and ListSecretsResponse are wrapper objects, not lists. Calling list methods like .append() directly on them raises AttributeError. Always go through .items:

# snapshots — page-number pagination
result = daytona.snapshot.list(page=1, limit=20)
# result.items       → list[Snapshot]
# result.total       → int (total across all pages)
# result.page        → int (current page, 1-indexed)
# result.total_pages → int
for snapshot in result.items:
    print(snapshot.name)

# secrets — cursor pagination
cursor = None
while True:
    page = daytona.secret.list(cursor=cursor, limit=50)
    # page.items       → list[Secret]
    # page.total       → int
    # page.next_cursor → str | None (None = no more pages)
    for secret in page.items:
        print(secret.name)
    if page.next_cursor is None:
        break
    cursor = page.next_cursor

# volumes — bare list, iterate directly
volumes = daytona.volume.list()
for vol in volumes:
    print(vol.name)

# sandboxes — lazy iterator, fetches pages on demand
from daytona import ListSandboxesQuery

for sandbox in daytona.list(ListSandboxesQuery(labels={"env": "dev"})):
    print(sandbox.id)

The async client (AsyncDaytona) uses the same field names. Replace for sandbox in with async for sandbox in for the sandbox iterator.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

daytona-0.207.0.tar.gz (188.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

daytona-0.207.0-py3-none-any.whl (226.0 kB view details)

Uploaded Python 3

File details

Details for the file daytona-0.207.0.tar.gz.

File metadata

  • Download URL: daytona-0.207.0.tar.gz
  • Upload date:
  • Size: 188.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.12 Linux/6.6.141

File hashes

Hashes for daytona-0.207.0.tar.gz
Algorithm Hash digest
SHA256 70ba628c3b1a148216f467adb2f5c6949c2444a71a3b5ac45f9c61ad55d37a56
MD5 82dc23a4bcb242f28f5d85ae81519e1f
BLAKE2b-256 9af2f86e6fa2eb36474a924d9fdbe02862a8eeb789d0a859ef710fc7ec3acdb5

See more details on using hashes here.

File details

Details for the file daytona-0.207.0-py3-none-any.whl.

File metadata

  • Download URL: daytona-0.207.0-py3-none-any.whl
  • Upload date:
  • Size: 226.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.2 CPython/3.12.12 Linux/6.6.141

File hashes

Hashes for daytona-0.207.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a5dc672232fb6b1d74a39f1f5719a8fefc39bd153c11ebde2d7730db8c2a1cdf
MD5 d1417791baee24286088cea4232a187b
BLAKE2b-256 0948e9be7e06518e7dd2a93b42773b71c9e367021b62467801e109c2960c5d74

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.1

2 files

This release

0.207.0 This release

2 files

0.205.1

2 files

0.205.0

2 files

0.204.0

2 files

0.203.0

2 files

0.202.0

2 files

0.201.0

2 files

0.200.2

2 files

0.200.1

2 files

0.200.0

2 files

0.199.0

2 files

0.198.0

2 files

0.197.0

2 files

0.196.0

2 files

0.195.0

2 files

0.194.0

2 files

0.193.0

2 files

0.192.0

2 files

0.191.0

2 files

0.190.1

2 files

0.190.0

2 files

0.189.0

2 files

0.187.0

2 files

0.186.0

2 files

0.185.0

2 files

0.184.0

2 files

0.183.0

2 files

0.182.0

2 files

0.181.0

2 files

0.180.0

2 files

0.179.0

2 files

0.178.0

2 files

0.176.0

2 files

0.175.0

2 files

0.173.0

2 files

0.172.0

2 files

0.171.0

2 files

0.170.0

2 files

0.169.0

2 files

0.168.0

2 files

0.167.0

2 files

0.166.0

2 files

0.165.0

2 files

0.164.0

2 files

0.163.0

2 files

0.162.0

2 files

0.161.0

2 files

0.160.0

2 files

0.159.0

2 files

0.158.1

2 files

0.158.0

2 files

0.157.0

2 files

0.155.0

2 files

0.154.0

2 files

0.153.0

2 files

0.152.1

2 files

0.152.0

2 files

0.151.0

2 files

0.150.0

2 files

0.149.0

2 files

0.148.0

2 files

0.147.0

2 files

0.146.0

2 files

0.145.0

2 files

0.144.0

2 files

0.143.0

2 files

0.142.0

2 files

0.141.0

2 files

0.140.0

2 files

0.139.0

2 files

0.138.0

2 files

0.136.0

2 files

0.135.0

2 files

0.134.0

2 files

0.133.0

2 files

0.132.0

2 files

0.130.0

2 files

0.129.0

2 files

0.128.1

2 files

0.128.0

2 files

0.127.0

2 files

0.125.0

2 files

0.124.0

2 files

0.123.0

2 files

0.122.0

2 files

0.121.0

2 files

0.120.0

2 files

0.119.0

2 files

0.118.0

2 files

0.117.0

2 files

0.116.0

2 files

0.115.2

2 files

0.115.1

2 files

0.115.0

2 files

0.114.0

2 files

0.113.2

2 files

0.113.1

2 files

0.113.0

2 files

0.112.3

2 files

0.112.2

2 files

0.112.1

2 files

0.112.0

2 files

0.111.1

2 files

0.111.0

2 files

0.110.2

2 files

0.110.1

2 files

0.110.0

2 files

0.109.0

2 files

0.108.1

2 files

0.108.0

2 files

0.107.1

2 files

0.106.5

2 files

0.106.4

2 files

0.106.1

2 files

0.105.1

2 files

0.105.0

2 files

0.103.0

2 files

0.102.0

2 files

0.27.1

2 files

0.27.0

2 files

0.26.0

2 files

0.25.6

2 files

0.25.5

2 files

0.25.4

2 files

0.25.3

2 files

0.25.1

2 files

0.25.0

2 files

0.24.5

2 files

0.24.4

2 files

0.24.2

2 files

0.24.1

2 files

0.24.0

2 files

0.23.0

2 files

0.22.1

2 files

0.22.0

2 files

0.21.8

2 files

0.21.7

2 files

0.21.6

2 files

0.21.5

2 files

0.21.4

2 files

0.21.3

2 files

0.21.2

2 files

0.21.1

2 files

0.21.0

2 files

0.20.2

2 files

0.20.0

2 files

0.19.0

2 files

0.18.2

2 files

0.18.1

2 files

0.18.0

2 files

0.17.0

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page