Skip to content

Sandbox

Represents a Daytona Sandbox.

Properties:

  • autoArchiveInterval? number - Auto-archive interval in minutes

    Implementation of
    SandboxDto.autoArchiveInterval
  • autoDeleteInterval? number - Auto-delete interval in minutes

    Implementation of
    SandboxDto.autoDeleteInterval
  • autoStopInterval? number - Auto-stop interval in minutes

    Implementation of
    SandboxDto.autoStopInterval
  • backupCreatedAt? string - When the backup was created

    Implementation of
    SandboxDto.backupCreatedAt
  • backupState? SandboxBackupStateEnum - Current state of Sandbox backup

    Implementation of
    SandboxDto.backupState
  • buildInfo? BuildInfo - Build information for the Sandbox if it was created from dynamic build

    Implementation of
    SandboxDto.buildInfo
  • computerUse ComputerUse - Computer use operations interface for desktop automation

  • cpu number - Number of CPUs allocated to the Sandbox

    Implementation of
    SandboxDto.cpu
  • createdAt? string - When the Sandbox was created

    Implementation of
    SandboxDto.createdAt
  • disk number - Amount of disk space allocated to the Sandbox in GiB

    Implementation of
    SandboxDto.disk
  • env Record<string, string> - Environment variables set in the Sandbox

    Implementation of
    SandboxDto.env
  • errorReason? string - Error message if Sandbox is in error state

    Implementation of
    SandboxDto.errorReason
  • fs FileSystem - File system operations interface

  • git Git - Git operations interface

  • gpu number - Number of GPUs allocated to the Sandbox

    Implementation of
    SandboxDto.gpu
  • id string - Unique identifier for the Sandbox

    Implementation of
    SandboxDto.id
  • labels Record<string, string> - Custom labels attached to the Sandbox

    Implementation of
    SandboxDto.labels
  • memory number - Amount of memory allocated to the Sandbox in GiB

    Implementation of
    SandboxDto.memory
  • networkAllowList? string - Comma-separated list of allowed CIDR network addresses for the Sandbox

    Implementation of
    SandboxDto.networkAllowList
  • networkBlockAll boolean - Whether to block all network access for the Sandbox

    Implementation of
    SandboxDto.networkBlockAll
  • organizationId string - Organization ID of the Sandbox

    Implementation of
    SandboxDto.organizationId
  • process Process - Process execution interface

  • public boolean - Whether the Sandbox is publicly accessible

    Implementation of
    SandboxDto.public
  • runnerDomain? string - Domain name of the Sandbox runner

    Implementation of
    SandboxDto.runnerDomain
  • snapshot? string - Daytona snapshot used to create the Sandbox

    Implementation of
    SandboxDto.snapshot
  • state? SandboxState - Current state of the Sandbox (e.g., “started”, “stopped”)

    Implementation of
    SandboxDto.state
  • target string - Target location of the runner where the Sandbox runs

    Implementation of
    SandboxDto.target
  • updatedAt? string - When the Sandbox was last updated

    Implementation of
    SandboxDto.updatedAt
  • user string - OS user running in the Sandbox

    Implementation of
    SandboxDto.user
  • volumes? SandboxVolume[] - Volumes attached to the Sandbox

    Implementation of
    SandboxDto.volumes

Implements

  • Sandbox

Constructors

new Sandbox()

new Sandbox(
sandboxDto: Sandbox,
clientConfig: Configuration,
sandboxApi: SandboxApi,
toolboxApi: ToolboxApi,
codeToolbox: SandboxCodeToolbox): Sandbox

Creates a new Sandbox instance

Parameters:

  • sandboxDto Sandbox - The API Sandbox instance
  • clientConfig Configuration
  • sandboxApi SandboxApi - API client for Sandbox operations
  • toolboxApi ToolboxApi - API client for toolbox operations
  • codeToolbox SandboxCodeToolbox - Language-specific toolbox implementation

Returns:

  • Sandbox

Methods

archive()

archive(): Promise<void>

Archives the sandbox, making it inactive and preserving its state. When sandboxes are archived, the entire filesystem state is moved to cost-effective object storage, making it possible to keep sandboxes available for an extended period. The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size. Sandbox must be stopped before archiving.

Returns:

  • Promise<void>

createLspServer()

createLspServer(languageId: string, pathToProject: string): Promise<LspServer>

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

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

Parameters:

  • languageId string - The language server type (e.g., “typescript”)
  • pathToProject string - Path to the project root directory. Relative paths are resolved based on the user’s root directory.

Returns:

  • Promise<LspServer> - A new LSP server instance configured for the specified language

Example:

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

delete()

delete(timeout: number): Promise<void>

Deletes the Sandbox.

Parameters:

  • timeout number = 60

Returns:

  • Promise<void>

getPreviewLink(port: number): Promise<PortPreviewUrl>

Retrieves the preview link for the sandbox at the specified port. If the port is closed, it will be opened automatically. For private sandboxes, a token is included to grant access to the URL.

