Skip to content

Sandbox

The Daytona SDK core Sandbox functionality.

Provides the main Workspace class representing a Daytona Sandbox that coordinates file system, Git, process execution, and LSP functionality. It serves as the central point for interacting with Daytona Sandboxes.

The Sandbox must be in a ‘started’ state before performing operations.

Example

// Create and initialize workspace
const daytona = new Daytona();
const workspace = await daytona.create();
// File operations
await workspace.fs.uploadFile(
'/app/config.json',
new File(['{"setting": "value"}'], 'config.json')
);
const contentBlob = await workspace.fs.downloadFile('/app/config.json');
// Git operations
await workspace.git.clone('https://github.com/user/repo.git');
// Process execution
const response = await workspace.process.executeCommand('ls -la');
console.log(response.result);
// LSP functionality
const lsp = workspace.createLspServer('typescript', '/workspace/project');
await lsp.didOpen('/workspace/project/src/index.ts');
const completions = await lsp.completions('/workspace/project/src/index.ts', {
line: 10,
character: 15
});
console.log(completions);

Workspace

[view_source]

Represents a Daytona Sandbox.

A Sandbox provides file system operations, Git operations, process execution, and LSP functionality. It serves as the main interface for interacting with a Daytona workspace.

Constructors

new Workspace()

new Workspace(
id: string,
instance: Workspace,
workspaceApi: WorkspaceApi,
toolboxApi: ToolboxApi,
codeToolbox: WorkspaceCodeToolbox): Workspace

[view_source]

Creates a new Sandbox instance

Parameters
ParameterTypeDescription
idstringUnique identifier for the Sandbox
instanceWorkspaceThe underlying Sandbox instance
workspaceApiWorkspaceApiAPI client for Sandbox operations
toolboxApiToolboxApiAPI client for toolbox operations
codeToolboxWorkspaceCodeToolboxLanguage-specific toolbox implementation
Returns

Workspace

Properties

PropertyModifierTypeDescription
fsreadonlyFileSystemFile system operations interface
gitreadonlyGitGit operations interface
idreadonlystringUnique identifier for the Sandbox
instancereadonlyWorkspaceThe underlying Sandbox instance
processreadonlyProcessProcess execution interface
toolboxApireadonlyToolboxApiAPI client for toolbox operations
workspaceApireadonlyWorkspaceApiAPI client for Sandbox operations

Methods

createLspServer()

createLspServer(languageId: LspLanguageId, pathToProject: string): LspServer

[view_source]

Creates a new Language Server Protocol (LSP) server instance.

The LSP server provides language-specific features like code completion, diagnostics, and more.

Parameters
ParameterTypeDescription
languageIdLspLanguageIdThe language server type (e.g., “typescript”)
pathToProjectstringAbsolute path to the project root directory
Returns

LspServer

A new LSP server instance configured for the specified language

Example
const lsp = workspace.createLspServer('typescript', '/workspace/project');

delete()

delete(): Promise<void>

[view_source]

Deletes the Sandbox.

Returns

Promise<void>


getWorkspaceRootDir()

getWorkspaceRootDir(): Promise<undefined | string>

[view_source]

Gets the root directory path of the Sandbox.

Returns

Promise<undefined | string>

The absolute path to the Sandbox root directory

Example
const rootDir = await workspace.getWorkspaceRootDir();
console.log(`Workspace root: ${rootDir}`);

info()

info(): Promise<WorkspaceInfo>

[view_source]

Gets structured information about the Sandbox.

Returns

Promise<WorkspaceInfo>

Detailed information about the Sandbox including its configuration, resources, and current state

Example
const info = await workspace.info();
console.log(`Workspace ${info.name}:`);
console.log(`State: ${info.state}`);
console.log(`Resources: ${info.resources.cpu} CPU, ${info.resources.memory} RAM`);

setAutostopInterval()

setAutostopInterval(interval: number): Promise<void>

[view_source]

Set the auto-stop interval for the Sandbox.

The Sandbox will automatically stop after being idle (no new events) for the specified interval. Events include any state changes or interactions with the Sandbox through the sdk. Interactions using Sandbox Previews are not included.

Parameters
ParameterTypeDescription
intervalnumberNumber of minutes of inactivity before auto-stopping. Set to 0 to disable auto-stop.
Returns

Promise<void>

Throws
  • Error - If interval is not a non-negative integer
