Skip to content

Authentication

View as Markdown

Daytona authenticates SDK, CLI, and API requests with a project API key. The key identifies the project that owns the sandboxes you create and carries the permissions a request may use.

  1. Go to Daytona Dashboard ↗
  2. Click Create API Key
  3. Enter Key Name
  4. Select write:sandboxes permission
  5. Click Create API Key
  6. Copy and save the API key as an environment variable

Daytona resolves configuration in order of precedence:

  1. Configuration in code
  2. Environment variables
VariableDescription
DAYTONA_API_KEYYour Daytona API key.
Required unless DAYTONA_JWT_TOKEN is set
DAYTONA_JWT_TOKENA JWT instead of an API key.
Optional; needs DAYTONA_PROJECT_ID
DAYTONA_PROJECT_IDThe project a JWT is scoped to.
Required with DAYTONA_JWT_TOKEN
Terminal window
DAYTONA_API_KEY=YOUR_API_KEY
Terminal window
export DAYTONA_API_KEY=YOUR_API_KEY

Construct the client without arguments to read the environment variables, or pass the configuration in code. Every call made through the client sends the API key or, with a JWT, a short-lived project token the client exchanges the JWT for.

from daytona import Daytona, DaytonaConfig
# Using environment variables
daytona = Daytona()
# Using explicit configuration
config = DaytonaConfig(api_key="YOUR_API_KEY")
daytona = Daytona(config)
# Pick the region per create
sandbox = daytona.v2.create(region="us")

Each DaytonaConfig field falls back to its environment variable independently. The client has no API URL or region field: every create takes a region, and the API picks the project, organization, or platform default when it is omitted.

ParameterTypeDescription
api_keystrFalls back to DAYTONA_API_KEY. When neither this nor jwt_token is set, the client constructor raises UnauthorizedError.
jwt_tokenstrA JWT instead of an API key. Falls back to DAYTONA_JWT_TOKEN. Needs project_id; setting both api_key and jwt_token raises BadRequestError.
project_idstrThe project a JWT is scoped to. Falls back to DAYTONA_PROJECT_ID.
request_timeoutfloatPer-request HTTP timeout in seconds. 0 disables the timeout.

Sign in once and the CLI saves the session in its active profile, so following commands need no key or flags. After a browser or device login, the CLI selects your personal organization and its default project the first time and remembers your last selection afterwards; sandbox commands then mint a short-lived project API key on your behalf, which expires with the session.

Terminal window
# Browser login
daytona login --api-url https://api.daytona.com
# Device-code login on a host without a browser
daytona login --device --api-url https://api.daytona.com
# Store an API key in the active profile
daytona login --token YOUR_API_KEY --api-url https://api.daytona.com
# Confirm who you are and what is selected
daytona whoami
# Create a sandbox with the saved session
daytona sandbox create
# Remove the saved session from this machine
daytona logout
Terminal window
# Using environment variables (DAYTONA_API_KEY, DAYTONA_API_URL)
daytona sandbox create
# Using explicit flags
daytona sandbox create --api-key YOUR_API_KEY --api-url https://api.daytona.com
FlagTypeDescription
--api-keystringTakes precedence over DAYTONA_API_KEY. Either one replaces the saved login for that command.
--api-urlstringTakes precedence over DAYTONA_API_URL, and either one overrides the URL stored in the profile.
--profilestringSelects a profile other than the active one. DAYTONA_PROFILE does the same.

Send the API key as a bearer token in the authorization header of every request.

Terminal window
curl 'https://api.daytona.com/sandboxes' \
--request POST \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer YOUR_API_KEY' \
--data '{}'
  • Creating a sandbox needs the write:sandboxes permission.
  • Creating a sandbox also needs the read:secrets permission when the request attaches secrets.