Skip to content

Sandbox Management

Sandboxes are isolated development environments managed by Daytona. This guide covers how to create, manage, and remove Sandboxes using the SDK.

Examples

// Initialize using environment variables (DAYTONA_API_KEY, DAYTONA_SERVER_URL, DAYTONA_TARGET)
const daytona = new Daytona();
// Create and use a workspace
const workspace = await daytona.create({
language: 'typescript',
envVars: { NODE_ENV: 'development' }
});
// Execute commands in the workspace
const response = await workspace.process.executeCommand('echo "Hello, World!"');
console.log(response.result);
// Execute code in the workspace
const response = await workspace.process.codeRun('console.log("Hello, World!")');
console.log(response.result);
// Initialize with explicit configuration
const daytona = new Daytona({
apiKey: process.env.CUSTOM_API_KEY,
serverUrl: 'https://daytona.example.com',
target: 'us'
});
// Create a custom workspace
const workspace = await daytona.create({
language: 'typescript',
image: 'node:18',
resources: {
cpu: 2,
memory: 4 // 4GB RAM
},
autoStopInterval: 60 // Auto-stop after 1 hour of inactivity
});
// Use workspace features
await workspace.git.clone('https://github.com/user/repo.git');
await workspace.process.executeCommand('npm test');

Daytona

[view_source]

Main class for interacting with Daytona Server 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_SERVER_URL, DAYTONA_TARGET
const daytona = new Daytona();
const workspace = await daytona.create();
// Using explicit configuration
const config: DaytonaConfig = {
apiKey: "your-api-key",
serverUrl: "https://your-server.com",
target: "us"
};
const daytona = new Daytona(config);
@class

Constructors

new Daytona()

new Daytona(config?: DaytonaConfig): Daytona

[view_source]

Creates a new Daytona client instance.

Parameters
ParameterTypeDescription
config?DaytonaConfigConfiguration options
Returns

Daytona

Throws
  • Error - When API key or server URL is missing

Methods

create()

create(params?: CreateWorkspaceParams): Promise<Workspace>

[view_source]

Creates Sandboxes with default or custom configurations. You can specify various parameters, including language, image, resources, environment variables, and volumes for the Sandbox.

Parameters
ParameterTypeDescription
params?CreateWorkspaceParamsParameters for Sandbox creation
Returns

Promise<Workspace>

The created Sandbox instance

Examples
// Create a default workspace
const workspace = await daytona.create();
// Create a custom workspace
const params: CreateWorkspaceParams = {
language: 'typescript',
image: 'node:18',
envVars: {
NODE_ENV: 'development',
DEBUG: 'true'
},
resources: {
cpu: 2,
memory: 4 // 4GB RAM
},
timeout: 300,
autoStopInterval: 60
};
const workspace = await daytona.create(params);

get()

get(workspaceId: string): Promise<Workspace>

[view_source]

Gets a Sandbox by its ID.

Parameters
ParameterTypeDescription
workspaceIdstringThe ID of the Sandbox to retrieve
Returns

Promise<Workspace>

The Sandbox

Example
const workspace = await daytona.get('my-workspace-id');
console.log(`Workspace state: ${workspace.instance.state}`);

getCurrentWorkspace()

getCurrentWorkspace(workspaceId: string): Promise<Workspace>

[view_source]

Gets the Sandbox by ID.

Parameters
ParameterTypeDescription
workspaceIdstringThe ID of the Sandbox to retrieve
Returns

Promise<Workspace>

The Sandbox

Example
const workspace = await daytona.getCurrentWorkspace('my-workspace-id');
console.log(`Current workspace state: ${workspace.instance.state}`);

list()

list(): Promise<Workspace[]>

[view_source]

Lists all Sandboxes.

Returns

Promise<Workspace[]>

Array of Sandboxes

Example
const workspaces = await daytona.list();
for (const workspace of workspaces) {
console.log(`${workspace.id}: ${workspace.instance.state}`);
}

remove()

remove(workspace: Workspace): Promise<void>

[view_source]

Removes a Sandbox.

Parameters
ParameterTypeDescription
workspaceWorkspaceThe Sandbox to remove
Returns

Promise<void>

Example
const workspace = await daytona.get('my-workspace-id');
await daytona.remove(workspace);

start()

start(workspace: Workspace, timeout?: number): Promise<void>

[view_source]

Starts a Sandbox and waits for it to be ready.

Parameters
ParameterTypeDescription
workspaceWorkspaceThe Sandbox to start
timeout?numberOptional timeout in seconds (0 means no timeout)
Returns

Promise<void>

Example
const workspace = await daytona.get('my-workspace-id');
// Wait up to 60 seconds for the workspace to start
await daytona.start(workspace, 60);

stop()

stop(workspace: Workspace): Promise<void>

[view_source]

Stops a Sandbox.

Parameters
ParameterTypeDescription
workspaceWorkspaceThe Sandbox to stop
Returns

Promise<void>

Example
const workspace = await daytona.get('my-workspace-id');
await daytona.stop(workspace);

CreateWorkspaceParams

[view_source]

Parameters for creating a new Sandbox.

Example

const params: CreateWorkspaceParams = {
language: 'typescript',
envVars: { NODE_ENV: 'development' },
resources: {
cpu: 2,
memory: 4 // 4GB RAM
},
timeout: 300,
autoStopInterval: 60 // Auto-stop after 1 hour of inactivity
};
const workspace = await daytona.create(params);

Properties

PropertyTypeDescription
async?booleanIf true, will not wait for the Sandbox to be ready before returning
autoStopInterval?numberAuto-stop interval in minutes (0 means disabled)
envVars?Record<string, string>Optional environment variables to set in the Sandbox
id?stringOptional Sandbox ID. If not provided, a random ID will be generated
image?stringOptional Docker image to use for the Sandbox
labels?Record<string, string>Sandbox labels
language?CodeLanguageProgramming language for direct code execution
public?booleanIs the Sandbox port preview public
resources?WorkspaceResourcesResource allocation for the Sandbox
target?stringTarget location for the Sandbox
timeout?numberTimeout in seconds for the Sandbox to be ready (0 means no timeout)
user?stringOptional os user to use for the Sandbox

DaytonaConfig

[view_source]

Configuration options for initializing the Daytona client.

Example

const config: DaytonaConfig = {
apiKey: "your-api-key",
serverUrl: "https://your-server.com",
target: "local"
};
const daytona = new Daytona(config);

Properties

PropertyTypeDescription
apiKeystringAPI key for authentication with Daytona server
serverUrlstringURL of the Daytona server
targetCreateWorkspaceTargetEnumTarget location for Sandboxes

WorkspaceResources

[view_source]

Resource allocation for a Sandbox.

Example

const resources: WorkspaceResources = {
cpu: 2,
memory: 4, // 4GB RAM
disk: 20 // 20GB disk
};

Properties

PropertyTypeDescription
cpu?numberCPU allocation for the Sandbox in cores
disk?numberDisk space allocation for the Sandbox in GB
gpu?numberGPU allocation for the Sandbox in units
memory?numberMemory allocation for the Sandbox in GB

CodeLanguage

type CodeLanguage = "python" | "javascript" | "typescript";

[view_source]

Supported programming languages for code execution.