@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/src/Process.js
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright 2025 Daytona Platforms Inc.
|
|
4
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Process = exports.CodeRunParams = void 0;
|
|
8
|
+
const ArtifactParser_1 = require("./utils/ArtifactParser");
|
|
9
|
+
const Stream_1 = require("./utils/Stream");
|
|
10
|
+
/**
|
|
11
|
+
* Parameters for code execution.
|
|
12
|
+
*/
|
|
13
|
+
class CodeRunParams {
|
|
14
|
+
/**
|
|
15
|
+
* Command line arguments
|
|
16
|
+
*/
|
|
17
|
+
argv;
|
|
18
|
+
/**
|
|
19
|
+
* Environment variables
|
|
20
|
+
*/
|
|
21
|
+
env;
|
|
22
|
+
}
|
|
23
|
+
exports.CodeRunParams = CodeRunParams;
|
|
24
|
+
/**
|
|
25
|
+
* Handles process and code execution within a Sandbox.
|
|
26
|
+
*
|
|
27
|
+
* @class
|
|
28
|
+
*/
|
|
29
|
+
class Process {
|
|
30
|
+
sandboxId;
|
|
31
|
+
codeToolbox;
|
|
32
|
+
toolboxApi;
|
|
33
|
+
getRootDir;
|
|
34
|
+
constructor(sandboxId, codeToolbox, toolboxApi, getRootDir) {
|
|
35
|
+
this.sandboxId = sandboxId;
|
|
36
|
+
this.codeToolbox = codeToolbox;
|
|
37
|
+
this.toolboxApi = toolboxApi;
|
|
38
|
+
this.getRootDir = getRootDir;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Executes a shell command in the Sandbox.
|
|
42
|
+
*
|
|
43
|
+
* @param {string} command - Shell command to execute
|
|
44
|
+
* @param {string} [cwd] - Working directory for command execution. If not specified, uses the Sandbox root directory.
|
|
45
|
+
* Default is the user's root directory.
|
|
46
|
+
* @param {Record<string, string>} [env] - Environment variables to set for the command
|
|
47
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for the command to complete. 0 means wait indefinitely.
|
|
48
|
+
* @returns {Promise<ExecuteResponse>} Command execution results containing:
|
|
49
|
+
* - exitCode: The command's exit status
|
|
50
|
+
* - result: Standard output from the command
|
|
51
|
+
* - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* // Simple command
|
|
55
|
+
* const response = await process.executeCommand('echo "Hello"');
|
|
56
|
+
* console.log(response.artifacts.stdout); // Prints: Hello
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* // Command with working directory
|
|
60
|
+
* const result = await process.executeCommand('ls', 'workspace/src');
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* // Command with timeout
|
|
64
|
+
* const result = await process.executeCommand('sleep 10', undefined, 5);
|
|
65
|
+
*/
|
|
66
|
+
async executeCommand(command, cwd, env, timeout) {
|
|
67
|
+
const base64UserCmd = Buffer.from(command).toString('base64');
|
|
68
|
+
command = `echo '${base64UserCmd}' | base64 -d | sh`;
|
|
69
|
+
if (env && Object.keys(env).length > 0) {
|
|
70
|
+
const safeEnvExports = Object.entries(env)
|
|
71
|
+
.map(([key, value]) => {
|
|
72
|
+
const encodedValue = Buffer.from(value).toString('base64');
|
|
73
|
+
return `export ${key}=$(echo '${encodedValue}' | base64 -d)`;
|
|
74
|
+
})
|
|
75
|
+
.join(';') + ';';
|
|
76
|
+
command = `${safeEnvExports} ${command}`;
|
|
77
|
+
}
|
|
78
|
+
command = `sh -c "${command}"`;
|
|
79
|
+
const response = await this.toolboxApi.executeCommand(this.sandboxId, {
|
|
80
|
+
command,
|
|
81
|
+
timeout,
|
|
82
|
+
cwd: cwd ?? (await this.getRootDir()),
|
|
83
|
+
});
|
|
84
|
+
// Parse artifacts from the output
|
|
85
|
+
const artifacts = ArtifactParser_1.ArtifactParser.parseArtifacts(response.data.result);
|
|
86
|
+
// Return enhanced response with parsed artifacts
|
|
87
|
+
return {
|
|
88
|
+
...response.data,
|
|
89
|
+
result: artifacts.stdout,
|
|
90
|
+
artifacts,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Executes code in the Sandbox using the appropriate language runtime.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} code - Code to execute
|
|
97
|
+
* @param {CodeRunParams} params - Parameters for code execution
|
|
98
|
+
* @param {number} [timeout] - Maximum time in seconds to wait for execution to complete
|
|
99
|
+
* @returns {Promise<ExecuteResponse>} Code execution results containing:
|
|
100
|
+
* - exitCode: The execution's exit status
|
|
101
|
+
* - result: Standard output from the code
|
|
102
|
+
* - artifacts: ExecutionArtifacts object containing `stdout` (same as result) and `charts` (matplotlib charts metadata)
|
|
103
|
+
*
|
|
104
|
+
* @example
|
|
105
|
+
* // Run TypeScript code
|
|
106
|
+
* const response = await process.codeRun(`
|
|
107
|
+
* const x = 10;
|
|
108
|
+
* const y = 20;
|
|
109
|
+
* console.log(\`Sum: \${x + y}\`);
|
|
110
|
+
* `);
|
|
111
|
+
* console.log(response.artifacts.stdout); // Prints: Sum: 30
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* // Run Python code with matplotlib
|
|
115
|
+
* const response = await process.codeRun(`
|
|
116
|
+
* import matplotlib.pyplot as plt
|
|
117
|
+
* import numpy as np
|
|
118
|
+
*
|
|
119
|
+
* x = np.linspace(0, 10, 30)
|
|
120
|
+
* y = np.sin(x)
|
|
121
|
+
*
|
|
122
|
+
* plt.figure(figsize=(8, 5))
|
|
123
|
+
* plt.plot(x, y, 'b-', linewidth=2)
|
|
124
|
+
* plt.title('Line Chart')
|
|
125
|
+
* plt.xlabel('X-axis (seconds)')
|
|
126
|
+
* plt.ylabel('Y-axis (amplitude)')
|
|
127
|
+
* plt.grid(True)
|
|
128
|
+
* plt.show()
|
|
129
|
+
* `);
|
|
130
|
+
*
|
|
131
|
+
* if (response.artifacts?.charts) {
|
|
132
|
+
* const chart = response.artifacts.charts[0];
|
|
133
|
+
*
|
|
134
|
+
* console.log(`Type: ${chart.type}`);
|
|
135
|
+
* console.log(`Title: ${chart.title}`);
|
|
136
|
+
* if (chart.type === ChartType.LINE) {
|
|
137
|
+
* const lineChart = chart as LineChart
|
|
138
|
+
* console.log('X Label:', lineChart.x_label)
|
|
139
|
+
* console.log('Y Label:', lineChart.y_label)
|
|
140
|
+
* console.log('X Ticks:', lineChart.x_ticks)
|
|
141
|
+
* console.log('Y Ticks:', lineChart.y_ticks)
|
|
142
|
+
* console.log('X Tick Labels:', lineChart.x_tick_labels)
|
|
143
|
+
* console.log('Y Tick Labels:', lineChart.y_tick_labels)
|
|
144
|
+
* console.log('X Scale:', lineChart.x_scale)
|
|
145
|
+
* console.log('Y Scale:', lineChart.y_scale)
|
|
146
|
+
* console.log('Elements:')
|
|
147
|
+
* console.dir(lineChart.elements, { depth: null })
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
*/
|
|
151
|
+
async codeRun(code, params, timeout) {
|
|
152
|
+
const runCommand = this.codeToolbox.getRunCommand(code, params);
|
|
153
|
+
return this.executeCommand(runCommand, undefined, params?.env, timeout);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Creates a new long-running background session in the Sandbox.
|
|
157
|
+
*
|
|
158
|
+
* Sessions are background processes that maintain state between commands, making them ideal for
|
|
159
|
+
* scenarios requiring multiple related commands or persistent environment setup. You can run
|
|
160
|
+
* long-running commands and monitor process status.
|
|
161
|
+
*
|
|
162
|
+
* @param {string} sessionId - Unique identifier for the new session
|
|
163
|
+
* @returns {Promise<void>}
|
|
164
|
+
*
|
|
165
|
+
* @example
|
|
166
|
+
* // Create a new session
|
|
167
|
+
* const sessionId = 'my-session';
|
|
168
|
+
* await process.createSession(sessionId);
|
|
169
|
+
* const session = await process.getSession(sessionId);
|
|
170
|
+
* // Do work...
|
|
171
|
+
* await process.deleteSession(sessionId);
|
|
172
|
+
*/
|
|
173
|
+
async createSession(sessionId) {
|
|
174
|
+
await this.toolboxApi.createSession(this.sandboxId, {
|
|
175
|
+
sessionId,
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Get a session in the sandbox.
|
|
180
|
+
*
|
|
181
|
+
* @param {string} sessionId - Unique identifier of the session to retrieve
|
|
182
|
+
* @returns {Promise<Session>} Session information including:
|
|
183
|
+
* - sessionId: The session's unique identifier
|
|
184
|
+
* - commands: List of commands executed in the session
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* const session = await process.getSession('my-session');
|
|
188
|
+
* session.commands.forEach(cmd => {
|
|
189
|
+
* console.log(`Command: ${cmd.command}`);
|
|
190
|
+
* });
|
|
191
|
+
*/
|
|
192
|
+
async getSession(sessionId) {
|
|
193
|
+
const response = await this.toolboxApi.getSession(this.sandboxId, sessionId);
|
|
194
|
+
return response.data;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Gets information about a specific command executed in a session.
|
|
198
|
+
*
|
|
199
|
+
* @param {string} sessionId - Unique identifier of the session
|
|
200
|
+
* @param {string} commandId - Unique identifier of the command
|
|
201
|
+
* @returns {Promise<Command>} Command information including:
|
|
202
|
+
* - id: The command's unique identifier
|
|
203
|
+
* - command: The executed command string
|
|
204
|
+
* - exitCode: Command's exit status (if completed)
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* const cmd = await process.getSessionCommand('my-session', 'cmd-123');
|
|
208
|
+
* if (cmd.exitCode === 0) {
|
|
209
|
+
* console.log(`Command ${cmd.command} completed successfully`);
|
|
210
|
+
* }
|
|
211
|
+
*/
|
|
212
|
+
async getSessionCommand(sessionId, commandId) {
|
|
213
|
+
const response = await this.toolboxApi.getSessionCommand(this.sandboxId, sessionId, commandId);
|
|
214
|
+
return response.data;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Executes a command in an existing session.
|
|
218
|
+
*
|
|
219
|
+
* @param {string} sessionId - Unique identifier of the session to use
|
|
220
|
+
* @param {SessionExecuteRequest} req - Command execution request containing:
|
|
221
|
+
* - command: The command to execute
|
|
222
|
+
* - runAsync: Whether to execute asynchronously
|
|
223
|
+
* @param {number} timeout - Timeout in seconds
|
|
224
|
+
* @returns {Promise<SessionExecuteResponse>} Command execution results containing:
|
|
225
|
+
* - cmdId: Unique identifier for the executed command
|
|
226
|
+
* - output: Command output (if synchronous execution)
|
|
227
|
+
* - exitCode: Command exit status (if synchronous execution)
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* // Execute commands in sequence, maintaining state
|
|
231
|
+
* const sessionId = 'my-session';
|
|
232
|
+
*
|
|
233
|
+
* // Change directory
|
|
234
|
+
* await process.executeSessionCommand(sessionId, {
|
|
235
|
+
* command: 'cd /home/daytona'
|
|
236
|
+
* });
|
|
237
|
+
*
|
|
238
|
+
* // Run command in new directory
|
|
239
|
+
* const result = await process.executeSessionCommand(sessionId, {
|
|
240
|
+
* command: 'pwd'
|
|
241
|
+
* });
|
|
242
|
+
* console.log(result.output); // Prints: /home/daytona
|
|
243
|
+
*/
|
|
244
|
+
async executeSessionCommand(sessionId, req, timeout) {
|
|
245
|
+
const response = await this.toolboxApi.executeSessionCommand(this.sandboxId, sessionId, req, undefined, timeout ? { timeout: timeout * 1000 } : {});
|
|
246
|
+
return response.data;
|
|
247
|
+
}
|
|
248
|
+
async getSessionCommandLogs(sessionId, commandId, onLogs) {
|
|
249
|
+
if (!onLogs) {
|
|
250
|
+
const response = await this.toolboxApi.getSessionCommandLogs(this.sandboxId, sessionId, commandId);
|
|
251
|
+
return response.data;
|
|
252
|
+
}
|
|
253
|
+
await (0, Stream_1.processStreamingResponse)(() => this.toolboxApi.getSessionCommandLogs(this.sandboxId, sessionId, commandId, undefined, true, {
|
|
254
|
+
responseType: 'stream',
|
|
255
|
+
}), onLogs, () => this.getSessionCommand(sessionId, commandId).then((res) => res.exitCode !== null && res.exitCode !== undefined));
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Lists all active sessions in the Sandbox.
|
|
259
|
+
*
|
|
260
|
+
* @returns {Promise<Session[]>} Array of active sessions
|
|
261
|
+
*
|
|
262
|
+
* @example
|
|
263
|
+
* const sessions = await process.listSessions();
|
|
264
|
+
* sessions.forEach(session => {
|
|
265
|
+
* console.log(`Session ${session.sessionId}:`);
|
|
266
|
+
* session.commands.forEach(cmd => {
|
|
267
|
+
* console.log(`- ${cmd.command} (${cmd.exitCode})`);
|
|
268
|
+
* });
|
|
269
|
+
* });
|
|
270
|
+
*/
|
|
271
|
+
async listSessions() {
|
|
272
|
+
const response = await this.toolboxApi.listSessions(this.sandboxId);
|
|
273
|
+
return response.data;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Delete a session from the Sandbox.
|
|
277
|
+
*
|
|
278
|
+
* @param {string} sessionId - Unique identifier of the session to delete
|
|
279
|
+
* @returns {Promise<void>}
|
|
280
|
+
*
|
|
281
|
+
* @example
|
|
282
|
+
* // Clean up a completed session
|
|
283
|
+
* await process.deleteSession('my-session');
|
|
284
|
+
*/
|
|
285
|
+
async deleteSession(sessionId) {
|
|
286
|
+
await this.toolboxApi.deleteSession(this.sandboxId, sessionId);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
exports.Process = Process;
|
|
290
|
+
//# sourceMappingURL=Process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3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CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,KAAK,IAAI,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAClH,CAAA;IACH,CAAC;IAED;;;;;;;;;;;;;OAaG;IACI,KAAK,CAAC,YAAY;QACvB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;QACnE,OAAO,QAAQ,CAAC,IAAI,CAAA;IACtB,CAAC;IAED;;;;;;;;;OASG;IACI,KAAK,CAAC,aAAa,CAAC,SAAiB;QAC1C,MAAM,IAAI,CAAC,UAAU,CAAC,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;IAChE,CAAC;CACF;AAtUD,0BAsUC"}
|
package/src/Sandbox.d.ts
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
import { ToolboxApi, SandboxState, SandboxApi, Sandbox as SandboxDto, PortPreviewUrl, SandboxVolume, BuildInfo, SandboxBackupStateEnum } from '@daytonaio/api-client';
|
|
2
|
+
import { FileSystem } from './FileSystem';
|
|
3
|
+
import { Git } from './Git';
|
|
4
|
+
import { CodeRunParams, Process } from './Process';
|
|
5
|
+
import { LspLanguageId, LspServer } from './LspServer';
|
|
6
|
+
/**
|
|
7
|
+
* Interface defining methods that a code toolbox must implement
|
|
8
|
+
* @interface
|
|
9
|
+
*/
|
|
10
|
+
export interface SandboxCodeToolbox {
|
|
11
|
+
/** Generates a command to run the provided code */
|
|
12
|
+
getRunCommand(code: string, params?: CodeRunParams): string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Represents a Daytona Sandbox.
|
|
16
|
+
*
|
|
17
|
+
* @property {FileSystem} fs - File system operations interface
|
|
18
|
+
* @property {Git} git - Git operations interface
|
|
19
|
+
* @property {Process} process - Process execution interface
|
|
20
|
+
* @property {string} id - Unique identifier for the Sandbox
|
|
21
|
+
* @property {string} organizationId - Organization ID of the Sandbox
|
|
22
|
+
* @property {string} [snapshot] - Daytona snapshot used to create the Sandbox
|
|
23
|
+
* @property {string} user - OS user running in the Sandbox
|
|
24
|
+
* @property {Record<string, string>} env - Environment variables set in the Sandbox
|
|
25
|
+
* @property {Record<string, string>} labels - Custom labels attached to the Sandbox
|
|
26
|
+
* @property {boolean} public - Whether the Sandbox is publicly accessible
|
|
27
|
+
* @property {string} target - Target location of the runner where the Sandbox runs
|
|
28
|
+
* @property {number} cpu - Number of CPUs allocated to the Sandbox
|
|
29
|
+
* @property {number} gpu - Number of GPUs allocated to the Sandbox
|
|
30
|
+
* @property {number} memory - Amount of memory allocated to the Sandbox in GiB
|
|
31
|
+
* @property {number} disk - Amount of disk space allocated to the Sandbox in GiB
|
|
32
|
+
* @property {SandboxState} state - Current state of the Sandbox (e.g., "started", "stopped")
|
|
33
|
+
* @property {string} [errorReason] - Error message if Sandbox is in error state
|
|
34
|
+
* @property {SandboxBackupStateEnum} [backupState] - Current state of Sandbox backup
|
|
35
|
+
* @property {string} [backupCreatedAt] - When the backup was created
|
|
36
|
+
* @property {number} [autoStopInterval] - Auto-stop interval in minutes
|
|
37
|
+
* @property {number} [autoArchiveInterval] - Auto-archive interval in minutes
|
|
38
|
+
* @property {string} [runnerDomain] - Domain name of the Sandbox runner
|
|
39
|
+
* @property {Array<SandboxVolume>} [volumes] - Volumes attached to the Sandbox
|
|
40
|
+
* @property {BuildInfo} [buildInfo] - Build information for the Sandbox if it was created from dynamic build
|
|
41
|
+
* @property {string} [createdAt] - When the Sandbox was created
|
|
42
|
+
* @property {string} [updatedAt] - When the Sandbox was last updated
|
|
43
|
+
*
|
|
44
|
+
* @class
|
|
45
|
+
*/
|
|
46
|
+
export declare class Sandbox implements SandboxDto {
|
|
47
|
+
private readonly sandboxApi;
|
|
48
|
+
private readonly toolboxApi;
|
|
49
|
+
private readonly codeToolbox;
|
|
50
|
+
readonly fs: FileSystem;
|
|
51
|
+
readonly git: Git;
|
|
52
|
+
readonly process: Process;
|
|
53
|
+
id: string;
|
|
54
|
+
organizationId: string;
|
|
55
|
+
snapshot?: string;
|
|
56
|
+
user: string;
|
|
57
|
+
env: Record<string, string>;
|
|
58
|
+
labels: Record<string, string>;
|
|
59
|
+
public: boolean;
|
|
60
|
+
target: string;
|
|
61
|
+
cpu: number;
|
|
62
|
+
gpu: number;
|
|
63
|
+
memory: number;
|
|
64
|
+
disk: number;
|
|
65
|
+
state?: SandboxState;
|
|
66
|
+
errorReason?: string;
|
|
67
|
+
backupState?: SandboxBackupStateEnum;
|
|
68
|
+
backupCreatedAt?: string;
|
|
69
|
+
autoStopInterval?: number;
|
|
70
|
+
autoArchiveInterval?: number;
|
|
71
|
+
runnerDomain?: string;
|
|
72
|
+
volumes?: Array<SandboxVolume>;
|
|
73
|
+
buildInfo?: BuildInfo;
|
|
74
|
+
createdAt?: string;
|
|
75
|
+
updatedAt?: string;
|
|
76
|
+
private rootDir;
|
|
77
|
+
/**
|
|
78
|
+
* Creates a new Sandbox instance
|
|
79
|
+
*
|
|
80
|
+
* @param {SandboxDto} sandboxDto - The API Sandbox instance
|
|
81
|
+
* @param {SandboxApi} sandboxApi - API client for Sandbox operations
|
|
82
|
+
* @param {ToolboxApi} toolboxApi - API client for toolbox operations
|
|
83
|
+
* @param {SandboxCodeToolbox} codeToolbox - Language-specific toolbox implementation
|
|
84
|
+
*/
|
|
85
|
+
constructor(sandboxDto: SandboxDto, sandboxApi: SandboxApi, toolboxApi: ToolboxApi, codeToolbox: SandboxCodeToolbox);
|
|
86
|
+
/**
|
|
87
|
+
* Gets the root directory path for the logged in user inside the Sandbox.
|
|
88
|
+
*
|
|
89
|
+
* @returns {Promise<string | undefined>} The absolute path to the Sandbox root directory for the logged in user
|
|
90
|
+
*
|
|
91
|
+
* @example
|
|
92
|
+
* const rootDir = await sandbox.getUserRootDir();
|
|
93
|
+
* console.log(`Sandbox root: ${rootDir}`);
|
|
94
|
+
*/
|
|
95
|
+
getUserRootDir(): Promise<string | undefined>;
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new Language Server Protocol (LSP) server instance.
|
|
98
|
+
*
|
|
99
|
+
* The LSP server provides language-specific features like code completion,
|
|
100
|
+
* diagnostics, and more.
|
|
101
|
+
*
|
|
102
|
+
* @param {LspLanguageId} languageId - The language server type (e.g., "typescript")
|
|
103
|
+
* @param {string} pathToProject - Path to the project root directory. Relative paths are resolved based on the user's
|
|
104
|
+
* root directory.
|
|
105
|
+
* @returns {LspServer} A new LSP server instance configured for the specified language
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* const lsp = await sandbox.createLspServer('typescript', 'workspace/project');
|
|
109
|
+
*/
|
|
110
|
+
createLspServer(languageId: LspLanguageId | string, pathToProject: string): Promise<LspServer>;
|
|
111
|
+
/**
|
|
112
|
+
* Sets labels for the Sandbox.
|
|
113
|
+
*
|
|
114
|
+
* Labels are key-value pairs that can be used to organize and identify Sandboxes.
|
|
115
|
+
*
|
|
116
|
+
* @param {Record<string, string>} labels - Dictionary of key-value pairs representing Sandbox labels
|
|
117
|
+
* @returns {Promise<void>}
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* // Set sandbox labels
|
|
121
|
+
* await sandbox.setLabels({
|
|
122
|
+
* project: 'my-project',
|
|
123
|
+
* environment: 'development',
|
|
124
|
+
* team: 'backend'
|
|
125
|
+
* });
|
|
126
|
+
*/
|
|
127
|
+
setLabels(labels: Record<string, string>): Promise<Record<string, string>>;
|
|
128
|
+
/**
|
|
129
|
+
* Start the Sandbox.
|
|
130
|
+
*
|
|
131
|
+
* This method starts the Sandbox and waits for it to be ready.
|
|
132
|
+
*
|
|
133
|
+
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
134
|
+
* Defaults to 60-second timeout.
|
|
135
|
+
* @returns {Promise<void>}
|
|
136
|
+
* @throws {DaytonaError} - `DaytonaError` - If Sandbox fails to start or times out
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* const sandbox = await daytona.getCurrentSandbox('my-sandbox');
|
|
140
|
+
* await sandbox.start(40); // Wait up to 40 seconds
|
|
141
|
+
* console.log('Sandbox started successfully');
|
|
142
|
+
*/
|
|
143
|
+
start(timeout?: number): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Stops the Sandbox.
|
|
146
|
+
*
|
|
147
|
+
* This method stops the Sandbox and waits for it to be fully stopped.
|
|
148
|
+
*
|
|
149
|
+
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
150
|
+
* Defaults to 60-second timeout.
|
|
151
|
+
* @returns {Promise<void>}
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* const sandbox = await daytona.getCurrentSandbox('my-sandbox');
|
|
155
|
+
* await sandbox.stop();
|
|
156
|
+
* console.log('Sandbox stopped successfully');
|
|
157
|
+
*/
|
|
158
|
+
stop(timeout?: number): Promise<void>;
|
|
159
|
+
/**
|
|
160
|
+
* Deletes the Sandbox.
|
|
161
|
+
* @returns {Promise<void>}
|
|
162
|
+
*/
|
|
163
|
+
delete(timeout?: number): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Waits for the Sandbox to reach the 'started' state.
|
|
166
|
+
*
|
|
167
|
+
* This method polls the Sandbox status until it reaches the 'started' state
|
|
168
|
+
* or encounters an error.
|
|
169
|
+
*
|
|
170
|
+
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
171
|
+
* Defaults to 60 seconds.
|
|
172
|
+
* @returns {Promise<void>}
|
|
173
|
+
* @throws {DaytonaError} - `DaytonaError` - If the sandbox ends up in an error state or fails to start within the timeout period.
|
|
174
|
+
*/
|
|
175
|
+
waitUntilStarted(timeout?: number): Promise<void>;
|
|
176
|
+
/**
|
|
177
|
+
* Wait for Sandbox to reach 'stopped' state.
|
|
178
|
+
*
|
|
179
|
+
* This method polls the Sandbox status until it reaches the 'stopped' state
|
|
180
|
+
* or encounters an error.
|
|
181
|
+
*
|
|
182
|
+
* @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
|
|
183
|
+
* Defaults to 60 seconds.
|
|
184
|
+
* @returns {Promise<void>}
|
|
185
|
+
* @throws {DaytonaError} - `DaytonaError` - If the sandbox fails to stop within the timeout period.
|
|
186
|
+
*/
|
|
187
|
+
waitUntilStopped(timeout?: number): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* Refreshes the Sandbox data from the API.
|
|
190
|
+
*
|
|
191
|
+
* @returns {Promise<void>}
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* await sandbox.refreshData();
|
|
195
|
+
* console.log(`Sandbox ${sandbox.id}:`);
|
|
196
|
+
* console.log(`State: ${sandbox.state}`);
|
|
197
|
+
* console.log(`Resources: ${sandbox.cpu} CPU, ${sandbox.memory} GiB RAM`);
|
|
198
|
+
*/
|
|
199
|
+
refreshData(): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Set the auto-stop interval for the Sandbox.
|
|
202
|
+
*
|
|
203
|
+
* The Sandbox will automatically stop after being idle (no new events) for the specified interval.
|
|
204
|
+
* Events include any state changes or interactions with the Sandbox through the sdk.
|
|
205
|
+
* Interactions using Sandbox Previews are not included.
|
|
206
|
+
*
|
|
207
|
+
* @param {number} interval - Number of minutes of inactivity before auto-stopping.
|
|
208
|
+
* Set to 0 to disable auto-stop. Default is 15 minutes.
|
|
209
|
+
* @returns {Promise<void>}
|
|
210
|
+
* @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
|
|
211
|
+
*
|
|
212
|
+
* @example
|
|
213
|
+
* // Auto-stop after 1 hour
|
|
214
|
+
* await sandbox.setAutostopInterval(60);
|
|
215
|
+
* // Or disable auto-stop
|
|
216
|
+
* await sandbox.setAutostopInterval(0);
|
|
217
|
+
*/
|
|
218
|
+
setAutostopInterval(interval: number): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Set the auto-archive interval for the Sandbox.
|
|
221
|
+
*
|
|
222
|
+
* The Sandbox will automatically archive after being continuously stopped for the specified interval.
|
|
223
|
+
*
|
|
224
|
+
* @param {number} interval - Number of minutes after which a continuously stopped Sandbox will be auto-archived.
|
|
225
|
+
* Set to 0 for the maximum interval. Default is 7 days.
|
|
226
|
+
* @returns {Promise<void>}
|
|
227
|
+
* @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* // Auto-archive after 1 hour
|
|
231
|
+
* await sandbox.setAutoArchiveInterval(60);
|
|
232
|
+
* // Or use the maximum interval
|
|
233
|
+
* await sandbox.setAutoArchiveInterval(0);
|
|
234
|
+
*/
|
|
235
|
+
setAutoArchiveInterval(interval: number): Promise<void>;
|
|
236
|
+
/**
|
|
237
|
+
* Retrieves the preview link for the sandbox at the specified port. If the port is closed,
|
|
238
|
+
* it will be opened automatically. For private sandboxes, a token is included to grant access
|
|
239
|
+
* to the URL.
|
|
240
|
+
*
|
|
241
|
+
* @param {number} port - The port to open the preview link on.
|
|
242
|
+
* @returns {PortPreviewUrl} The response object for the preview link, which includes the `url`
|
|
243
|
+
* and the `token` (to access private sandboxes).
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* const previewLink = await sandbox.getPreviewLink(3000);
|
|
247
|
+
* console.log(`Preview URL: ${previewLink.url}`);
|
|
248
|
+
* console.log(`Token: ${previewLink.token}`);
|
|
249
|
+
*/
|
|
250
|
+
getPreviewLink(port: number): Promise<PortPreviewUrl>;
|
|
251
|
+
/**
|
|
252
|
+
* Archives the sandbox, making it inactive and preserving its state. When sandboxes are archived, the entire filesystem
|
|
253
|
+
* state is moved to cost-effective object storage, making it possible to keep sandboxes available for an extended period.
|
|
254
|
+
* The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size.
|
|
255
|
+
* Sandbox must be stopped before archiving.
|
|
256
|
+
*/
|
|
257
|
+
archive(): Promise<void>;
|
|
258
|
+
private getRootDir;
|
|
259
|
+
/**
|
|
260
|
+
* Assigns the API sandbox data to the Sandbox object.
|
|
261
|
+
*
|
|
262
|
+
* @param {SandboxDto} sandboxDto - The API sandbox instance to assign data from
|
|
263
|
+
* @returns {void}
|
|
264
|
+
*/
|
|
265
|
+
private processSandboxDto;
|
|
266
|
+
}
|