Skip to main content
The Daytona SDK uses API keys to authenticate requests. You can generate and manage your API keys from the Daytona dashboard.

Getting your API key

1

Sign up or log in

Go to app.daytona.io and create an account or log in
2

Navigate to API keys

Click on your profile and go to Dashboard > API Keys
3

Generate a new key

Click “Generate New API Key” and give it a descriptive name
4

Copy and store securely

Copy the API key immediately - you won’t be able to see it again
Never commit your API key to version control or share it publicly. Treat it like a password.

Configuration methods

There are two main ways to configure the SDK with your API key: The simplest and most secure method is to use environment variables:
export DAYTONA_API_KEY="your-api-key-here"
Then initialize the SDK without explicitly passing the key:
from daytona import Daytona

# Automatically uses DAYTONA_API_KEY from environment
daytona = Daytona()

Configuration object

You can also pass the API key directly in your code:
from daytona import Daytona, DaytonaConfig

config = DaytonaConfig(
    api_key="your-api-key",
    api_url="https://app.daytona.io/api",  # Optional
    target="us"  # Optional
)
daytona = Daytona(config)
When passing the API key directly in code, make sure to:
  • Never commit it to version control
  • Use environment variables or a secrets manager
  • Keep your API key in a .env file that’s in .gitignore

Environment variables reference

VariableDescriptionRequiredDefault
DAYTONA_API_KEYYour Daytona API keyYes-
DAYTONA_API_URLThe Daytona API endpointNohttps://app.daytona.io/api
DAYTONA_TARGETTarget region for sandboxesNous

Using .env files

For local development, you can use a .env file to store your API key:
1

Create a .env file

Create a file named .env in your project root:
DAYTONA_API_KEY=your-api-key-here
DAYTONA_TARGET=us
2

Add to .gitignore

Make sure .env is in your .gitignore:
echo ".env" >> .gitignore
3

Load environment variables

Use a library to load the .env file:
pip install python-dotenv
from dotenv import load_dotenv
from daytona import Daytona

load_dotenv()
daytona = Daytona()

Production best practices

For production deployments:
Always use environment variables or a secrets manager (AWS Secrets Manager, HashiCorp Vault, etc.) instead of hardcoding API keys.
Generate new API keys periodically and revoke old ones:
  1. Generate a new key in the dashboard
  2. Update your production environment
  3. Revoke the old key after confirming the new one works
Create different API keys for development, staging, and production:
# Development
DAYTONA_API_KEY=dev_key_here

# Staging
DAYTONA_API_KEY=staging_key_here

# Production
DAYTONA_API_KEY=prod_key_here
Regularly check your API key usage in the Daytona dashboard to detect:
  • Unusual activity patterns
  • Compromised keys
  • Rate limit issues

Verifying authentication

To verify your API key is working correctly:
from daytona import Daytona

try:
    daytona = Daytona()
    sandboxes = daytona.list()
    print(f"✓ Authentication successful! You have {sandboxes.total} sandboxes.")
except Exception as e:
    print(f"✗ Authentication failed: {e}")

Troubleshooting

This means your API key is invalid or missing. Check that:
  • The API key is correctly copied from the dashboard
  • The environment variable is properly set
  • The API key hasn’t been revoked
Try regenerating a new API key if the issue persists.
Make sure you’ve exported the variable in your current shell:
echo $DAYTONA_API_KEY
If empty, export it again or add it to your shell profile (~/.bashrc, ~/.zshrc, etc.).
If you’re getting connection errors:
  • Verify your internet connection
  • Check if you’re behind a proxy or firewall
  • Ensure DAYTONA_API_URL is set correctly if using a custom endpoint

Next steps

Quickstart

Create your first sandbox in under 5 minutes

SDK guides

Learn about SDK configuration options for all languages

Build docs developers (and LLMs) love