Example
// Auto-stop after 1 hour
await workspace.setAutostopInterval(60);
// Or disable auto-stop
await workspace.setAutostopInterval(0);

setLabels()

setLabels(labels: Record<string, string>): Promise<void>

[view_source]

Sets labels for the Sandbox.

Labels are key-value pairs that can be used to organize and identify Sandboxes.

Parameters
ParameterTypeDescription
labelsRecord<string, string>Dictionary of key-value pairs representing Sandbox labels
Returns

Promise<void>

Example
// Set workspace labels
await workspace.setLabels({
project: 'my-project',
environment: 'development',
team: 'backend'
});

start()

start(timeout?: number): Promise<void>

[view_source]

Start the Sandbox.

This method starts the Sandbox and waits for it to be ready.

Parameters
ParameterTypeDescription
timeout?numberMaximum time to wait in seconds. 0 means no timeout. Defaults to 60-second timeout.
Returns

Promise<void>

Throws
  • Error - If Sandbox fails to start or times out
Example
const workspace = await daytona.getCurrentWorkspace('my-workspace');
await workspace.start(40); // Wait up to 40 seconds
console.log('Workspace started successfully');

stop()

stop(): Promise<void>

[view_source]

Stops the Sandbox.

This method stops the Sandbox and waits for it to be fully stopped.

Returns

Promise<void>

Example
const workspace = await daytona.getCurrentWorkspace('my-workspace');
await workspace.stop();
console.log('Workspace stopped successfully');

waitUntilStarted()

waitUntilStarted(timeout?: number): Promise<void>

[view_source]

Waits for the Sandbox to reach the ‘started’ state.

This method polls the Sandbox status until it reaches the ‘started’ state or encounters an error.

Parameters
ParameterTypeDefault valueDescription
timeout?number60Maximum time to wait in seconds. 0 means no timeout. Defaults to 60 seconds.
Returns

Promise<void>

Throws
  • Error - If timeout is negative

  • Error - If Sandbox fails to start or times out

  • Error - If Sandbox fails to become ready within the timeout period


waitUntilStopped()

waitUntilStopped(): Promise<void>

[view_source]

Wait for Sandbox to reach ‘stopped’ state.

This method polls the Sandbox status until it reaches the ‘stopped’ state or encounters an error. It will wait up to 60 seconds for the Sandbox to stop.

Returns

Promise<void>

Throws
  • Error - If Sandbox fails to stop or times out

WorkspaceCodeToolbox

[view_source]

Interface defining methods that a code toolbox must implement WorkspaceCodeToolbox

Methods

getRunCommand()

getRunCommand(code: string): string

[view_source]

Generates a command to run the provided code

Parameters
ParameterType
codestring
Returns

string


WorkspaceInfo

[view_source]

Structured information about a Sandbox

This interface provides detailed information about a Sandbox’s configuration, resources, and current state.

WorkspaceInfo

Example

const workspace = await daytona.create();
const info = await workspace.info();
console.log(`Workspace ${info.name} is ${info.state}`);
console.log(`Resources: ${info.resources.cpu} CPU, ${info.resources.memory} RAM`);

Properties

PropertyTypeDescription
envRecord<string, string>Environment variables set in the Sandbox
errorReasonnull | stringError message if Sandbox is in error state
idstringUnique identifier for the Sandbox
imagestringDocker image used for the Sandbox
labelsRecord<string, string>Custom labels attached to the Sandbox
namestringDisplay name of the Sandbox
publicbooleanWhether the Sandbox is publicly accessible
resourcesWorkspaceResourcesResource allocations for the Sandbox
snapshotStatenull | stringCurrent state of Sandbox snapshot
snapshotStateCreatedAtnull | DateWhen the snapshot state was created
statestringCurrent state of the Sandbox (e.g., “started”, “stopped”)
targetstringTarget environment where the Sandbox runs
userstringOS user running in the Sandbox

WorkspaceResources

[view_source]

Resources allocated to a Sandbox

WorkspaceResources

Example

const resources: WorkspaceResources = {
cpu: "2",
gpu: "1",
memory: "4Gi",
disk: "20Gi"
};

Properties

PropertyTypeDescription
cpustringNumber of CPU cores allocated (e.g., “1”, “2”)
diskstringAmount of disk space allocated with unit (e.g., “10Gi”, “20Gi”)
gpunull | stringNumber of GPUs allocated (e.g., “1”) or null if no GPU
memorystringAmount of memory allocated with unit (e.g., “2Gi”, “4Gi”)