@daytonaio/sdk 0.14.0 → 0.16.0-alpha.0

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 CHANGED
@@ -34,7 +34,7 @@ const response = await sandbox.process.codeRun('console.log("Hello World!")')
34
34
  console.log(response.result)
35
35
 
36
36
  // Clean up when done
37
- await daytona.remove(sandbox)
37
+ await daytona.delete(sandbox)
38
38
  ```
39
39
 
40
40
  ## Configuration
package/dist/Daytona.d.ts CHANGED
@@ -1,5 +1,18 @@
1
- import { CreateWorkspaceTargetEnum as SandboxTargetRegion } from '@daytonaio/api-client';
1
+ import { CreateWorkspaceTargetEnum as SandboxTargetRegion, WorkspaceVolume } from '@daytonaio/api-client';
2
2
  import { Sandbox, Sandbox as Workspace } from './Sandbox';
3
+ import { VolumeService } from './Volume';
4
+ /**
5
+ * Represents a volume mount for a Sandbox.
6
+ *
7
+ * @interface
8
+ * @property {string} volumeId - ID of the Volume to mount
9
+ * @property {string} mountPath - Path on the Sandbox to mount the Volume
10
+ * @extends {WorkspaceVolume}
11
+ */
12
+ export interface VolumeMount extends WorkspaceVolume {
13
+ volumeId: string;
14
+ mountPath: string;
15
+ }
3
16
  /**
4
17
  * Configuration options for initializing the Daytona client.
5
18
  *
@@ -76,7 +89,6 @@ export interface SandboxResources {
76
89
  * Parameters for creating a new Sandbox.
77
90
  *
78
91
  * @interface
79
- * @property {string} [id] - Optional Sandbox ID. If not provided, a random ID will be generated
80
92
  * @property {string} [image] - Optional Docker image to use for the Sandbox
81
93
  * @property {string} [user] - Optional os user to use for the Sandbox
82
94
  * @property {CodeLanguage | string} [language] - Programming language for direct code execution
@@ -102,8 +114,6 @@ export interface SandboxResources {
102
114
  * const sandbox = await daytona.create(params, 50);
103
115
  */
104
116
  export type CreateSandboxParams = {
105
- /** Optional Sandbox ID. If not provided, a random ID will be generated */
106
- id?: string;
107
117
  /** Optional Docker image to use for the Sandbox */
108
118
  image?: string;
109
119
  /** Optional os user to use for the Sandbox */
@@ -129,13 +139,26 @@ export type CreateSandboxParams = {
129
139
  timeout?: number;
130
140
  /** Auto-stop interval in minutes (0 means disabled) (must be a non-negative integer) */
131
141
  autoStopInterval?: number;
142
+ /** List of volumes to mount in the Sandbox */
143
+ volumes?: VolumeMount[];
132
144
  };
133
145
  /**
134
- * Main class for interacting with the Daytona API.
146
+ * Filter for Sandboxes.
135
147
  *
148
+ * @interface
149
+ * @property {string} [id] - The ID of the Sandbox to retrieve
150
+ * @property {Record<string, string>} [labels] - Labels to filter Sandboxes
151
+ */
152
+ export type SandboxFilter = {
153
+ id?: string;
154
+ labels?: Record<string, string>;
155
+ };
156
+ /**
157
+ * Main class for interacting with the Daytona API.
136
158
  * Provides methods for creating, managing, and interacting with Daytona Sandboxes.
137
159
  * Can be initialized either with explicit configuration or using environment variables.
138
160
  *
161
+ * @property {VolumeService} volume - Service for managing Daytona Volumes
139
162
  *
140
163
  * @example
141
164
  * // Using environment variables
@@ -162,6 +185,7 @@ export declare class Daytona {
162
185
  private readonly jwtToken?;
163
186
  private readonly organizationId?;
164
187
  private readonly apiUrl;
188
+ readonly volume: VolumeService;
165
189
  /**
166
190
  * Creates a new Daytona client instance.
167
191
  *
@@ -211,17 +235,29 @@ export declare class Daytona {
211
235
  */
212
236
  get(sandboxId: string): Promise<Sandbox>;
213
237
  /**
214
- * Lists all Sandboxes.
238
+ * Finds a Sandbox by its ID or labels.
239
+ *
240
+ * @param {SandboxFilter} filter - Filter for Sandboxes
241
+ * @returns {Promise<Sandbox>} First Sandbox that matches the ID or labels.
242
+ *
243
+ * @example
244
+ * const sandbox = await daytona.findOne({ labels: { 'my-label': 'my-value' } });
245
+ * console.log(`Sandbox: ${await sandbox.info()}`);
246
+ */
247
+ findOne(filter: SandboxFilter): Promise<Sandbox>;
248
+ /**
249
+ * Lists all Sandboxes filtered by labels.
215
250
  *
216
- * @returns {Promise<Sandbox[]>} Array of Sandboxes
251
+ * @param {Record<string, string>} [labels] - Labels to filter Sandboxes
252
+ * @returns {Promise<Sandbox[]>} Array of Sandboxes that match the labels.
217
253
  *
218
254
  * @example
219
- * const sandboxes = await daytona.list();
255
+ * const sandboxes = await daytona.list({ 'my-label': 'my-value' });
220
256
  * for (const sandbox of sandboxes) {
221
257
  * console.log(`${sandbox.id}: ${sandbox.instance.state}`);
222
258
  * }
223
259
  */
224
- list(): Promise<Sandbox[]>;
260
+ list(labels?: Record<string, string>): Promise<Sandbox[]>;
225
261
  /**
226
262
  * Starts a Sandbox and waits for it to be ready.
227
263
  *
@@ -247,17 +283,19 @@ export declare class Daytona {
247
283
  */
248
284
  stop(sandbox: Sandbox): Promise<void>;
249
285
  /**
250
- * Removes a Sandbox.
286
+ * Deletes a Sandbox.
251
287
  *
252
- * @param {Sandbox} sandbox - The Sandbox to remove
288
+ * @param {Sandbox} sandbox - The Sandbox to delete
253
289
  * @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
254
290
  * @returns {Promise<void>}
255
291
  *
256
292
  * @example
257
293
  * const sandbox = await daytona.get('my-sandbox-id');
258
- * await daytona.remove(sandbox);
294
+ * await daytona.delete(sandbox);
259
295
  */
260
- remove(sandbox: Sandbox, timeout?: number): Promise<void>;
296
+ delete(sandbox: Sandbox, timeout?: number): Promise<void>;
297
+ /** @hidden */
298
+ remove: (sandbox: Sandbox, timeout?: number) => Promise<void>;
261
299
  /**
262
300
  * Gets the Sandbox by ID.
263
301
  *
package/dist/Daytona.js CHANGED
@@ -44,6 +44,7 @@ const SandboxPythonCodeToolbox_1 = require("./code-toolbox/SandboxPythonCodeTool
44
44
  const SandboxTsCodeToolbox_1 = require("./code-toolbox/SandboxTsCodeToolbox");
45
45
  const DaytonaError_1 = require("./errors/DaytonaError");
46
46
  const Sandbox_1 = require("./Sandbox");
47
+ const Volume_1 = require("./Volume");
47
48
  /**
48
49
  * Supported programming languages for code execution
49
50
  */
@@ -55,10 +56,10 @@ var CodeLanguage;
55
56
  })(CodeLanguage || (exports.CodeLanguage = CodeLanguage = {}));
56
57
  /**
57
58
  * Main class for interacting with the Daytona API.
58
- *
59
59
  * Provides methods for creating, managing, and interacting with Daytona Sandboxes.
60
60
  * Can be initialized either with explicit configuration or using environment variables.
61
61
  *
62
+ * @property {VolumeService} volume - Service for managing Daytona Volumes
62
63
  *
63
64
  * @example
64
65
  * // Using environment variables
@@ -86,6 +87,7 @@ class Daytona {
86
87
  */
87
88
  constructor(config) {
88
89
  var _a, _b, _c, _d, _e, _f, _g, _h;
90
+ this.remove = this.delete.bind(this);
89
91
  dotenv_1.default.config();
90
92
  dotenv_1.default.config({ path: '.env.local', override: true });
91
93
  const apiKey = !(config === null || config === void 0 ? void 0 : config.apiKey) && (config === null || config === void 0 ? void 0 : config.jwtToken) ? undefined : (config === null || config === void 0 ? void 0 : config.apiKey) || ((_a = process === null || process === void 0 ? void 0 : process.env) === null || _a === void 0 ? void 0 : _a.DAYTONA_API_KEY);
@@ -148,6 +150,7 @@ class Daytona {
148
150
  });
149
151
  this.sandboxApi = new api_client_1.WorkspaceApi(configuration, '', axiosInstance);
150
152
  this.toolboxApi = new api_client_1.ToolboxApi(configuration, '', axiosInstance);
153
+ this.volume = new Volume_1.VolumeService(new api_client_1.VolumesApi(configuration, '', axiosInstance));
151
154
  }
152
155
  /**
153
156
  * Creates Sandboxes with default or custom configurations. You can specify various parameters,
@@ -200,8 +203,6 @@ class Daytona {
200
203
  const codeToolbox = this.getCodeToolbox(params.language);
201
204
  try {
202
205
  const response = await this.sandboxApi.createWorkspace({
203
- id: params.id,
204
- name: params.id,
205
206
  image: params.image,
206
207
  user: params.user,
207
208
  env: params.envVars || {},
@@ -213,12 +214,16 @@ class Daytona {
213
214
  memory: (_c = params.resources) === null || _c === void 0 ? void 0 : _c.memory,
214
215
  disk: (_d = params.resources) === null || _d === void 0 ? void 0 : _d.disk,
215
216
  autoStopInterval: params.autoStopInterval,
217
+ volumes: params.volumes,
216
218
  }, undefined, {
217
219
  timeout: effectiveTimeout * 1000,
218
220
  });
219
221
  const sandboxInstance = response.data;
220
222
  const sandboxInfo = Sandbox_1.Sandbox.toSandboxInfo(sandboxInstance);
221
- sandboxInstance.info = sandboxInfo;
223
+ sandboxInstance.info = {
224
+ ...sandboxInfo,
225
+ name: '',
226
+ };
222
227
  const sandbox = new Sandbox_1.Sandbox(sandboxInstance.id, sandboxInstance, this.sandboxApi, this.toolboxApi, codeToolbox);
223
228
  // if (!params.async) {
224
229
  // const timeElapsed = Date.now() - startTime;
@@ -227,7 +232,6 @@ class Daytona {
227
232
  return sandbox;
228
233
  }
229
234
  catch (error) {
230
- void this.sandboxApi.deleteWorkspace(params.id, true).catch(() => { });
231
235
  if (error instanceof DaytonaError_1.DaytonaError && error.message.includes('Operation timed out')) {
232
236
  throw new DaytonaError_1.DaytonaError(`Failed to create and start sandbox within ${effectiveTimeout} seconds. Operation timed out.`);
233
237
  }
@@ -250,27 +254,54 @@ class Daytona {
250
254
  const language = sandboxInstance.labels && sandboxInstance.labels['code-toolbox-language'];
251
255
  const codeToolbox = this.getCodeToolbox(language);
252
256
  const sandboxInfo = Sandbox_1.Sandbox.toSandboxInfo(sandboxInstance);
253
- sandboxInstance.info = sandboxInfo;
257
+ sandboxInstance.info = {
258
+ ...sandboxInfo,
259
+ name: '',
260
+ };
254
261
  return new Sandbox_1.Sandbox(sandboxId, sandboxInstance, this.sandboxApi, this.toolboxApi, codeToolbox);
255
262
  }
256
263
  /**
257
- * Lists all Sandboxes.
264
+ * Finds a Sandbox by its ID or labels.
265
+ *
266
+ * @param {SandboxFilter} filter - Filter for Sandboxes
267
+ * @returns {Promise<Sandbox>} First Sandbox that matches the ID or labels.
268
+ *
269
+ * @example
270
+ * const sandbox = await daytona.findOne({ labels: { 'my-label': 'my-value' } });
271
+ * console.log(`Sandbox: ${await sandbox.info()}`);
272
+ */
273
+ async findOne(filter) {
274
+ if (filter.id) {
275
+ return this.get(filter.id);
276
+ }
277
+ const sandboxes = await this.list(filter.labels);
278
+ if (sandboxes.length === 0) {
279
+ throw new DaytonaError_1.DaytonaError(`No sandbox found with labels ${JSON.stringify(filter.labels)}`);
280
+ }
281
+ return sandboxes[0];
282
+ }
283
+ /**
284
+ * Lists all Sandboxes filtered by labels.
258
285
  *
259
- * @returns {Promise<Sandbox[]>} Array of Sandboxes
286
+ * @param {Record<string, string>} [labels] - Labels to filter Sandboxes
287
+ * @returns {Promise<Sandbox[]>} Array of Sandboxes that match the labels.
260
288
  *
261
289
  * @example
262
- * const sandboxes = await daytona.list();
290
+ * const sandboxes = await daytona.list({ 'my-label': 'my-value' });
263
291
  * for (const sandbox of sandboxes) {
264
292
  * console.log(`${sandbox.id}: ${sandbox.instance.state}`);
265
293
  * }
266
294
  */
267
- async list() {
268
- const response = await this.sandboxApi.listWorkspaces();
295
+ async list(labels) {
296
+ const response = await this.sandboxApi.listWorkspaces(undefined, undefined, labels ? JSON.stringify(labels) : undefined);
269
297
  return response.data.map((sandbox) => {
270
298
  var _a;
271
299
  const language = (_a = sandbox.labels) === null || _a === void 0 ? void 0 : _a['code-toolbox-language'];
272
300
  const sandboxInfo = Sandbox_1.Sandbox.toSandboxInfo(sandbox);
273
- sandbox.info = sandboxInfo;
301
+ sandbox.info = {
302
+ ...sandboxInfo,
303
+ name: '',
304
+ };
274
305
  return new Sandbox_1.Sandbox(sandbox.id, sandbox, this.sandboxApi, this.toolboxApi, this.getCodeToolbox(language));
275
306
  });
276
307
  }
@@ -303,17 +334,17 @@ class Daytona {
303
334
  await sandbox.stop();
304
335
  }
305
336
  /**
306
- * Removes a Sandbox.
337
+ * Deletes a Sandbox.
307
338
  *
308
- * @param {Sandbox} sandbox - The Sandbox to remove
339
+ * @param {Sandbox} sandbox - The Sandbox to delete
309
340
  * @param {number} timeout - Timeout in seconds (0 means no timeout, default is 60)
310
341
  * @returns {Promise<void>}
311
342
  *
312
343
  * @example
313
344
  * const sandbox = await daytona.get('my-sandbox-id');
314
- * await daytona.remove(sandbox);
345
+ * await daytona.delete(sandbox);
315
346
  */
316
- async remove(sandbox, timeout = 60) {
347
+ async delete(sandbox, timeout = 60) {
317
348
  await this.sandboxApi.deleteWorkspace(sandbox.id, true, undefined, { timeout: timeout * 1000 });
318
349
  }
319
350
  /**
package/dist/Process.js CHANGED
@@ -45,21 +45,23 @@ class Process {
45
45
  * const result = await process.executeCommand('sleep 10', undefined, 5);
46
46
  */
47
47
  async executeCommand(command, cwd, env, timeout) {
48
- const envVars = env
49
- ? Object.entries(env)
50
- .map(([key, value]) => `${key}=${value}`)
51
- .join(' ')
52
- : undefined;
53
- if (envVars) {
54
- const base64Cmd = Buffer.from(command).toString('base64');
55
- command = `sh -c '${envVars} sh -c "echo '${base64Cmd}' | base64 -d | sh"'`;
48
+ const base64UserCmd = Buffer.from(command).toString('base64');
49
+ command = `echo '${base64UserCmd}' | base64 -d | sh`;
50
+ if (env && Object.keys(env).length > 0) {
51
+ const safeEnvExports = Object.entries(env)
52
+ .map(([key, value]) => {
53
+ const encodedValue = Buffer.from(value).toString('base64');
54
+ return `export ${key}=$(echo '${encodedValue}' | base64 -d)`;
55
+ })
56
+ .join(';') + ';';
57
+ command = `${safeEnvExports} ${command}`;
56
58
  }
59
+ command = `sh -c "${command}"`;
57
60
  const response = await this.toolboxApi.executeCommand(this.instance.id, {
58
61
  command,
59
62
  timeout,
60
63
  cwd,
61
64
  });
62
- // console.log(response)
63
65
  // Parse artifacts from the output
64
66
  const artifacts = ArtifactParser_1.ArtifactParser.parseArtifacts(response.data.result);
65
67
  // Return enhanced response with parsed artifacts
@@ -129,7 +131,7 @@ class Process {
129
131
  */
130
132
  async codeRun(code, params, timeout) {
131
133
  const runCommand = this.codeToolbox.getRunCommand(code, params);
132
- return this.executeCommand(runCommand, undefined, undefined, timeout);
134
+ return this.executeCommand(runCommand, undefined, params === null || params === void 0 ? void 0 : params.env, timeout);
133
135
  }
134
136
  /**
135
137
  * Creates a new long-running background session in the Sandbox.
package/dist/Sandbox.d.ts CHANGED
@@ -43,7 +43,6 @@ export interface SandboxResources {
43
43
  *
44
44
  * @interface
45
45
  * @property {string} id - Unique identifier for the Sandbox
46
- * @property {string} name - Display name of the Sandbox
47
46
  * @property {string} image - Docker image used for the Sandbox
48
47
  * @property {string} user - OS user running in the Sandbox
49
48
  * @property {Record<string, string>} env - Environment variables set in the Sandbox
@@ -54,7 +53,7 @@ export interface SandboxResources {
54
53
  * @property {string} state - Current state of the Sandbox (e.g., "started", "stopped")
55
54
  * @property {string | null} errorReason - Error message if Sandbox is in error state
56
55
  * @property {string | null} snapshotState - Current state of Sandbox snapshot
57
- * @property {Date | null} snapshotCreatedAt - When the snapshot was created
56
+ * @property {string | null} snapshotCreatedAt - When the snapshot was created
58
57
  * @property {string} nodeDomain - Domain name of the Sandbox node
59
58
  * @property {string} region - Region of the Sandbox node
60
59
  * @property {string} class - Sandbox class
@@ -65,14 +64,12 @@ export interface SandboxResources {
65
64
  * @example
66
65
  * const sandbox = await daytona.create();
67
66
  * const info = await sandbox.info();
68
- * console.log(`Sandbox ${info.name} is ${info.state}`);
67
+ * console.log(`Sandbox ${info.id} is ${info.state}`);
69
68
  * console.log(`Resources: ${info.resources.cpu} CPU, ${info.resources.memory} RAM`);
70
69
  */
71
- export interface SandboxInfo extends ApiSandboxInfo {
70
+ export interface SandboxInfo extends Omit<ApiSandboxInfo, 'name'> {
72
71
  /** Unique identifier */
73
72
  id: string;
74
- /** Sandbox name */
75
- name: string;
76
73
  /** Docker image */
77
74
  image: string;
78
75
  /** OS user */
@@ -93,8 +90,8 @@ export interface SandboxInfo extends ApiSandboxInfo {
93
90
  errorReason: string | null;
94
91
  /** Snapshot state */
95
92
  snapshotState: string | null;
96
- /** Snapshot creation timestamp */
97
- snapshotCreatedAt: Date | null;
93
+ /** Snapshot creation time */
94
+ snapshotCreatedAt: string | null;
98
95
  /** Node domain */
99
96
  nodeDomain: string;
100
97
  /** Region */
@@ -269,7 +266,7 @@ export declare class Sandbox {
269
266
  *
270
267
  * @example
271
268
  * const info = await sandbox.info();
272
- * console.log(`Sandbox ${info.name}:`);
269
+ * console.log(`Sandbox ${info.id}:`);
273
270
  * console.log(`State: ${info.state}`);
274
271
  * console.log(`Resources: ${info.resources.cpu} CPU, ${info.resources.memory} RAM`);
275
272
  */
package/dist/Sandbox.js CHANGED
@@ -217,7 +217,7 @@ class Sandbox {
217
217
  *
218
218
  * @example
219
219
  * const info = await sandbox.info();
220
- * console.log(`Sandbox ${info.name}:`);
220
+ * console.log(`Sandbox ${info.id}:`);
221
221
  * console.log(`State: ${info.state}`);
222
222
  * console.log(`Resources: ${info.resources.cpu} CPU, ${info.resources.memory} RAM`);
223
223
  */
@@ -255,7 +255,6 @@ class Sandbox {
255
255
  };
256
256
  return {
257
257
  id: instance.id,
258
- name: instance.name,
259
258
  image: instance.image,
260
259
  user: instance.user,
261
260
  env: instance.env || {},
@@ -266,7 +265,7 @@ class Sandbox {
266
265
  state: instance.state || api_client_1.WorkspaceState.UNKNOWN,
267
266
  errorReason: instance.errorReason || null,
268
267
  snapshotState: instance.snapshotState || null,
269
- snapshotCreatedAt: instance.snapshotCreatedAt ? new Date(instance.snapshotCreatedAt) : null,
268
+ snapshotCreatedAt: instance.snapshotCreatedAt || null,
270
269
  autoStopInterval: instance.autoStopInterval || 15,
271
270
  created: ((_d = instance.info) === null || _d === void 0 ? void 0 : _d.created) || '',
272
271
  nodeDomain: providerMetadata.nodeDomain || '',
@@ -0,0 +1,78 @@
1
+ import { VolumeDto, VolumesApi } from '@daytonaio/api-client';
2
+ /**
3
+ * Represents a Daytona Volume which is a shared storage volume for Sandboxes.
4
+ *
5
+ * @property {string} id - Unique identifier for the Volume
6
+ * @property {string} name - Name of the Volume
7
+ * @property {string} organizationId - Organization ID that owns the Volume
8
+ * @property {string} state - Current state of the Volume
9
+ * @property {string} createdAt - Date and time when the Volume was created
10
+ * @property {string} updatedAt - Date and time when the Volume was last updated
11
+ * @property {string} lastUsedAt - Date and time when the Volume was last used
12
+ */
13
+ export type Volume = VolumeDto & {
14
+ __brand: 'Volume';
15
+ };
16
+ /**
17
+ * Service for managing Daytona Volumes.
18
+ *
19
+ * This service provides methods to list, get, create, and delete Volumes.
20
+ *
21
+ * @class
22
+ */
23
+ export declare class VolumeService {
24
+ private volumesApi;
25
+ constructor(volumesApi: VolumesApi);
26
+ /**
27
+ * Lists all available Volumes.
28
+ *
29
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
30
+ *
31
+ * @example
32
+ * const daytona = new Daytona();
33
+ * const volumes = await daytona.volume.list();
34
+ * console.log(`Found ${volumes.length} volumes`);
35
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
36
+ */
37
+ list(): Promise<Volume[]>;
38
+ /**
39
+ * Gets a Volume by its name.
40
+ *
41
+ * @param {string} name - Name of the Volume to retrieve
42
+ * @returns {Promise<Volume>} The requested Volume
43
+ * @throws {Error} If the Volume does not exist or cannot be accessed
44
+ *
45
+ * @example
46
+ * const daytona = new Daytona();
47
+ * const volume = await daytona.volume.get("volume-name");
48
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
49
+ */
50
+ get(name: string): Promise<Volume>;
51
+ /**
52
+ * Creates a new Volume with the specified name.
53
+ *
54
+ * @param {string} name - Name for the new Volume
55
+ * @returns {Promise<Volume>} The newly created Volume
56
+ * @throws {Error} If the Volume cannot be created
57
+ *
58
+ * @example
59
+ * const daytona = new Daytona();
60
+ * const volume = await daytona.volume.create("my-data-volume");
61
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
62
+ */
63
+ create(name: string): Promise<Volume>;
64
+ /**
65
+ * Deletes a Volume.
66
+ *
67
+ * @param {Volume} volume - Volume to delete
68
+ * @returns {Promise<void>}
69
+ * @throws {Error} If the Volume does not exist or cannot be deleted
70
+ *
71
+ * @example
72
+ * const daytona = new Daytona();
73
+ * const volume = await daytona.volume.get("volume-name");
74
+ * await daytona.volume.delete(volume);
75
+ * console.log("Volume deleted successfully");
76
+ */
77
+ delete(volume: Volume): Promise<void>;
78
+ }
package/dist/Volume.js ADDED
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.VolumeService = void 0;
4
+ /**
5
+ * Service for managing Daytona Volumes.
6
+ *
7
+ * This service provides methods to list, get, create, and delete Volumes.
8
+ *
9
+ * @class
10
+ */
11
+ class VolumeService {
12
+ constructor(volumesApi) {
13
+ this.volumesApi = volumesApi;
14
+ }
15
+ /**
16
+ * Lists all available Volumes.
17
+ *
18
+ * @returns {Promise<Volume[]>} List of all Volumes accessible to the user
19
+ *
20
+ * @example
21
+ * const daytona = new Daytona();
22
+ * const volumes = await daytona.volume.list();
23
+ * console.log(`Found ${volumes.length} volumes`);
24
+ * volumes.forEach(vol => console.log(`${vol.name} (${vol.id})`));
25
+ */
26
+ async list() {
27
+ const response = await this.volumesApi.listVolumes();
28
+ return response.data;
29
+ }
30
+ /**
31
+ * Gets a Volume by its name.
32
+ *
33
+ * @param {string} name - Name of the Volume to retrieve
34
+ * @returns {Promise<Volume>} The requested Volume
35
+ * @throws {Error} If the Volume does not exist or cannot be accessed
36
+ *
37
+ * @example
38
+ * const daytona = new Daytona();
39
+ * const volume = await daytona.volume.get("volume-name");
40
+ * console.log(`Volume ${volume.name} is in state ${volume.state}`);
41
+ */
42
+ async get(name) {
43
+ const response = await this.volumesApi.getVolumeByName(name);
44
+ return response.data;
45
+ }
46
+ /**
47
+ * Creates a new Volume with the specified name.
48
+ *
49
+ * @param {string} name - Name for the new Volume
50
+ * @returns {Promise<Volume>} The newly created Volume
51
+ * @throws {Error} If the Volume cannot be created
52
+ *
53
+ * @example
54
+ * const daytona = new Daytona();
55
+ * const volume = await daytona.volume.create("my-data-volume");
56
+ * console.log(`Created volume ${volume.name} with ID ${volume.id}`);
57
+ */
58
+ async create(name) {
59
+ const response = await this.volumesApi.createVolume({ name });
60
+ return response.data;
61
+ }
62
+ /**
63
+ * Deletes a Volume.
64
+ *
65
+ * @param {Volume} volume - Volume to delete
66
+ * @returns {Promise<void>}
67
+ * @throws {Error} If the Volume does not exist or cannot be deleted
68
+ *
69
+ * @example
70
+ * const daytona = new Daytona();
71
+ * const volume = await daytona.volume.get("volume-name");
72
+ * await daytona.volume.delete(volume);
73
+ * console.log("Volume deleted successfully");
74
+ */
75
+ async delete(volume) {
76
+ await this.volumesApi.deleteVolume(volume.id);
77
+ }
78
+ }
79
+ exports.VolumeService = VolumeService;
@@ -14,17 +14,11 @@ class SandboxPythonCodeToolbox {
14
14
  code_wrapper = code_wrapper.replace('{encoded_code}', base64Code);
15
15
  base64Code = Buffer.from(code_wrapper).toString('base64');
16
16
  }
17
- // Build environment variables string
18
- const envVars = (params === null || params === void 0 ? void 0 : params.env)
19
- ? Object.entries(params.env)
20
- .map(([key, value]) => `${key}='${value}'`)
21
- .join(' ')
22
- : '';
23
17
  // Build command-line arguments string
24
18
  const argv = (params === null || params === void 0 ? void 0 : params.argv) ? params.argv.join(' ') : '';
25
19
  // Execute the bootstrapper code directly
26
20
  // Use -u flag to ensure unbuffered output for real-time error reporting
27
- return `sh -c '${envVars} python3 -u -c "exec(__import__(\\\"base64\\\").b64decode(\\\"${base64Code}\\\").decode())" ${argv}'`;
21
+ return `sh -c 'python3 -u -c "exec(__import__(\\\"base64\\\").b64decode(\\\"${base64Code}\\\").decode())" ${argv}'`;
28
22
  }
29
23
  /**
30
24
  * Checks if matplotlib is imported in the given Python code string.
@@ -7,13 +7,8 @@ class SandboxTsCodeToolbox {
7
7
  }
8
8
  getRunCommand(code, params) {
9
9
  const base64Code = Buffer.from(code).toString('base64');
10
- const envVars = (params === null || params === void 0 ? void 0 : params.env)
11
- ? Object.entries(params.env)
12
- .map(([key, value]) => `${key}='${value}'`)
13
- .join(' ')
14
- : '';
15
10
  const argv = (params === null || params === void 0 ? void 0 : params.argv) ? params.argv.join(' ') : '';
16
- return `sh -c 'echo ${base64Code} | base64 --decode | ${envVars} npx ts-node -O "{\\\"module\\\":\\\"CommonJS\\\"}" -e "$(cat)" x ${argv} 2>&1 | grep -vE "npm notice|npm warn exec"'`;
11
+ return `sh -c 'echo ${base64Code} | base64 --decode | npx ts-node -O "{\\\"module\\\":\\\"CommonJS\\\"}" -e "$(cat)" x ${argv} 2>&1 | grep -vE "npm notice"'`;
17
12
  }
18
13
  }
19
14
  exports.SandboxTsCodeToolbox = SandboxTsCodeToolbox;
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { CodeLanguage, Daytona } from './Daytona';
2
- export type { CreateSandboxParams, DaytonaConfig, SandboxResources } from './Daytona';
2
+ export type { CreateSandboxParams, DaytonaConfig, SandboxResources, VolumeMount } from './Daytona';
3
3
  export { FileSystem } from './FileSystem';
4
4
  export { Git } from './Git';
5
5
  export { LspLanguageId } from './LspServer';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@daytonaio/sdk",
3
- "version": "0.14.0",
3
+ "version": "0.16.0-alpha.0",
4
4
  "description": "Daytona client library for AI Agents",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "typescript": "^5.0.0"
35
35
  },
36
36
  "dependencies": {
37
- "@daytonaio/api-client": "^0.16.0",
37
+ "@daytonaio/api-client": "^0.18.0-alpha.0",
38
38
  "uuid": "^11.0.3",
39
39
  "@dotenvx/dotenvx": "^1.25.1"
40
40
  }