{"id":7142,"library":"daytona-sdk","title":"Daytona SDK","description":"The Daytona Python SDK is the official Python library for Daytona, an open-source, secure, and elastic infrastructure for running AI-generated code. It provides interfaces for managing sandboxes (isolated execution environments), file system operations, Git operations, language server protocol support, and process and code execution. The library is actively maintained and currently at version 0.166.0, with regular updates. [1, 13]","status":"active","version":"0.166.0","language":"en","source_language":"en","source_url":"https://github.com/daytonaio/sdk","tags":["AI","developer tools","sandbox","execution environment","cloud","sdk","agent development","code execution"],"install":[{"cmd":"pip install daytona-sdk","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"Main client for interacting with the Daytona API.","symbol":"Daytona","correct":"from daytona import Daytona"},{"note":"Used to configure the Daytona client, e.g., API key, API URL, target region.","symbol":"DaytonaConfig","correct":"from daytona import DaytonaConfig"},{"note":"Used for creating sandboxes from existing snapshots, which is the recommended approach since v0.21.0. [2, 5]","symbol":"CreateSandboxFromSnapshotParams","correct":"from daytona import CreateSandboxFromSnapshotParams"},{"note":"Asynchronous client for non-blocking operations. [12]","symbol":"AsyncDaytona","correct":"from daytona import AsyncDaytona"}],"quickstart":{"code":"import os\nfrom daytona import Daytona, DaytonaConfig\n\n# Configure with API key from environment variable (recommended) or direct string\napi_key = os.environ.get(\"DAYTONA_API_KEY\", \"\") # Replace with your actual key or ensure env var is set\n\nif not api_key:\n    print(\"Warning: DAYTONA_API_KEY not found in environment variables. Please set it or pass it directly.\")\n    # For demonstration purposes, you might uncomment and replace:\n    # api_key = \"YOUR_API_KEY_HERE\"\n    # if api_key == \"YOUR_API_KEY_HERE\":\n    #     raise ValueError(\"Please provide a valid Daytona API key.\")\n\nconfig = DaytonaConfig(api_key=api_key)\ndaytona = Daytona(config)\n\ntry:\n    # Create a sandbox\n    print(\"Creating Daytona sandbox...\")\n    sandbox = daytona.create()\n    print(f\"Created Sandbox ID: {sandbox.id}\")\n\n    # Run code securely inside the Sandbox\n    print(\"Running code in sandbox...\")\n    response = sandbox.process.code_run('print(\"Hello World from Daytona!\")')\n    print(f\"Code Output: {response.result}\")\n\n    # Optional: Execute a shell command\n    # shell_response = sandbox.process.exec(\"ls -la\")\n    # print(f\"Shell Command Output:\\n{shell_response.result}\")\n\nfinally:\n    # Clean up the sandbox (important to release resources)\n    if 'sandbox' in locals() and sandbox:\n        print(f\"Deleting Sandbox ID: {sandbox.id}...\")\n        sandbox.delete()\n        print(\"Sandbox deleted.\")\n","lang":"python","description":"This quickstart demonstrates how to initialize the Daytona SDK, create an isolated sandbox environment, execute Python code within it, and then clean up the sandbox. Ensure your `DAYTONA_API_KEY` is set as an environment variable or passed directly to `DaytonaConfig`. [3, 6, 13]"},"warnings":[{"fix":"Upgrade to v0.21.0+ and update sandbox creation calls to use `CreateSandboxFromSnapshotParams` for declarative provisioning, and configure resources via snapshots. Consult the official migration guide for details. [2]","message":"Major breaking changes were introduced in Daytona SDK v0.21.0, shifting from a 'declarative image builder' to a 'snapshot-based workflow'. This affects how sandboxes are created and how resources are managed. [2, 19]","severity":"breaking","affected_versions":"<0.21.0"},{"fix":"When creating sandboxes, ensure resources are specified within the `CreateSandboxFromSnapshotParams` or other snapshot-related configurations. Direct `SandboxResources` configuration is deprecated. [2]","message":"Resource configuration for sandboxes is now tied to the snapshot rather than being directly configurable on the sandbox object during creation in the new workflow (v0.21.0+). [19]","severity":"breaking","affected_versions":"<0.21.0"},{"fix":"Use `sandbox.delete()` for cleanup operations. Refer to the updated SDK documentation for current object structures and method calls. [2]","message":"Older sandbox management methods, such as `daytona.remove(sandbox)`, are no longer supported. Sandbox details are also now available as top-level properties on the `Sandbox` object. [2]","severity":"deprecated","affected_versions":"<0.21.0"},{"fix":"Consider upgrading to v0.21.0 or newer to benefit from the Apache 2.0 license, which offers more flexibility for integration. [19]","message":"The SDK license changed from AGPL to Apache 2.0 starting from v0.21.0. While this is generally less restrictive, users on older versions should be aware of the original AGPL license implications if they have not upgraded. [19]","severity":"gotcha","affected_versions":"<0.21.0"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the `DAYTONA_API_KEY` environment variable is correctly set, or pass a valid API key directly to `DaytonaConfig`. Generate a new API key from the Daytona Dashboard if needed. [3, 7]","cause":"The SDK could not authenticate with the Daytona API. This typically means the `DAYTONA_API_KEY` is incorrect, missing, or has expired. [7]","error":"daytona.exceptions.DaytonaAuthenticationException: Invalid or missing API key"},{"fix":"Review the parameters passed to your SDK calls (e.g., `daytona.create()`, `CreateSandboxFromSnapshotParams`) against the official documentation to ensure they are valid and correctly formatted for your SDK version. [7]","cause":"A request made to the Daytona API (e.g., creating a sandbox or snapshot) contained malformed data or invalid parameters, such as an unsupported language or invalid resource specification. [7]","error":"daytona.exceptions.DaytonaBadRequestException: Invalid request parameters"},{"fix":"Verify your internet connection, check the `DAYTONA_API_URL` configuration if explicitly set (default is `https://app.daytona.io/api`), and ensure no firewalls are preventing outbound connections to the Daytona API. [7, 13]","cause":"The SDK failed to establish a network connection with the Daytona API. This could be due to DNS issues, a firewall blocking access, an incorrect API URL, or general network instability. [7]","error":"daytona.exceptions.DaytonaConnectionException: Cannot reach Daytona API: [network error details]"}]}