Parameters:

  • port number - The port to open the preview link on.

Returns:

  • Promise<PortPreviewUrl> - The response object for the preview link, which includes the url and the token (to access private sandboxes).

Example:

const previewLink = await sandbox.getPreviewLink(3000);
console.log(`Preview URL: ${previewLink.url}`);
console.log(`Token: ${previewLink.token}`);

getUserRootDir()

getUserRootDir(): Promise<string>

Gets the root directory path for the logged in user inside the Sandbox.

Returns:

  • Promise<string> - The absolute path to the Sandbox root directory for the logged in user

Example:

const rootDir = await sandbox.getUserRootDir();
console.log(`Sandbox root: ${rootDir}`);

refreshData()

refreshData(): Promise<void>

Refreshes the Sandbox data from the API.

Returns:

  • Promise<void>

Example:

await sandbox.refreshData();
console.log(`Sandbox ${sandbox.id}:`);
console.log(`State: ${sandbox.state}`);
console.log(`Resources: ${sandbox.cpu} CPU, ${sandbox.memory} GiB RAM`);

setAutoArchiveInterval()

setAutoArchiveInterval(interval: number): Promise<void>

Set the auto-archive interval for the Sandbox.

The Sandbox will automatically archive after being continuously stopped for the specified interval.

Parameters:

  • interval number - Number of minutes after which a continuously stopped Sandbox will be auto-archived. Set to 0 for the maximum interval. Default is 7 days.

Returns:

  • Promise<void>

Throws:

  • DaytonaError - If interval is not a non-negative integer

Example:

// Auto-archive after 1 hour
await sandbox.setAutoArchiveInterval(60);
// Or use the maximum interval
await sandbox.setAutoArchiveInterval(0);

setAutoDeleteInterval()

setAutoDeleteInterval(interval: number): Promise<void>

Set the auto-delete interval for the Sandbox.

The Sandbox will automatically delete after being continuously stopped for the specified interval.

Parameters:

  • interval number - Number of minutes after which a continuously stopped Sandbox will be auto-deleted. Set to negative value to disable auto-delete. Set to 0 to delete immediately upon stopping. By default, auto-delete is disabled.

Returns:

  • Promise<void>

Example:

// Auto-delete after 1 hour
await sandbox.setAutoDeleteInterval(60);
// Or delete immediately upon stopping
await sandbox.setAutoDeleteInterval(0);
// Or disable auto-delete
await sandbox.setAutoDeleteInterval(-1);

setAutostopInterval()

setAutostopInterval(interval: number): Promise<void>

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:

  • interval number - Number of minutes of inactivity before auto-stopping. Set to 0 to disable auto-stop. Default is 15 minutes.

Returns:

  • Promise<void>

Throws:

  • DaytonaError - If interval is not a non-negative integer

Example:

// Auto-stop after 1 hour
await sandbox.setAutostopInterval(60);
// Or disable auto-stop
await sandbox.setAutostopInterval(0);

setLabels()

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

Sets labels for the Sandbox.

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

Parameters:

  • labels Record<string, string> - Dictionary of key-value pairs representing Sandbox labels

Returns:

  • Promise<Record<string, string>>

Example:

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

start()

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

Start the Sandbox.

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

Parameters:

  • timeout? number = 60 - Maximum time to wait in seconds. 0 means no timeout. Defaults to 60-second timeout.

Returns:

  • Promise<void>

Throws:

  • DaytonaError - If Sandbox fails to start or times out

Example:

const sandbox = await daytona.getCurrentSandbox('my-sandbox');
await sandbox.start(40); // Wait up to 40 seconds
console.log('Sandbox started successfully');

stop()

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

Stops the Sandbox.

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

Parameters:

  • timeout? number = 60 - Maximum time to wait in seconds. 0 means no timeout. Defaults to 60-second timeout.

Returns:

  • Promise<void>

Example:

const sandbox = await daytona.getCurrentSandbox('my-sandbox');
await sandbox.stop();
console.log('Sandbox stopped successfully');

waitUntilStarted()

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

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:

  • timeout? number = 60 - Maximum time to wait in seconds. 0 means no timeout. Defaults to 60 seconds.

Returns:

  • Promise<void>

Throws:

  • DaytonaError - If the sandbox ends up in an error state or fails to start within the timeout period.

waitUntilStopped()

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

Wait for Sandbox to reach ‘stopped’ state.

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

Parameters:

  • timeout? number = 60 - Maximum time to wait in seconds. 0 means no timeout. Defaults to 60 seconds.

Returns:

  • Promise<void>

Throws:

  • DaytonaError - If the sandbox fails to stop within the timeout period.

SandboxCodeToolbox

Interface defining methods that a code toolbox must implement

Methods

getRunCommand()

getRunCommand(code: string, params?: CodeRunParams): string

Generates a command to run the provided code

Parameters:

  • code string
  • params? CodeRunParams

Returns:

  • string