Sandbox
Represents a Daytona Sandbox.
Properties:
autoArchiveInterval?
number - Auto-archive interval in minutes
Implementation of
SandboxDto.autoArchiveInterval
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
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 interfacegit
Git - Git operations interfacegpu
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
organizationId
string - Organization ID of the Sandbox
Implementation of
SandboxDto.organizationId
process
Process - Process execution interfacepublic
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, sandboxApi: SandboxApi, toolboxApi: ToolboxApi, codeToolbox: SandboxCodeToolbox): Sandbox
Creates a new Sandbox instance
Parameters:
sandboxDto
Sandbox - The API Sandbox instancesandboxApi
SandboxApi - API client for Sandbox operationstoolboxApi
ToolboxApi - API client for toolbox operationscodeToolbox
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(): Promise<void>
Deletes the Sandbox.
Returns:
Promise<void>
getPreviewLink()
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 theurl
and thetoken
(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<undefined | string>
Gets the root directory path for the logged in user inside the Sandbox.
Returns:
Promise<undefined | 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 hourawait sandbox.setAutoArchiveInterval(60);// Or use the maximum intervalawait sandbox.setAutoArchiveInterval(0);
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 hourawait sandbox.setAutostopInterval(60);// Or disable auto-stopawait sandbox.setAutostopInterval(0);
setLabels()
setLabels(labels: Record<string, string>): Promise<void>
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<void>
Example:
// Set sandbox labelsawait 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 secondsconsole.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
stringparams?
CodeRunParams
Returns:
string