@daytonaio/sdk 0.0.0-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +146 -0
- package/package.json +39 -0
- package/src/Daytona.d.ts +331 -0
- package/src/Daytona.js +400 -0
- package/src/Daytona.js.map +1 -0
- package/src/FileSystem.d.ts +270 -0
- package/src/FileSystem.js +302 -0
- package/src/FileSystem.js.map +1 -0
- package/src/Git.d.ts +211 -0
- package/src/Git.js +275 -0
- package/src/Git.js.map +1 -0
- package/src/Image.d.ts +264 -0
- package/src/Image.js +565 -0
- package/src/Image.js.map +1 -0
- package/src/LspServer.d.ts +173 -0
- package/src/LspServer.js +209 -0
- package/src/LspServer.js.map +1 -0
- package/src/ObjectStorage.d.ts +85 -0
- package/src/ObjectStorage.js +231 -0
- package/src/ObjectStorage.js.map +1 -0
- package/src/Process.d.ts +246 -0
- package/src/Process.js +290 -0
- package/src/Process.js.map +1 -0
- package/src/Sandbox.d.ts +266 -0
- package/src/Sandbox.js +389 -0
- package/src/Sandbox.js.map +1 -0
- package/src/Snapshot.d.ts +116 -0
- package/src/Snapshot.js +187 -0
- package/src/Snapshot.js.map +1 -0
- package/src/Volume.d.ts +79 -0
- package/src/Volume.js +97 -0
- package/src/Volume.js.map +1 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.d.ts +11 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.js +358 -0
- package/src/code-toolbox/SandboxPythonCodeToolbox.js.map +1 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.d.ts +5 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.js +17 -0
- package/src/code-toolbox/SandboxTsCodeToolbox.js.map +1 -0
- package/src/errors/DaytonaError.d.ts +10 -0
- package/src/errors/DaytonaError.js +20 -0
- package/src/errors/DaytonaError.js.map +1 -0
- package/src/index.d.ts +15 -0
- package/src/index.js +32 -0
- package/src/index.js.map +1 -0
- package/src/types/Charts.d.ts +151 -0
- package/src/types/Charts.js +46 -0
- package/src/types/Charts.js.map +1 -0
- package/src/types/ExecuteResponse.d.ts +26 -0
- package/src/types/ExecuteResponse.js +7 -0
- package/src/types/ExecuteResponse.js.map +1 -0
- package/src/utils/ArtifactParser.d.ts +13 -0
- package/src/utils/ArtifactParser.js +55 -0
- package/src/utils/ArtifactParser.js.map +1 -0
- package/src/utils/Path.d.ts +1 -0
- package/src/utils/Path.js +61 -0
- package/src/utils/Path.js.map +1 -0
- package/src/utils/Stream.d.ts +13 -0
- package/src/utils/Stream.js +82 -0
- package/src/utils/Stream.js.map +1 -0
package/README.md
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Daytona SDK for TypeScript
|
|
2
|
+
|
|
3
|
+
A TypeScript SDK for interacting with the Daytona API, providing a simple interface for Daytona Sandbox management, Git operations, file system operations, and language server protocol support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
You can install the package using npm:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @daytonaio/sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or using yarn:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @daytonaio/sdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## Quick Start
|
|
20
|
+
|
|
21
|
+
Here's a simple example of using the SDK:
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { Daytona } from '@daytonaio/sdk'
|
|
25
|
+
|
|
26
|
+
// Initialize using environment variables
|
|
27
|
+
const daytona = new Daytona()
|
|
28
|
+
|
|
29
|
+
// Create a sandbox
|
|
30
|
+
const sandbox = await daytona.create()
|
|
31
|
+
|
|
32
|
+
// Run code in the sandbox
|
|
33
|
+
const response = await sandbox.process.codeRun('console.log("Hello World!")')
|
|
34
|
+
console.log(response.result)
|
|
35
|
+
|
|
36
|
+
// Clean up when done
|
|
37
|
+
await daytona.delete(sandbox)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Configuration
|
|
41
|
+
|
|
42
|
+
The SDK can be configured using environment variables or by passing a configuration object:
|
|
43
|
+
|
|
44
|
+
```typescript
|
|
45
|
+
import { Daytona } from '@daytonaio/sdk'
|
|
46
|
+
|
|
47
|
+
// Initialize with configuration
|
|
48
|
+
const daytona = new Daytona({
|
|
49
|
+
apiKey: 'your-api-key',
|
|
50
|
+
apiUrl: 'your-api-url',
|
|
51
|
+
target: 'us',
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Or using environment variables:
|
|
56
|
+
|
|
57
|
+
- `DAYTONA_API_KEY`: Your Daytona API key
|
|
58
|
+
- `DAYTONA_API_URL`: The Daytona API URL
|
|
59
|
+
- `DAYTONA_TARGET`: Your target environment
|
|
60
|
+
|
|
61
|
+
You can also customize sandbox creation:
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
const sandbox = await daytona.create({
|
|
65
|
+
language: 'typescript',
|
|
66
|
+
envVars: { NODE_ENV: 'development' },
|
|
67
|
+
autoStopInterval: 60, // Auto-stop after 1 hour of inactivity,
|
|
68
|
+
autoArchiveInterval: 60, // Auto-archive after a Sandbox has been stopped for 1 hour
|
|
69
|
+
})
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Features
|
|
73
|
+
|
|
74
|
+
- **Sandbox Management**: Create, manage and remove sandboxes
|
|
75
|
+
- **Git Operations**: Clone repositories, manage branches, and more
|
|
76
|
+
- **File System Operations**: Upload, download, search and manipulate files
|
|
77
|
+
- **Language Server Protocol**: Interact with language servers for code intelligence
|
|
78
|
+
- **Process Management**: Execute code and commands in sandboxes
|
|
79
|
+
|
|
80
|
+
## Examples
|
|
81
|
+
|
|
82
|
+
### Execute Commands
|
|
83
|
+
|
|
84
|
+
```typescript
|
|
85
|
+
// Execute a shell command
|
|
86
|
+
const response = await sandbox.process.executeCommand('echo "Hello, World!"')
|
|
87
|
+
console.log(response.result)
|
|
88
|
+
|
|
89
|
+
// Run TypeScript code
|
|
90
|
+
const response = await sandbox.process.codeRun(`
|
|
91
|
+
const x = 10
|
|
92
|
+
const y = 20
|
|
93
|
+
console.log(\`Sum: \${x + y}\`)
|
|
94
|
+
`)
|
|
95
|
+
console.log(response.result)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### File Operations
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
// Upload a file
|
|
102
|
+
await sandbox.fs.uploadFile(Buffer.from('Hello, World!'), 'path/to/file.txt')
|
|
103
|
+
|
|
104
|
+
// Download a file
|
|
105
|
+
const content = await sandbox.fs.downloadFile('path/to/file.txt')
|
|
106
|
+
|
|
107
|
+
// Search for files
|
|
108
|
+
const matches = await sandbox.fs.findFiles(root_dir, 'search_pattern')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Git Operations
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
// Clone a repository
|
|
115
|
+
await sandbox.git.clone('https://github.com/example/repo', 'path/to/clone')
|
|
116
|
+
|
|
117
|
+
// List branches
|
|
118
|
+
const branches = await sandbox.git.branches('path/to/repo')
|
|
119
|
+
|
|
120
|
+
// Add files
|
|
121
|
+
await sandbox.git.add('path/to/repo', ['file1.txt', 'file2.txt'])
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Language Server Protocol
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
// Create and start a language server
|
|
128
|
+
const lsp = await sandbox.createLspServer('typescript', 'path/to/project')
|
|
129
|
+
await lsp.start()
|
|
130
|
+
|
|
131
|
+
// Notify the lsp for the file
|
|
132
|
+
await lsp.didOpen('path/to/file.ts')
|
|
133
|
+
|
|
134
|
+
// Get document symbols
|
|
135
|
+
const symbols = await lsp.documentSymbols('path/to/file.ts')
|
|
136
|
+
|
|
137
|
+
// Get completions
|
|
138
|
+
const completions = await lsp.completions('path/to/file.ts', {
|
|
139
|
+
line: 10,
|
|
140
|
+
character: 15,
|
|
141
|
+
})
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Contributing
|
|
145
|
+
|
|
146
|
+
Daytona is Open Source under the [Apache License 2.0](/libs/sdk-typescript//LICENSE), and is the [copyright of its contributors](/NOTICE). If you would like to contribute to the software, read the Developer Certificate of Origin Version 1.1 (https://developercertificate.org/). Afterwards, navigate to the [contributing guide](/CONTRIBUTING.md) to get started.
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@daytonaio/sdk",
|
|
3
|
+
"version": "0.0.0-dev",
|
|
4
|
+
"description": "TypeScript SDK for Daytona",
|
|
5
|
+
"main": "./src/index.js",
|
|
6
|
+
"types": "./src/index.d.ts",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/daytonaio/daytona.git"
|
|
10
|
+
},
|
|
11
|
+
"author": "Daytona Platforms Inc.",
|
|
12
|
+
"license": "Apache-2.0",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/daytonaio/daytona/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://www.daytona.io/docs",
|
|
17
|
+
"config": {
|
|
18
|
+
"docsDir": "../../apps/docs/content/sdk-typescript"
|
|
19
|
+
},
|
|
20
|
+
"scripts": {
|
|
21
|
+
"docs": "bash -O extglob -c 'rm -rf $npm_package_config_docsDir/!(index.mdx)' && typedoc && rm -f $npm_package_config_docsDir/readme.mdx"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [],
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@aws-sdk/client-s3": "^3.787.0",
|
|
26
|
+
"@aws-sdk/lib-storage": "^3.798.0",
|
|
27
|
+
"@iarna/toml": "^2.2.5",
|
|
28
|
+
"axios": "^1.6.1",
|
|
29
|
+
"dotenv": "16.5.0",
|
|
30
|
+
"fast-glob": "^3.3.0",
|
|
31
|
+
"form-data": "^4.0.0",
|
|
32
|
+
"shell-quote": "^1.8.2",
|
|
33
|
+
"tar": "^6.2.0",
|
|
34
|
+
"untildify": "^5.0.0",
|
|
35
|
+
"@daytonaio/api-client": "0.0.0-dev"
|
|
36
|
+
},
|
|
37
|
+
"packageManager": "yarn@4.6.0",
|
|
38
|
+
"type": "commonjs"
|
|
39
|
+
}
|
package/src/Daytona.d.ts
ADDED
|
@@ -0,0 +1,331 @@
|
|
|
1
|
+
import { SandboxVolume } from '@daytonaio/api-client';
|
|
2
|
+
import { Image } from './Image';
|
|
3
|
+
import { Sandbox } from './Sandbox';
|
|
4
|
+
import { SnapshotService } from './Snapshot';
|
|
5
|
+
import { VolumeService } from './Volume';
|
|
6
|
+
/**
|
|
7
|
+
* Represents a volume mount for a Sandbox.
|
|
8
|
+
*
|
|
9
|
+
* @interface
|
|
10
|
+
* @property {string} volumeId - ID of the Volume to mount
|
|
11
|
+
* @property {string} mountPath - Path on the Sandbox to mount the Volume
|
|
12
|
+
*/
|
|
13
|
+
export interface VolumeMount extends SandboxVolume {
|
|
14
|
+
volumeId: string;
|
|
15
|
+
mountPath: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Configuration options for initializing the Daytona client.
|
|
19
|
+
*
|
|
20
|
+
* @interface
|
|
21
|
+
* @property {string} apiKey - API key for authentication with the Daytona API
|
|
22
|
+
* @property {string} jwtToken - JWT token for authentication with the Daytona API. If not set, it must be provided
|
|
23
|
+
* via the environment variable `DAYTONA_JWT_TOKEN`, or an API key must be provided instead.
|
|
24
|
+
* @property {string} organizationId - Organization ID used for JWT-based authentication. Required if a JWT token
|
|
25
|
+
* is provided, and must be set either here or in the environment variable `DAYTONA_ORGANIZATION_ID`.
|
|
26
|
+
* @property {string} apiUrl - URL of the Daytona API. Defaults to 'https://app.daytona.io/api'
|
|
27
|
+
* if not set here and not set in environment variable DAYTONA_API_URL.
|
|
28
|
+
* @property {string} target - Target location for Sandboxes
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* const config: DaytonaConfig = {
|
|
32
|
+
* apiKey: "your-api-key",
|
|
33
|
+
* apiUrl: "https://your-api.com",
|
|
34
|
+
* target: "us"
|
|
35
|
+
* };
|
|
36
|
+
* const daytona = new Daytona(config);
|
|
37
|
+
*/
|
|
38
|
+
export interface DaytonaConfig {
|
|
39
|
+
/** API key for authentication with the Daytona API */
|
|
40
|
+
apiKey?: string;
|
|
41
|
+
/** JWT token for authentication with the Daytona API */
|
|
42
|
+
jwtToken?: string;
|
|
43
|
+
/** Organization ID for authentication with the Daytona API */
|
|
44
|
+
organizationId?: string;
|
|
45
|
+
/** URL of the Daytona API.
|
|
46
|
+
*/
|
|
47
|
+
apiUrl?: string;
|
|
48
|
+
/**
|
|
49
|
+
* @deprecated Use `apiUrl` instead. This property will be removed in future versions.
|
|
50
|
+
*/
|
|
51
|
+
serverUrl?: string;
|
|
52
|
+
/** Target environment for sandboxes */
|
|
53
|
+
target?: string;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Supported programming languages for code execution
|
|
57
|
+
*/
|
|
58
|
+
export declare enum CodeLanguage {
|
|
59
|
+
PYTHON = "python",
|
|
60
|
+
TYPESCRIPT = "typescript",
|
|
61
|
+
JAVASCRIPT = "javascript"
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Resource allocation for a Sandbox.
|
|
65
|
+
*
|
|
66
|
+
* @interface
|
|
67
|
+
* @property {number} [cpu] - CPU allocation for the Sandbox in cores
|
|
68
|
+
* @property {number} [gpu] - GPU allocation for the Sandbox in units
|
|
69
|
+
* @property {number} [memory] - Memory allocation for the Sandbox in GiB
|
|
70
|
+
* @property {number} [disk] - Disk space allocation for the Sandbox in GiB
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const resources: SandboxResources = {
|
|
74
|
+
* cpu: 2,
|
|
75
|
+
* memory: 4, // 4GiB RAM
|
|
76
|
+
* disk: 20 // 20GiB disk
|
|
77
|
+
* };
|
|
78
|
+
*/
|
|
79
|
+
export interface Resources {
|
|
80
|
+
/** CPU allocation for the Sandbox */
|
|
81
|
+
cpu?: number;
|
|
82
|
+
/** GPU allocation for the Sandbox */
|
|
83
|
+
gpu?: number;
|
|
84
|
+
/** Memory allocation for the Sandbox in GiB */
|
|
85
|
+
memory?: number;
|
|
86
|
+
/** Disk space allocation for the Sandbox in GiB */
|
|
87
|
+
disk?: number;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Base parameters for creating a new Sandbox.
|
|
91
|
+
*
|
|
92
|
+
* @interface
|
|
93
|
+
* @property {string} [user] - Optional os user to use for the Sandbox
|
|
94
|
+
* @property {CodeLanguage | string} [language] - Programming language for direct code execution
|
|
95
|
+
* @property {Record<string, string>} [envVars] - Optional environment variables to set in the Sandbox
|
|
96
|
+
* @property {Record<string, string>} [labels] - Sandbox labels
|
|
97
|
+
* @property {boolean} [public] - Is the Sandbox port preview public
|
|
98
|
+
* @property {number} [autoStopInterval] - Auto-stop interval in minutes (0 means disabled). Default is 15 minutes.
|
|
99
|
+
* @property {number} [autoArchiveInterval] - Auto-archive interval in minutes (0 means the maximum interval will be used). Default is 7 days.
|
|
100
|
+
*/
|
|
101
|
+
export type CreateSandboxBaseParams = {
|
|
102
|
+
user?: string;
|
|
103
|
+
language?: CodeLanguage | string;
|
|
104
|
+
envVars?: Record<string, string>;
|
|
105
|
+
labels?: Record<string, string>;
|
|
106
|
+
public?: boolean;
|
|
107
|
+
autoStopInterval?: number;
|
|
108
|
+
autoArchiveInterval?: number;
|
|
109
|
+
volumes?: VolumeMount[];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
* Parameters for creating a new Sandbox.
|
|
113
|
+
*
|
|
114
|
+
* @interface
|
|
115
|
+
* @property {string | Image} [image] - Custom Docker image to use for the Sandbox. If an Image object is provided,
|
|
116
|
+
* the image will be dynamically built.
|
|
117
|
+
* @property {Resources} [resources] - Resource allocation for the Sandbox. If not provided, sandbox will
|
|
118
|
+
* have default resources.
|
|
119
|
+
*/
|
|
120
|
+
export type CreateSandboxFromImageParams = CreateSandboxBaseParams & {
|
|
121
|
+
image: string | Image;
|
|
122
|
+
resources?: Resources;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Parameters for creating a new Sandbox from a snapshot.
|
|
126
|
+
*
|
|
127
|
+
* @interface
|
|
128
|
+
* @property {string} [snapshot] - Name of the snapshot to use for the Sandbox.
|
|
129
|
+
*/
|
|
130
|
+
export type CreateSandboxFromSnapshotParams = CreateSandboxBaseParams & {
|
|
131
|
+
snapshot?: string;
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Filter for Sandboxes.
|
|
135
|
+
*
|
|
136
|
+
* @interface
|
|
137
|
+
* @property {string} [id] - The ID of the Sandbox to retrieve
|
|
138
|
+
* @property {Record<string, string>} [labels] - Labels to filter Sandboxes
|
|
139
|
+
*/
|
|
140
|
+
export type SandboxFilter = {
|
|
141
|
+
id?: string;
|
|
142
|
+
labels?: Record<string, string>;
|
|
143
|
+
};
|
|
144
|
+
/**
|
|
145
|
+
* Main class for interacting with the Daytona API.
|
|
146
|
+
* Provides methods for creating, managing, and interacting with Daytona Sandboxes.
|
|
147
|
+
* Can be initialized either with explicit configuration or using environment variables.
|
|
148
|
+
*
|
|
149
|
+
* @property {VolumeService} volume - Service for managing Daytona Volumes
|
|
150
|
+
* @property {SnapshotService} snapshot - Service for managing Daytona Snapshots
|
|
151
|
+
*
|
|
152
|
+
* @example
|
|
153
|
+
* // Using environment variables
|
|
154
|
+
* // Uses DAYTONA_API_KEY, DAYTONA_API_URL, DAYTONA_TARGET
|
|
155
|
+
* const daytona = new Daytona();
|
|
156
|
+
* const sandbox = await daytona.create();
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
* // Using explicit configuration
|
|
160
|
+
* const config: DaytonaConfig = {
|
|
161
|
+
* apiKey: "your-api-key",
|
|
162
|
+
* apiUrl: "https://your-api.com",
|
|
163
|
+
* target: "us"
|
|
164
|
+
* };
|
|
165
|
+
* const daytona = new Daytona(config);
|
|
166
|
+
*
|
|
167
|
+
* @class
|
|
168
|
+
*/
|
|
169
|
+
export declare class Daytona {
|
|
170
|
+
private readonly sandboxApi;
|
|
171
|
+
private readonly toolboxApi;
|
|
172
|
+
private readonly objectStorageApi;
|
|
173
|
+
private readonly target?;
|
|
174
|
+
private readonly apiKey?;
|
|
175
|
+
private readonly jwtToken?;
|
|
176
|
+
private readonly organizationId?;
|
|
177
|
+
private readonly apiUrl;
|
|
178
|
+
readonly volume: VolumeService;
|
|
179
|
+
readonly snapshot: SnapshotService;
|
|
180
|
+
/**
|
|
181
|
+
* Creates a new Daytona client instance.
|
|
182
|
+
*
|
|
183
|
+
* @param {DaytonaConfig} [config] - Configuration options
|
|
184
|
+
* @throws {DaytonaError} - `DaytonaError` - When API key is missing
|
|
185
|
+
*/
|
|
186
|
+
constructor(config?: DaytonaConfig);
|
|
187
|
+
/**
|
|
188
|
+
* Creates Sandboxes from specified or default snapshot. You can specify various parameters,
|
|
189
|
+
* including language, image, environment variables, and volumes.
|
|
190
|
+
*
|
|
191
|
+
* @param {CreateSandboxFromSnapshotParams} [params] - Parameters for Sandbox creation from snapshot
|
|
192
|
+
* @param {object} [options] - Options for the create operation
|
|
193
|
+
* @param {number} [options.timeout] - Timeout in seconds (0 means no timeout, default is 60)
|
|
194
|
+
* @returns {Promise<Sandbox>} The created Sandbox instance
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* const sandbox = await daytona.create();
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* // Create a custom sandbox
|
|
201
|
+
* const params: CreateSandboxFromSnapshotParams = {
|
|
202
|
+
* language: 'typescript',
|
|
203
|
+
* snapshot: 'my-snapshot-id',
|
|
204
|
+
* envVars: {
|
|
205
|
+
* NODE_ENV: 'development',
|
|
206
|
+
* DEBUG: 'true'
|
|
207
|
+
* },
|
|
208
|
+
* autoStopInterval: 60
|
|
209
|
+
* };
|
|
210
|
+
* const sandbox = await daytona.create(params, { timeout: 100 });
|
|
211
|
+
*/
|
|
212
|
+
create(params?: CreateSandboxFromSnapshotParams, options?: {
|
|
213
|
+
timeout?: number;
|
|
214
|
+
}): Promise<Sandbox>;
|
|
215
|
+
/**
|
|
216
|
+
* Creates Sandboxes from specified image available on some registry or declarative Daytona Image. You can specify various parameters,
|
|
217
|
+
* including resources, language, image, environment variables, and volumes. Daytona creates snapshot from
|
|
218
|
+
* provided image and uses it to create Sandbox.
|
|
219
|
+
*
|
|
220
|
+
* @param {CreateSandboxFromImageParams} [params] - Parameters for Sandbox creation from image
|
|
221
|
+
* @param {object} [options] - Options for the create operation
|
|
222
|
+
* @param {number} [options.timeout] - Timeout in seconds (0 means no timeout, default is 60)
|
|
223
|
+
* @param {function} [options.onSnapshotCreateLogs] - Callback function to handle snapshot creation logs.
|
|
224
|
+
* @returns {Promise<Sandbox>} The created Sandbox instance
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* const sandbox = await daytona.create({ image: 'debian:12.9' }, { timeout: 90, onSnapshotCreateLogs: console.log });
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* // Create a custom sandbox
|
|
231
|
+
* const image = Image.base('alpine:3.18').pipInstall('numpy');
|
|
232
|
+
* const params: CreateSandboxFromImageParams = {
|
|
233
|
+
* language: 'typescript',
|
|
234
|
+
* image,
|
|
235
|
+
* envVars: {
|
|
236
|
+
* NODE_ENV: 'development',
|
|
237
|
+
* DEBUG: 'true'
|
|
238
|
+
* },
|
|
239
|
+
* resources: {
|
|
240
|
+
* cpu: 2,
|
|
241
|
+
* memory: 4 // 4GB RAM
|
|
242
|
+
* },
|
|
243
|
+
* autoStopInterval: 60
|
|
244
|
+
* };
|
|
245
|
+
* const sandbox = await daytona.create(params, { timeout: 100, onSnapshotCreateLogs: console.log });
|
|
246
|
+
*/
|
|
247
|
+
create(params?: CreateSandboxFromImageParams, options?: {
|
|
248
|
+
onSnapshotCreateLogs?: (chunk: string) => void;
|
|
249
|
+
timeout?: number;
|
|
250
|
+
}): Promise<Sandbox>;
|
|
251
|
+
/**
|
|
252
|
+
* Gets a Sandbox by its ID.
|
|
253
|
+
*
|
|
254
|
+
* @param {string} sandboxId - The ID of the Sandbox to retrieve
|
|
255
|
+
* @returns {Promise<Sandbox>} The Sandbox
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* const sandbox = await daytona.get('my-sandbox-id');
|
|
259
|
+
* console.log(`Sandbox state: ${sandbox.state}`);
|
|
260
|
+
*/
|
|
261
|
+
get(sandboxId: string): Promise<Sandbox>;
|
|
262
|
+
/**
|
|
263
|
+
* Finds a Sandbox by its ID or labels.
|
|
264
|
+
*
|
|
265
|
+
* @param {SandboxFilter} filter - Filter for Sandboxes
|
|
266
|
+
* @returns {Promise<Sandbox>} First Sandbox that matches the ID or labels.
|
|
267
|
+
*
|
|
268
|
+
* @example
|
|
269
|
+
* const sandbox = await daytona.findOne({ labels: { 'my-label': 'my-value' } });
|
|
270
|
+
* console.log(`Sandbox ID: ${sandbox.id}, State: ${sandbox.state}`);
|
|
271
|
+
*/
|
|
272
|
+
findOne(filter: SandboxFilter): Promise<Sandbox>;
|
|
273
|
+
/**
|
|
274
|
+
* Lists all Sandboxes filtered by labels.
|
|
275
|
+
*
|
|
276
|
+
* @param {Record<string, string>} [labels] - Labels to filter Sandboxes
|
|
277
|
+
* @returns {Promise<Sandbox[]>} Array of Sandboxes that match the labels.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* const sandboxes = await daytona.list({ 'my-label': 'my-value' });
|
|
281
|
+
* for (const sandbox of sandboxes) {
|
|
282
|
+
* console.log(`${sandbox.id}: ${sandbox.state}`);
|
|
283
|
+
* }
|
|
284
|
+
*/
|
|
285
|
+
list(labels?: Record<string, string>): Promise<Sandbox[]>;
|
|
286
|
+
/**
|
|
287
|
+
* Starts a Sandbox and waits for it to be ready.
|
|
288
|
+
*
|
|
289
|
+
* @param {Sandbox} sandbox - The Sandbox to start
|
|
290
|
+
* @param {number} [timeout] - Optional timeout in seconds (0 means no timeout)
|
|
291
|
+
* @returns {Promise<void>}
|
|
292
|
+
*
|
|
293
|
+
* @example
|
|
294
|
+
* const sandbox = await daytona.get('my-sandbox-id');
|
|
295
|
+
* // Wait up to 60 seconds for the sandbox to start
|
|
296
|
+
* await daytona.start(sandbox, 60);
|
|
297
|
+
*/
|
|
298
|
+
start(sandbox: Sandbox, timeout?: number): Promise<void>;
|
|
299
|
+
/**
|
|
300
|
+
* Stops a Sandbox.
|
|
301
|
+
*
|
|
302
|
+
* @param {Sandbox} sandbox - The Sandbox to stop
|
|
303
|
+
* @returns {Promise<void>}
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
* const sandbox = await daytona.get('my-sandbox-id');
|
|
307
|
+
* await daytona.stop(sandbox);
|
|
308
|
+
*/
|
|
309
|
+
stop(sandbox: Sandbox): Promise<void>;
|
|
310
|
+
/**
|
|
311
|
+
* Deletes a Sandbox.
|
|
312
|
+
*
|
|
313
|
+
* @param {Sandbox} sandbox - The Sandbox to delete
|
|
314
|
+
* @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
|
|
315
|
+
* @returns {Promise<void>}
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* const sandbox = await daytona.get('my-sandbox-id');
|
|
319
|
+
* await daytona.delete(sandbox);
|
|
320
|
+
*/
|
|
321
|
+
delete(sandbox: Sandbox, timeout?: number): Promise<void>;
|
|
322
|
+
/**
|
|
323
|
+
* Gets the appropriate code toolbox based on language.
|
|
324
|
+
*
|
|
325
|
+
* @private
|
|
326
|
+
* @param {CodeLanguage} [language] - Programming language for the toolbox
|
|
327
|
+
* @returns {SandboxCodeToolbox} The appropriate code toolbox instance
|
|
328
|
+
* @throws {DaytonaError} - `DaytonaError` - When an unsupported language is specified
|
|
329
|
+
*/
|
|
330
|
+
private getCodeToolbox;
|
|
331
|
+
}
|