Sandbox
Represents a Daytona Sandbox.
Properties:
-
autoArchiveInterval?number - Auto-archive interval in minutesImplementation of
SandboxDto.autoArchiveInterval -
autoDeleteInterval?number - Auto-delete interval in minutesImplementation of
SandboxDto.autoDeleteInterval -
autoStopInterval?number - Auto-stop interval in minutesImplementation of
SandboxDto.autoStopInterval -
backupCreatedAt?string - When the backup was createdImplementation of
SandboxDto.backupCreatedAt -
backupState?SandboxBackupStateEnum - Current state of Sandbox backupImplementation of
SandboxDto.backupState -
buildInfo?BuildInfo - Build information for the Sandbox if it was created from dynamic buildImplementation of
SandboxDto.buildInfo -
computerUseComputerUse - Computer use operations interface for desktop automation -
cpunumber - Number of CPUs allocated to the SandboxImplementation of
SandboxDto.cpu -
createdAt?string - When the Sandbox was createdImplementation of
SandboxDto.createdAt -
disknumber - Amount of disk space allocated to the Sandbox in GiBImplementation of
SandboxDto.disk -
envRecord<string, string> - Environment variables set in the SandboxImplementation of
SandboxDto.env -
errorReason?string - Error message if Sandbox is in error stateImplementation of
SandboxDto.errorReason -
fsFileSystem - File system operations interface -
gitGit - Git operations interface -
gpunumber - Number of GPUs allocated to the SandboxImplementation of
SandboxDto.gpu -
idstring - Unique identifier for the SandboxImplementation of
SandboxDto.id -
labelsRecord<string, string> - Custom labels attached to the SandboxImplementation of
SandboxDto.labels -
memorynumber - Amount of memory allocated to the Sandbox in GiBImplementation of
SandboxDto.memory -
namestring - The name of the sandboxImplementation of
SandboxDto.name -
networkAllowList?string - Comma-separated list of allowed CIDR network addresses for the SandboxImplementation of
SandboxDto.networkAllowList -
networkBlockAllboolean - Whether to block all network access for the SandboxImplementation of
SandboxDto.networkBlockAll -
organizationIdstring - Organization ID of the SandboxImplementation of
SandboxDto.organizationId -
processProcess - Process execution interface -
publicboolean - Whether the Sandbox is publicly accessibleImplementation of
SandboxDto.public -
snapshot?string - Daytona snapshot used to create the SandboxImplementation of
SandboxDto.snapshot -
state?SandboxState - Current state of the Sandbox (e.g., “started”, “stopped”)Implementation of
SandboxDto.state -
targetstring - Target location of the runner where the Sandbox runsImplementation of
SandboxDto.target -
updatedAt?string - When the Sandbox was last updatedImplementation of
SandboxDto.updatedAt -
userstring - OS user running in the SandboxImplementation of
SandboxDto.user -
volumes?SandboxVolume[] - Volumes attached to the SandboxImplementation of
SandboxDto.volumes
Implements
Sandbox
Constructors
new Sandbox()
new Sandbox( sandboxDto: Sandbox, clientConfig: Configuration, sandboxApi: SandboxApi, toolboxApi: ToolboxApi, codeToolbox: SandboxCodeToolbox): SandboxCreates a new Sandbox instance
Parameters:
sandboxDtoSandbox - The API Sandbox instanceclientConfigConfigurationsandboxApiSandboxApi - API client for Sandbox operationstoolboxApiToolboxApi - API client for toolbox operationscodeToolboxSandboxCodeToolbox - 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:
languageIdstring - The language server type (e.g., “typescript”)pathToProjectstring - Path to the project root directory. Relative paths are resolved based on the sandbox working directory.
Returns:
Promise<LspServer>- A new LSP server instance configured for the specified language
Example:
const lsp = await sandbox.createLspServer('typescript', 'workspace/project');createSshAccess()
createSshAccess(expiresInMinutes?: number): Promise<SshAccessDto>Creates an SSH access token for the sandbox.
Parameters:
expiresInMinutes?number - The number of minutes the SSH access token will be valid for.
Returns:
Promise<SshAccessDto>- The SSH access token.
delete()
delete(timeout: number): Promise<void>Deletes the Sandbox.
Parameters:
timeoutnumber = 60
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:
portnumber - The port to open the preview link on.
Returns:
Promise<PortPreviewUrl>- The response object for the preview link, which includes theurland thetoken(to access private sandboxes).
Example:
const previewLink = await sandbox.getPreviewLink(3000);console.log(`Preview URL: ${previewLink.url}`);console.log(`Token: ${previewLink.token}`);getUserHomeDir()
getUserHomeDir(): Promise<string>Gets the user’s home directory path for the logged in user inside the Sandbox.
Returns:
Promise<string>- The absolute path to the Sandbox user’s home directory for the logged in user
Example:
const userHomeDir = await sandbox.getUserHomeDir();console.log(`Sandbox user home: ${userHomeDir}`);getUserRootDir()
getUserRootDir(): Promise<string>Returns:
Promise<string>
Deprecated
Use getUserHomeDir instead. This method will be removed in a future version.
getWorkDir()
getWorkDir(): Promise<string>Gets the working directory path inside the Sandbox.
Returns:
Promise<string>- The absolute path to the Sandbox working directory. Uses the WORKDIR specified in the Dockerfile if present, or falling back to the user’s home directory if not.
Example:
const workDir = await sandbox.getWorkDir();console.log(`Sandbox working directory: ${workDir}`);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`);revokeSshAccess()
revokeSshAccess(token: string): Promise<void>Revokes an SSH access token for the sandbox.
Parameters:
tokenstring - The token to revoke.
Returns:
Promise<void>
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:
intervalnumber - 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);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:
intervalnumber - 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 hourawait sandbox.setAutoDeleteInterval(60);// Or delete immediately upon stoppingawait sandbox.setAutoDeleteInterval(0);// Or disable auto-deleteawait 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:
intervalnumber - 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<Record<string, string>>Sets labels for the Sandbox.
Labels are key-value pairs that can be used to organize and identify Sandboxes.
Parameters:
labelsRecord<string, string> - Dictionary of key-value pairs representing Sandbox labels
Returns:
Promise<Record<string, string>>
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');validateSshAccess()
validateSshAccess(token: string): Promise<SshAccessValidationDto>Validates an SSH access token for the sandbox.
Parameters:
tokenstring - The token to validate.
Returns:
Promise<SshAccessValidationDto>- The SSH access validation result.
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.
PaginatedSandboxes
Extends:
Properties:
-
itemsSandbox[] -
pagenumber- Inherited from:
PaginatedSandboxes.page
- Inherited from:
-
totalnumber- Inherited from:
PaginatedSandboxes.total
- Inherited from:
-
totalPagesnumber- Inherited from:
PaginatedSandboxes.totalPages
- Inherited from:
-
Omit<PaginatedSandboxesDto,"items">
SandboxCodeToolbox
Interface defining methods that a code toolbox must implement
Methods
getRunCommand()
getRunCommand(code: string, params?: CodeRunParams): stringGenerates a command to run the provided code
Parameters:
codestringparams?CodeRunParams
Returns:
string