Daytona
Main class for interacting with the Daytona API.
Provides methods for creating, managing, and interacting with Daytona Sandboxes. Can be initialized either with explicit configuration or using environment variables.
Examples:
// Using environment variables// Uses DAYTONA_API_KEY, DAYTONA_API_URL, DAYTONA_TARGETconst daytona = new Daytona();const sandbox = await daytona.create();
// Using explicit configurationconst config: DaytonaConfig = { apiKey: "your-api-key", apiUrl: "https://your-api.com", target: "us"};const daytona = new Daytona(config);
@class
Constructors
new Daytona()
new Daytona(config?: DaytonaConfig): Daytona
Creates a new Daytona client instance.
Parameters:
config?
DaytonaConfig - Configuration options
Returns:
Daytona
Throws:
DaytonaError
- When API key is missing
Methods
create()
create(params?: CreateSandboxParams, timeout?: number): Promise<Sandbox>
Creates Sandboxes with default or custom configurations. You can specify various parameters, including language, image, resources, environment variables, and volumes for the Sandbox.
Parameters:
params?
CreateSandboxParams - Parameters for Sandbox creationtimeout?
number = 60 - Timeout in seconds (0 means no timeout, default is 60)
Returns:
Promise<Sandbox>
- The created Sandbox instance
Examples:
// Create a default sandboxconst sandbox = await daytona.create();
// Create a custom sandboxconst params: CreateSandboxParams = { language: 'typescript', image: 'node:18', envVars: { NODE_ENV: 'development', DEBUG: 'true' }, resources: { cpu: 2, memory: 4 // 4GB RAM }, autoStopInterval: 60};const sandbox = await daytona.create(params, 40);
get()
get(sandboxId: string): Promise<Sandbox>
Gets a Sandbox by its ID.
Parameters:
sandboxId
string - The ID of the Sandbox to retrieve
Returns:
Promise<Sandbox>
- The Sandbox
Example:
const sandbox = await daytona.get('my-sandbox-id');console.log(`Sandbox state: ${sandbox.instance.state}`);
getCurrentSandbox()
getCurrentSandbox(sandboxId: string): Promise<Sandbox>
Gets the Sandbox by ID.
Parameters:
sandboxId
string - The ID of the Sandbox to retrieve
Returns:
Promise<Sandbox>
- The Sandbox
Example:
const sandbox = await daytona.getCurrentSandbox('my-sandbox-id');console.log(`Current sandbox state: ${sandbox.instance.state}`);
getCurrentWorkspace()
getCurrentWorkspace(workspaceId: string): Promise<Sandbox>
Gets the Sandbox by ID.
Parameters:
workspaceId
string - The ID of the Sandbox to retrieve
Returns:
Promise<Sandbox>
- The Sandbox
Deprecated
Use getCurrentSandbox
instead. This method will be removed in a future version.
list()
list(): Promise<Sandbox[]>
Lists all Sandboxes.
Returns:
Promise<Sandbox[]>
- Array of Sandboxes
Example:
const sandboxes = await daytona.list();for (const sandbox of sandboxes) { console.log(`${sandbox.id}: ${sandbox.instance.state}`);}
remove()
remove(sandbox: Sandbox, timeout: number): Promise<void>
Removes a Sandbox.
Parameters:
sandbox
Sandbox - The Sandbox to removetimeout
number = 60 - Timeout in seconds (0 means no timeout, default is 60)
Returns:
Promise<void>
Example:
const sandbox = await daytona.get('my-sandbox-id');await daytona.remove(sandbox);
start()
start(sandbox: Sandbox, timeout?: number): Promise<void>
Starts a Sandbox and waits for it to be ready.
Parameters:
sandbox
Sandbox - The Sandbox to starttimeout?
number - Optional timeout in seconds (0 means no timeout)
Returns:
Promise<void>
Example:
const sandbox = await daytona.get('my-sandbox-id');// Wait up to 60 seconds for the sandbox to startawait daytona.start(sandbox, 60);
stop()
stop(sandbox: Sandbox): Promise<void>
Stops a Sandbox.
Parameters:
sandbox
Sandbox - The Sandbox to stop
Returns:
Promise<void>
Example:
const sandbox = await daytona.get('my-sandbox-id');await daytona.stop(sandbox);
CodeLanguage
Supported programming languages for code execution
Enum Members:
JAVASCRIPT
(“javascript”)PYTHON
(“python”)TYPESCRIPT
(“typescript”)
CreateSandboxParams
Parameters for creating a new Sandbox.
Properties:
async?
boolean - If true, will not wait for the Sandbox to be ready before returningautoStopInterval?
number - Auto-stop interval in minutes (0 means disabled)envVars?
Record<string, string> - Optional environment variables to set in the Sandboxid?
string - Optional Sandbox ID. If not provided, a random ID will be generatedimage?
string - Optional Docker image to use for the Sandboxlabels?
Record<string, string> - Sandbox labelslanguage?
string - Programming language for direct code executionpublic?
boolean - Is the Sandbox port preview publicresources?
SandboxResources - Resource allocation for the Sandboxtarget?
string - Target location for the Sandboxtimeout?
number - Timeout in seconds for the Sandbox to be ready (0 means no timeout)user?
string - Optional os user to use for the Sandbox
Example:
const params: CreateSandboxParams = { language: 'typescript', envVars: { NODE_ENV: 'development' }, resources: { cpu: 2, memory: 4 // 4GB RAM }, autoStopInterval: 60 // Auto-stop after 1 hour of inactivity};const sandbox = await daytona.create(params, 50);
DaytonaConfig
Configuration options for initializing the Daytona client.
Properties:
apiKey?
string - API key for authentication with the Daytona APIapiUrl?
string - URL of the Daytona API. Defaults to ‘https://app.daytona.io/api’ if not set here and not set in environment variable DAYTONA_API_URL.jwtToken?
string - JWT token for authentication with the Daytona API. If not set, it must be provided via the environment variableDAYTONA_JWT_TOKEN
, or an API key must be provided instead.organizationId?
string - Organization ID used for JWT-based authentication. Required if a JWT token is provided, and must be set either here or in the environment variableDAYTONA_ORGANIZATION_ID
.string - Deprecated - UseserverUrl?
apiUrl
instead. This property will be removed in future versions.target?
CreateWorkspaceTargetEnum - Target location for Sandboxes
Example:
const config: DaytonaConfig = { apiKey: "your-api-key", apiUrl: "https://your-api.com", target: "us"};const daytona = new Daytona(config);
SandboxResources
Resource allocation for a Sandbox.
Properties:
cpu?
number - CPU allocation for the Sandbox in coresdisk?
number - Disk space allocation for the Sandbox in GBgpu?
number - GPU allocation for the Sandbox in unitsmemory?
number - Memory allocation for the Sandbox in GB
Example:
const resources: SandboxResources = { cpu: 2, memory: 4, // 4GB RAM disk: 20 // 20GB disk};