@daytonaio/sdk 0.170.0 → 0.171.0-alpha.3

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.
Files changed (237) hide show
  1. package/LICENSE +190 -0
  2. package/cjs/CodeInterpreter.d.ts +95 -0
  3. package/cjs/CodeInterpreter.d.ts.map +1 -0
  4. package/cjs/CodeInterpreter.js +297 -0
  5. package/cjs/CodeInterpreter.js.map +1 -0
  6. package/cjs/ComputerUse.d.ts +539 -0
  7. package/cjs/ComputerUse.d.ts.map +1 -0
  8. package/cjs/ComputerUse.js +808 -0
  9. package/cjs/ComputerUse.js.map +1 -0
  10. package/cjs/Daytona.d.ts +355 -0
  11. package/cjs/Daytona.d.ts.map +1 -0
  12. package/cjs/Daytona.js +527 -0
  13. package/cjs/Daytona.js.map +1 -0
  14. package/cjs/FileSystem.d.ts +371 -0
  15. package/cjs/FileSystem.d.ts.map +1 -0
  16. package/cjs/FileSystem.js +489 -0
  17. package/cjs/FileSystem.js.map +1 -0
  18. package/cjs/Git.d.ts +203 -0
  19. package/cjs/Git.d.ts.map +1 -0
  20. package/cjs/Git.js +326 -0
  21. package/cjs/Git.js.map +1 -0
  22. package/cjs/Image.d.ts +265 -0
  23. package/cjs/Image.d.ts.map +1 -0
  24. package/cjs/Image.js +586 -0
  25. package/cjs/Image.js.map +1 -0
  26. package/cjs/LspServer.d.ts +172 -0
  27. package/cjs/LspServer.d.ts.map +1 -0
  28. package/cjs/LspServer.js +259 -0
  29. package/cjs/LspServer.js.map +1 -0
  30. package/cjs/ObjectStorage.d.ts +79 -0
  31. package/cjs/ObjectStorage.d.ts.map +1 -0
  32. package/cjs/ObjectStorage.js +199 -0
  33. package/cjs/ObjectStorage.js.map +1 -0
  34. package/cjs/Process.d.ts +490 -0
  35. package/cjs/Process.d.ts.map +1 -0
  36. package/cjs/Process.js +647 -0
  37. package/cjs/Process.js.map +1 -0
  38. package/cjs/PtyHandle.d.ts +155 -0
  39. package/cjs/PtyHandle.d.ts.map +1 -0
  40. package/cjs/PtyHandle.js +416 -0
  41. package/cjs/PtyHandle.js.map +1 -0
  42. package/cjs/README.md +180 -0
  43. package/cjs/Sandbox.d.ts +476 -0
  44. package/cjs/Sandbox.d.ts.map +1 -0
  45. package/cjs/Sandbox.js +905 -0
  46. package/cjs/Sandbox.js.map +1 -0
  47. package/cjs/Snapshot.d.ts +140 -0
  48. package/cjs/Snapshot.d.ts.map +1 -0
  49. package/cjs/Snapshot.js +248 -0
  50. package/cjs/Snapshot.js.map +1 -0
  51. package/cjs/Volume.d.ts +84 -0
  52. package/cjs/Volume.d.ts.map +1 -0
  53. package/cjs/Volume.js +119 -0
  54. package/cjs/Volume.js.map +1 -0
  55. package/cjs/__tests__/helpers.d.ts +6 -0
  56. package/cjs/__tests__/helpers.d.ts.map +1 -0
  57. package/cjs/__tests__/helpers.js +26 -0
  58. package/cjs/__tests__/helpers.js.map +1 -0
  59. package/cjs/errors/DaytonaError.d.ts +171 -0
  60. package/cjs/errors/DaytonaError.d.ts.map +1 -0
  61. package/cjs/errors/DaytonaError.js +258 -0
  62. package/cjs/errors/DaytonaError.js.map +1 -0
  63. package/cjs/index.d.ts +22 -0
  64. package/cjs/index.d.ts.map +1 -0
  65. package/cjs/index.js +49 -0
  66. package/cjs/index.js.map +1 -0
  67. package/cjs/package.json +3 -0
  68. package/cjs/types/Charts.d.ts +38 -0
  69. package/cjs/types/Charts.d.ts.map +1 -0
  70. package/cjs/types/Charts.js +37 -0
  71. package/cjs/types/Charts.js.map +1 -0
  72. package/cjs/types/CodeInterpreter.d.ts +77 -0
  73. package/cjs/types/CodeInterpreter.d.ts.map +1 -0
  74. package/cjs/types/CodeInterpreter.js +7 -0
  75. package/cjs/types/CodeInterpreter.js.map +1 -0
  76. package/cjs/types/ExecuteResponse.d.ts +26 -0
  77. package/cjs/types/ExecuteResponse.d.ts.map +1 -0
  78. package/cjs/types/ExecuteResponse.js +7 -0
  79. package/cjs/types/ExecuteResponse.js.map +1 -0
  80. package/cjs/types/Pty.d.ts +48 -0
  81. package/cjs/types/Pty.d.ts.map +1 -0
  82. package/cjs/types/Pty.js +7 -0
  83. package/cjs/types/Pty.js.map +1 -0
  84. package/cjs/utils/Binary.d.ts +39 -0
  85. package/cjs/utils/Binary.d.ts.map +1 -0
  86. package/cjs/utils/Binary.js +168 -0
  87. package/cjs/utils/Binary.js.map +1 -0
  88. package/cjs/utils/FileTransfer.d.ts +15 -0
  89. package/cjs/utils/FileTransfer.d.ts.map +1 -0
  90. package/cjs/utils/FileTransfer.js +261 -0
  91. package/cjs/utils/FileTransfer.js.map +1 -0
  92. package/cjs/utils/Import.d.ts +125 -0
  93. package/cjs/utils/Import.d.ts.map +1 -0
  94. package/cjs/utils/Import.js +112 -0
  95. package/cjs/utils/Import.js.map +1 -0
  96. package/cjs/utils/Multipart.d.ts +29 -0
  97. package/cjs/utils/Multipart.d.ts.map +1 -0
  98. package/cjs/utils/Multipart.js +115 -0
  99. package/cjs/utils/Multipart.js.map +1 -0
  100. package/cjs/utils/Runtime.d.ts +44 -0
  101. package/cjs/utils/Runtime.d.ts.map +1 -0
  102. package/cjs/utils/Runtime.js +95 -0
  103. package/cjs/utils/Runtime.js.map +1 -0
  104. package/cjs/utils/Stream.d.ts +20 -0
  105. package/cjs/utils/Stream.d.ts.map +1 -0
  106. package/cjs/utils/Stream.js +364 -0
  107. package/cjs/utils/Stream.js.map +1 -0
  108. package/cjs/utils/WebSocket.d.ts +10 -0
  109. package/cjs/utils/WebSocket.d.ts.map +1 -0
  110. package/cjs/utils/WebSocket.js +26 -0
  111. package/cjs/utils/WebSocket.js.map +1 -0
  112. package/cjs/utils/otel.decorator.d.ts +83 -0
  113. package/cjs/utils/otel.decorator.d.ts.map +1 -0
  114. package/cjs/utils/otel.decorator.js +141 -0
  115. package/cjs/utils/otel.decorator.js.map +1 -0
  116. package/esm/CodeInterpreter.d.ts +95 -0
  117. package/esm/CodeInterpreter.d.ts.map +1 -0
  118. package/esm/CodeInterpreter.js +292 -0
  119. package/esm/CodeInterpreter.js.map +1 -0
  120. package/esm/ComputerUse.d.ts +539 -0
  121. package/esm/ComputerUse.d.ts.map +1 -0
  122. package/esm/ComputerUse.js +799 -0
  123. package/esm/ComputerUse.js.map +1 -0
  124. package/esm/Daytona.d.ts +355 -0
  125. package/esm/Daytona.d.ts.map +1 -0
  126. package/esm/Daytona.js +523 -0
  127. package/esm/Daytona.js.map +1 -0
  128. package/esm/FileSystem.d.ts +371 -0
  129. package/esm/FileSystem.d.ts.map +1 -0
  130. package/esm/FileSystem.js +485 -0
  131. package/esm/FileSystem.js.map +1 -0
  132. package/esm/Git.d.ts +203 -0
  133. package/esm/Git.d.ts.map +1 -0
  134. package/esm/Git.js +322 -0
  135. package/esm/Git.js.map +1 -0
  136. package/esm/Image.d.ts +265 -0
  137. package/esm/Image.d.ts.map +1 -0
  138. package/esm/Image.js +581 -0
  139. package/esm/Image.js.map +1 -0
  140. package/esm/LspServer.d.ts +172 -0
  141. package/esm/LspServer.d.ts.map +1 -0
  142. package/esm/LspServer.js +255 -0
  143. package/esm/LspServer.js.map +1 -0
  144. package/esm/ObjectStorage.d.ts +79 -0
  145. package/esm/ObjectStorage.d.ts.map +1 -0
  146. package/esm/ObjectStorage.js +195 -0
  147. package/esm/ObjectStorage.js.map +1 -0
  148. package/esm/Process.d.ts +490 -0
  149. package/esm/Process.d.ts.map +1 -0
  150. package/esm/Process.js +642 -0
  151. package/esm/Process.js.map +1 -0
  152. package/esm/PtyHandle.d.ts +155 -0
  153. package/esm/PtyHandle.d.ts.map +1 -0
  154. package/esm/PtyHandle.js +412 -0
  155. package/esm/PtyHandle.js.map +1 -0
  156. package/esm/README.md +180 -0
  157. package/esm/Sandbox.d.ts +476 -0
  158. package/esm/Sandbox.d.ts.map +1 -0
  159. package/esm/Sandbox.js +901 -0
  160. package/esm/Sandbox.js.map +1 -0
  161. package/esm/Snapshot.d.ts +140 -0
  162. package/esm/Snapshot.d.ts.map +1 -0
  163. package/esm/Snapshot.js +244 -0
  164. package/esm/Snapshot.js.map +1 -0
  165. package/esm/Volume.d.ts +84 -0
  166. package/esm/Volume.d.ts.map +1 -0
  167. package/esm/Volume.js +115 -0
  168. package/esm/Volume.js.map +1 -0
  169. package/esm/__tests__/helpers.d.ts +6 -0
  170. package/esm/__tests__/helpers.d.ts.map +1 -0
  171. package/esm/__tests__/helpers.js +20 -0
  172. package/esm/__tests__/helpers.js.map +1 -0
  173. package/esm/errors/DaytonaError.d.ts +171 -0
  174. package/esm/errors/DaytonaError.d.ts.map +1 -0
  175. package/esm/errors/DaytonaError.js +243 -0
  176. package/esm/errors/DaytonaError.js.map +1 -0
  177. package/esm/index.d.ts +22 -0
  178. package/esm/index.d.ts.map +1 -0
  179. package/esm/index.js +21 -0
  180. package/esm/index.js.map +1 -0
  181. package/esm/package.json +3 -0
  182. package/esm/types/Charts.d.ts +38 -0
  183. package/esm/types/Charts.d.ts.map +1 -0
  184. package/esm/types/Charts.js +33 -0
  185. package/esm/types/Charts.js.map +1 -0
  186. package/esm/types/CodeInterpreter.d.ts +77 -0
  187. package/esm/types/CodeInterpreter.d.ts.map +1 -0
  188. package/esm/types/CodeInterpreter.js +6 -0
  189. package/esm/types/CodeInterpreter.js.map +1 -0
  190. package/esm/types/ExecuteResponse.d.ts +26 -0
  191. package/esm/types/ExecuteResponse.d.ts.map +1 -0
  192. package/esm/types/ExecuteResponse.js +6 -0
  193. package/esm/types/ExecuteResponse.js.map +1 -0
  194. package/esm/types/Pty.d.ts +48 -0
  195. package/esm/types/Pty.d.ts.map +1 -0
  196. package/esm/types/Pty.js +6 -0
  197. package/esm/types/Pty.js.map +1 -0
  198. package/esm/utils/Binary.d.ts +39 -0
  199. package/esm/utils/Binary.d.ts.map +1 -0
  200. package/esm/utils/Binary.js +157 -0
  201. package/esm/utils/Binary.js.map +1 -0
  202. package/esm/utils/FileTransfer.d.ts +15 -0
  203. package/esm/utils/FileTransfer.d.ts.map +1 -0
  204. package/esm/utils/FileTransfer.js +254 -0
  205. package/esm/utils/FileTransfer.js.map +1 -0
  206. package/esm/utils/Import.d.ts +95 -0
  207. package/esm/utils/Import.d.ts.map +1 -0
  208. package/esm/utils/Import.js +77 -0
  209. package/esm/utils/Import.js.map +1 -0
  210. package/esm/utils/Multipart.d.ts +29 -0
  211. package/esm/utils/Multipart.d.ts.map +1 -0
  212. package/esm/utils/Multipart.js +109 -0
  213. package/esm/utils/Multipart.js.map +1 -0
  214. package/esm/utils/Runtime.d.ts +44 -0
  215. package/esm/utils/Runtime.d.ts.map +1 -0
  216. package/esm/utils/Runtime.js +89 -0
  217. package/esm/utils/Runtime.js.map +1 -0
  218. package/esm/utils/Stream.d.ts +20 -0
  219. package/esm/utils/Stream.d.ts.map +1 -0
  220. package/esm/utils/Stream.js +360 -0
  221. package/esm/utils/Stream.js.map +1 -0
  222. package/esm/utils/WebSocket.d.ts +10 -0
  223. package/esm/utils/WebSocket.d.ts.map +1 -0
  224. package/esm/utils/WebSocket.js +22 -0
  225. package/esm/utils/WebSocket.js.map +1 -0
  226. package/esm/utils/otel.decorator.d.ts +83 -0
  227. package/esm/utils/otel.decorator.d.ts.map +1 -0
  228. package/esm/utils/otel.decorator.js +136 -0
  229. package/esm/utils/otel.decorator.js.map +1 -0
  230. package/package.json +20 -8
  231. package/src/ComputerUse.d.ts +4 -4
  232. package/src/ComputerUse.js +4 -4
  233. package/src/Sandbox.d.ts +1 -18
  234. package/src/Sandbox.js +0 -29
  235. package/src/Sandbox.js.map +1 -1
  236. package/src/__tests__/helpers.js +0 -2
  237. package/src/__tests__/helpers.js.map +1 -1
package/esm/Sandbox.js ADDED
@@ -0,0 +1,901 @@
1
+ /*
2
+ * Copyright 2025 Daytona Platforms Inc.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { __decorate, __metadata } from "tslib";
6
+ import { SandboxState, } from '@daytona/api-client';
7
+ import { Daytona } from './Daytona.js';
8
+ import { FileSystemApi, GitApi, ProcessApi, LspApi, InfoApi, ComputerUseApi, InterpreterApi, } from '@daytona/toolbox-api-client';
9
+ import { FileSystem } from './FileSystem.js';
10
+ import { Git } from './Git.js';
11
+ import { Process } from './Process.js';
12
+ import { LspServer } from './LspServer.js';
13
+ import { DaytonaError, DaytonaNotFoundError, DaytonaTimeoutError, DaytonaValidationError } from './errors/DaytonaError.js';
14
+ import { CODE_TOOLBOX_LANGUAGE_LABEL } from './Daytona.js';
15
+ import { ComputerUse } from './ComputerUse.js';
16
+ import { CodeInterpreter } from './CodeInterpreter.js';
17
+ import { WithInstrumentation } from './utils/otel.decorator.js';
18
+ /**
19
+ * Represents a Daytona Sandbox.
20
+ *
21
+ * @property {FileSystem} fs - File system operations interface
22
+ * @property {Git} git - Git operations interface
23
+ * @property {Process} process - Process execution interface
24
+ * @property {CodeInterpreter} codeInterpreter - Stateful interpreter interface for executing code.
25
+ * Currently supports only Python. For other languages, use the `process.codeRun` method.
26
+ * @property {ComputerUse} computerUse - Computer use operations interface for desktop automation
27
+ * @property {string} id - Unique identifier for the Sandbox
28
+ * @property {string} organizationId - Organization ID of the Sandbox
29
+ * @property {string} [snapshot] - Daytona snapshot used to create the Sandbox
30
+ * @property {string} user - OS user running in the Sandbox
31
+ * @property {Record<string, string>} env - Environment variables set in the Sandbox
32
+ * @property {Record<string, string>} labels - Custom labels attached to the Sandbox
33
+ * @property {boolean} public - Whether the Sandbox is publicly accessible
34
+ * @property {string} target - Target location of the runner where the Sandbox runs
35
+ * @property {number} cpu - Number of CPUs allocated to the Sandbox
36
+ * @property {number} gpu - Number of GPUs allocated to the Sandbox
37
+ * @property {number} memory - Amount of memory allocated to the Sandbox in GiB
38
+ * @property {number} disk - Amount of disk space allocated to the Sandbox in GiB
39
+ * @property {SandboxState} state - Current state of the Sandbox (e.g., "started", "stopped")
40
+ * @property {string} [errorReason] - Error message if Sandbox is in error state
41
+ * @property {boolean} [recoverable] - Whether the Sandbox error is recoverable.
42
+ * @property {SandboxBackupStateEnum} [backupState] - Current state of Sandbox backup
43
+ * @property {string} [backupCreatedAt] - When the backup was created
44
+ * @property {number} [autoStopInterval] - Auto-stop interval in minutes
45
+ * @property {number} [autoArchiveInterval] - Auto-archive interval in minutes
46
+ * @property {number} [autoDeleteInterval] - Auto-delete interval in minutes
47
+ * @property {Array<SandboxVolume>} [volumes] - Volumes attached to the Sandbox
48
+ * @property {BuildInfo} [buildInfo] - Build information for the Sandbox if it was created from dynamic build
49
+ * @property {string} [createdAt] - When the Sandbox was created
50
+ * @property {string} [updatedAt] - When the Sandbox was last updated
51
+ * @property {string} [lastActivityAt] - When the Sandbox last had activity
52
+ * @property {boolean} networkBlockAll - Whether to block all network access for the Sandbox
53
+ * @property {string} [networkAllowList] - Comma-separated list of allowed CIDR network addresses for the Sandbox
54
+ *
55
+ * @class
56
+ */
57
+ export class Sandbox {
58
+ clientConfig;
59
+ axiosInstance;
60
+ sandboxApi;
61
+ fs;
62
+ git;
63
+ process;
64
+ computerUse;
65
+ codeInterpreter;
66
+ id;
67
+ name;
68
+ organizationId;
69
+ snapshot;
70
+ user;
71
+ env;
72
+ labels;
73
+ public;
74
+ target;
75
+ cpu;
76
+ gpu;
77
+ memory;
78
+ disk;
79
+ state;
80
+ errorReason;
81
+ recoverable;
82
+ backupState;
83
+ backupCreatedAt;
84
+ autoStopInterval;
85
+ autoArchiveInterval;
86
+ autoDeleteInterval;
87
+ volumes;
88
+ buildInfo;
89
+ createdAt;
90
+ updatedAt;
91
+ lastActivityAt;
92
+ networkBlockAll;
93
+ networkAllowList;
94
+ toolboxProxyUrl;
95
+ infoApi;
96
+ /**
97
+ * Creates a new Sandbox instance
98
+ *
99
+ * @param {SandboxDto} sandboxDto - The API Sandbox instance
100
+ */
101
+ constructor(sandboxDto, clientConfig, axiosInstance, sandboxApi) {
102
+ this.clientConfig = clientConfig;
103
+ this.axiosInstance = axiosInstance;
104
+ this.sandboxApi = sandboxApi;
105
+ this.processSandboxDto(sandboxDto);
106
+ // Set the toolbox base URL
107
+ let baseUrl = this.toolboxProxyUrl;
108
+ if (!baseUrl.endsWith('/')) {
109
+ baseUrl += '/';
110
+ }
111
+ this.axiosInstance.defaults.baseURL = baseUrl + this.id;
112
+ this.clientConfig.basePath = this.axiosInstance.defaults.baseURL;
113
+ // Initialize Services
114
+ const getPreviewToken = async () => (await this.getPreviewLink(1)).token;
115
+ this.fs = new FileSystem(this.clientConfig, new FileSystemApi(this.clientConfig, '', this.axiosInstance));
116
+ this.git = new Git(new GitApi(this.clientConfig, '', this.axiosInstance));
117
+ const language = sandboxDto.labels?.[CODE_TOOLBOX_LANGUAGE_LABEL];
118
+ this.process = new Process(this.clientConfig, new ProcessApi(this.clientConfig, '', this.axiosInstance), getPreviewToken, language);
119
+ this.codeInterpreter = new CodeInterpreter(this.clientConfig, new InterpreterApi(this.clientConfig, '', this.axiosInstance), getPreviewToken);
120
+ this.computerUse = new ComputerUse(new ComputerUseApi(this.clientConfig, '', this.axiosInstance));
121
+ this.infoApi = new InfoApi(this.clientConfig, '', this.axiosInstance);
122
+ }
123
+ /**
124
+ * Gets the user's home directory path for the logged in user inside the Sandbox.
125
+ *
126
+ * @returns {Promise<string | undefined>} The absolute path to the Sandbox user's home directory for the logged in user
127
+ *
128
+ * @example
129
+ * const userHomeDir = await sandbox.getUserHomeDir();
130
+ * console.log(`Sandbox user home: ${userHomeDir}`);
131
+ */
132
+ async getUserHomeDir() {
133
+ const response = await this.infoApi.getUserHomeDir();
134
+ return response.data.dir;
135
+ }
136
+ /**
137
+ * @deprecated Use `getUserHomeDir` instead. This method will be removed in a future version.
138
+ */
139
+ async getUserRootDir() {
140
+ return this.getUserHomeDir();
141
+ }
142
+ /**
143
+ * Gets the working directory path inside the Sandbox.
144
+ *
145
+ * @returns {Promise<string | undefined>} The absolute path to the Sandbox working directory. Uses the WORKDIR specified
146
+ * in the Dockerfile if present, or falling back to the user's home directory if not.
147
+ *
148
+ * @example
149
+ * const workDir = await sandbox.getWorkDir();
150
+ * console.log(`Sandbox working directory: ${workDir}`);
151
+ */
152
+ async getWorkDir() {
153
+ const response = await this.infoApi.getWorkDir();
154
+ return response.data.dir;
155
+ }
156
+ /**
157
+ * Creates a new Language Server Protocol (LSP) server instance.
158
+ *
159
+ * The LSP server provides language-specific features like code completion,
160
+ * diagnostics, and more.
161
+ *
162
+ * @param {LspLanguageId} languageId - The language server type (e.g., "typescript")
163
+ * @param {string} pathToProject - Path to the project root directory. Relative paths are resolved based on the sandbox working directory.
164
+ * @returns {LspServer} A new LSP server instance configured for the specified language
165
+ *
166
+ * @example
167
+ * const lsp = await sandbox.createLspServer('typescript', 'workspace/project');
168
+ */
169
+ async createLspServer(languageId, pathToProject) {
170
+ return new LspServer(languageId, pathToProject, new LspApi(this.clientConfig, '', this.axiosInstance));
171
+ }
172
+ /**
173
+ * Sets labels for the Sandbox.
174
+ *
175
+ * Labels are key-value pairs that can be used to organize and identify Sandboxes.
176
+ *
177
+ * @param {Record<string, string>} labels - Dictionary of key-value pairs representing Sandbox labels
178
+ * @returns {Promise<void>}
179
+ *
180
+ * @example
181
+ * // Set sandbox labels
182
+ * await sandbox.setLabels({
183
+ * project: 'my-project',
184
+ * environment: 'development',
185
+ * team: 'backend'
186
+ * });
187
+ */
188
+ async setLabels(labels) {
189
+ this.labels = (await this.sandboxApi.replaceLabels(this.id, { labels })).data.labels;
190
+ return this.labels;
191
+ }
192
+ /**
193
+ * Start the Sandbox.
194
+ *
195
+ * This method starts the Sandbox and waits for it to be ready.
196
+ *
197
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
198
+ * Defaults to 60-second timeout.
199
+ * @returns {Promise<void>}
200
+ * @throws {DaytonaError} - `DaytonaError` - If Sandbox fails to start or times out
201
+ *
202
+ * @example
203
+ * const sandbox = await daytona.getCurrentSandbox('my-sandbox');
204
+ * await sandbox.start(40); // Wait up to 40 seconds
205
+ * console.log('Sandbox started successfully');
206
+ */
207
+ async start(timeout = 60) {
208
+ if (timeout < 0) {
209
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
210
+ }
211
+ const startTime = Date.now();
212
+ const response = await this.sandboxApi.startSandbox(this.id, undefined, { timeout: timeout * 1000 });
213
+ this.processSandboxDto(response.data);
214
+ const timeElapsed = Date.now() - startTime;
215
+ await this.waitUntilStarted(timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout);
216
+ }
217
+ /**
218
+ * Recover the Sandbox from a recoverable error and wait for it to be ready.
219
+ *
220
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
221
+ * Defaults to 60-second timeout.
222
+ * @returns {Promise<void>}
223
+ * @throws {DaytonaError} - `DaytonaError` - If Sandbox fails to recover or times out
224
+ *
225
+ * @example
226
+ * const sandbox = await daytona.get('my-sandbox-id');
227
+ * await sandbox.recover();
228
+ * console.log('Sandbox recovered successfully');
229
+ */
230
+ async recover(timeout = 60) {
231
+ if (timeout < 0) {
232
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
233
+ }
234
+ const startTime = Date.now();
235
+ const response = await this.sandboxApi.recoverSandbox(this.id, undefined, undefined, { timeout: timeout * 1000 });
236
+ this.processSandboxDto(response.data);
237
+ const timeElapsed = Date.now() - startTime;
238
+ await this.waitUntilStarted(timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout);
239
+ }
240
+ /**
241
+ * Stops the Sandbox.
242
+ *
243
+ * This method stops the Sandbox and waits for it to be fully stopped.
244
+ *
245
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
246
+ * Defaults to 60-second timeout.
247
+ * @param {boolean} [force] - If true, uses SIGKILL instead of SIGTERM. Defaults to false.
248
+ * @returns {Promise<void>}
249
+ *
250
+ * @example
251
+ * const sandbox = await daytona.get('my-sandbox-id');
252
+ * await sandbox.stop();
253
+ * console.log('Sandbox stopped successfully');
254
+ */
255
+ async stop(timeout = 60, force = false) {
256
+ if (timeout < 0) {
257
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
258
+ }
259
+ const startTime = Date.now();
260
+ await this.sandboxApi.stopSandbox(this.id, undefined, force, { timeout: timeout * 1000 });
261
+ await this.refreshDataSafe();
262
+ const timeElapsed = Date.now() - startTime;
263
+ await this.waitUntilStopped(timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout);
264
+ }
265
+ /**
266
+ * Forks the Sandbox, creating a new Sandbox with an identical filesystem.
267
+ *
268
+ * The forked Sandbox is a copy-on-write clone of the original. It starts
269
+ * with the same disk contents but operates independently from that point on.
270
+ *
271
+ * @param {object} [params] - Fork parameters
272
+ * @param {string} [params.name] - Optional name for the forked Sandbox. If not provided, a unique name will be generated.
273
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
274
+ * Defaults to 60-second timeout.
275
+ * @returns {Promise<Sandbox>} The forked Sandbox.
276
+ * @throws {DaytonaValidationError} - If timeout is a negative number
277
+ * @throws {DaytonaError} - If the fork operation fails or times out
278
+ *
279
+ * @example
280
+ * const sandbox = await daytona.get('my-sandbox');
281
+ * const forked = await sandbox._experimental_fork({ name: 'my-fork' });
282
+ * console.log(`Forked sandbox: ${forked.id}`);
283
+ */
284
+ async _experimental_fork(params, timeout = 60) {
285
+ if (timeout < 0) {
286
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
287
+ }
288
+ const startTime = Date.now();
289
+ const response = await this.sandboxApi.forkSandbox(this.id, { name: params?.name }, undefined, {
290
+ timeout: timeout * 1000,
291
+ });
292
+ const sandboxDto = response.data;
293
+ const forkedSandbox = new Sandbox(sandboxDto, structuredClone(this.clientConfig), Daytona.createAxiosInstance(), this.sandboxApi);
294
+ const timeElapsed = Date.now() - startTime;
295
+ await forkedSandbox.waitUntilStarted(timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout);
296
+ return forkedSandbox;
297
+ }
298
+ /**
299
+ * Creates a snapshot from the current state of the Sandbox.
300
+ *
301
+ * This captures the Sandbox's filesystem into a reusable snapshot that can be
302
+ * used to create new Sandboxes. The Sandbox will temporarily enter a
303
+ * 'snapshotting' state and return to its previous state when complete.
304
+ *
305
+ * @param {string} name - Name for the new snapshot
306
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
307
+ * Defaults to 60-second timeout.
308
+ * @returns {Promise<void>}
309
+ * @throws {DaytonaValidationError} - If timeout is a negative number
310
+ * @throws {DaytonaError} - If the snapshot operation fails or times out
311
+ *
312
+ * @example
313
+ * const sandbox = await daytona.get('my-sandbox');
314
+ * await sandbox._experimental_createSnapshot('my-snapshot');
315
+ * console.log('Snapshot created successfully');
316
+ */
317
+ async _experimental_createSnapshot(name, timeout = 60) {
318
+ if (timeout < 0) {
319
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
320
+ }
321
+ const startTime = Date.now();
322
+ const req = { name };
323
+ await this.sandboxApi.createSandboxSnapshot(this.id, req, undefined, {
324
+ timeout: timeout * 1000,
325
+ });
326
+ await this.refreshData();
327
+ const timeElapsed = Date.now() - startTime;
328
+ const remainingTimeout = timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout;
329
+ await this.waitForSnapshotComplete(remainingTimeout);
330
+ }
331
+ async waitForSnapshotComplete(timeout) {
332
+ let checkInterval = 100;
333
+ const startTime = Date.now();
334
+ while (this.state === SandboxState.SNAPSHOTTING) {
335
+ await this.refreshData();
336
+ // @ts-expect-error this.refreshData() can modify this.state so this check is fine
337
+ if (this.state === SandboxState.ERROR || this.state === SandboxState.BUILD_FAILED) {
338
+ throw new DaytonaError(`Sandbox ${this.id} snapshot failed with state: ${this.state}, error reason: ${this.errorReason}`);
339
+ }
340
+ if (this.state !== SandboxState.SNAPSHOTTING) {
341
+ return;
342
+ }
343
+ if (timeout !== 0 && Date.now() - startTime > timeout * 1000) {
344
+ throw new DaytonaTimeoutError('Sandbox snapshot did not complete within the timeout period');
345
+ }
346
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
347
+ if (Date.now() - startTime > 5000) {
348
+ checkInterval = Math.min(checkInterval * 1.1, 1000);
349
+ }
350
+ }
351
+ }
352
+ /**
353
+ * Deletes the Sandbox.
354
+ * @returns {Promise<void>}
355
+ */
356
+ async delete(timeout = 60) {
357
+ await this.sandboxApi.deleteSandbox(this.id, undefined, { timeout: timeout * 1000 });
358
+ this.refreshDataSafe();
359
+ }
360
+ /**
361
+ * Waits for the Sandbox to reach the 'started' state.
362
+ *
363
+ * This method polls the Sandbox status until it reaches the 'started' state
364
+ * or encounters an error.
365
+ *
366
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
367
+ * Defaults to 60 seconds.
368
+ * @returns {Promise<void>}
369
+ * @throws {DaytonaError} - `DaytonaError` - If the sandbox ends up in an error state or fails to start within the timeout period.
370
+ */
371
+ async waitUntilStarted(timeout = 60) {
372
+ if (timeout < 0) {
373
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
374
+ }
375
+ let checkInterval = 100;
376
+ const startTime = Date.now();
377
+ while (this.state !== 'started') {
378
+ await this.refreshData();
379
+ // @ts-expect-error this.refreshData() can modify this.state so this check is fine
380
+ if (this.state === 'started') {
381
+ return;
382
+ }
383
+ if (this.state === 'error') {
384
+ const errMsg = `Sandbox ${this.id} failed to start with status: ${this.state}, error reason: ${this.errorReason}`;
385
+ throw new DaytonaError(errMsg);
386
+ }
387
+ if (timeout !== 0 && Date.now() - startTime > timeout * 1000) {
388
+ throw new DaytonaTimeoutError('Sandbox failed to become ready within the timeout period');
389
+ }
390
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
391
+ if (Date.now() - startTime > 5000) {
392
+ checkInterval = Math.min(checkInterval * 1.1, 1000);
393
+ }
394
+ }
395
+ }
396
+ /**
397
+ * Wait for Sandbox to reach 'stopped' state.
398
+ *
399
+ * This method polls the Sandbox status until it reaches the 'stopped' state
400
+ * or encounters an error.
401
+ *
402
+ * @param {number} [timeout] - Maximum time to wait in seconds. 0 means no timeout.
403
+ * Defaults to 60 seconds.
404
+ * @returns {Promise<void>}
405
+ * @throws {DaytonaError} - `DaytonaError` - If the sandbox fails to stop within the timeout period.
406
+ */
407
+ async waitUntilStopped(timeout = 60) {
408
+ if (timeout < 0) {
409
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
410
+ }
411
+ let checkInterval = 100;
412
+ const startTime = Date.now();
413
+ // Treat destroyed as stopped to cover ephemeral sandboxes that are automatically deleted after stopping
414
+ while (this.state !== 'stopped' && this.state !== 'destroyed') {
415
+ this.refreshDataSafe();
416
+ // @ts-expect-error this.refreshData() can modify this.state so this check is fine
417
+ if (this.state === 'stopped' || this.state === 'destroyed') {
418
+ return;
419
+ }
420
+ if (this.state === 'error') {
421
+ const errMsg = `Sandbox failed to stop with status: ${this.state}, error reason: ${this.errorReason}`;
422
+ throw new DaytonaError(errMsg);
423
+ }
424
+ if (timeout !== 0 && Date.now() - startTime > timeout * 1000) {
425
+ throw new DaytonaTimeoutError('Sandbox failed to become stopped within the timeout period');
426
+ }
427
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
428
+ if (Date.now() - startTime > 5000) {
429
+ checkInterval = Math.min(checkInterval * 1.1, 1000);
430
+ }
431
+ }
432
+ }
433
+ /**
434
+ * Refreshes the Sandbox data from the API.
435
+ *
436
+ * @returns {Promise<void>}
437
+ *
438
+ * @example
439
+ * await sandbox.refreshData();
440
+ * console.log(`Sandbox ${sandbox.id}:`);
441
+ * console.log(`State: ${sandbox.state}`);
442
+ * console.log(`Resources: ${sandbox.cpu} CPU, ${sandbox.memory} GiB RAM`);
443
+ */
444
+ async refreshData() {
445
+ const response = await this.sandboxApi.getSandbox(this.id);
446
+ this.processSandboxDto(response.data);
447
+ }
448
+ /**
449
+ * Refreshes the sandbox activity to reset the timer for automated lifecycle management actions.
450
+ *
451
+ * This method updates the sandbox's last activity timestamp without changing its state.
452
+ * It is useful for keeping long-running sessions alive while there is still user activity.
453
+ *
454
+ * @returns {Promise<void>}
455
+ *
456
+ * @example
457
+ * // Keep sandbox activity alive
458
+ * await sandbox.refreshActivity();
459
+ */
460
+ async refreshActivity() {
461
+ await this.sandboxApi.updateLastActivity(this.id);
462
+ }
463
+ /**
464
+ * Set the auto-stop interval for the Sandbox.
465
+ *
466
+ * The Sandbox will automatically stop after being idle (no new events) for the specified interval.
467
+ * Events include any state changes or interactions with the Sandbox through the sdk.
468
+ * Interactions using Sandbox Previews are not included.
469
+ *
470
+ * @param {number} interval - Number of minutes of inactivity before auto-stopping.
471
+ * Set to 0 to disable auto-stop. Default is 15 minutes.
472
+ * @returns {Promise<void>}
473
+ * @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
474
+ *
475
+ * @example
476
+ * // Auto-stop after 1 hour
477
+ * await sandbox.setAutostopInterval(60);
478
+ * // Or disable auto-stop
479
+ * await sandbox.setAutostopInterval(0);
480
+ */
481
+ async setAutostopInterval(interval) {
482
+ if (!Number.isInteger(interval) || interval < 0) {
483
+ throw new DaytonaValidationError('autoStopInterval must be a non-negative integer');
484
+ }
485
+ await this.sandboxApi.setAutostopInterval(this.id, interval);
486
+ this.autoStopInterval = interval;
487
+ }
488
+ /**
489
+ * Set the auto-archive interval for the Sandbox.
490
+ *
491
+ * The Sandbox will automatically archive after being continuously stopped for the specified interval.
492
+ *
493
+ * @param {number} interval - Number of minutes after which a continuously stopped Sandbox will be auto-archived.
494
+ * Set to 0 for the maximum interval. Default is 7 days.
495
+ * @returns {Promise<void>}
496
+ * @throws {DaytonaError} - `DaytonaError` - If interval is not a non-negative integer
497
+ *
498
+ * @example
499
+ * // Auto-archive after 1 hour
500
+ * await sandbox.setAutoArchiveInterval(60);
501
+ * // Or use the maximum interval
502
+ * await sandbox.setAutoArchiveInterval(0);
503
+ */
504
+ async setAutoArchiveInterval(interval) {
505
+ if (!Number.isInteger(interval) || interval < 0) {
506
+ throw new DaytonaValidationError('autoArchiveInterval must be a non-negative integer');
507
+ }
508
+ await this.sandboxApi.setAutoArchiveInterval(this.id, interval);
509
+ this.autoArchiveInterval = interval;
510
+ }
511
+ /**
512
+ * Set the auto-delete interval for the Sandbox.
513
+ *
514
+ * The Sandbox will automatically delete after being continuously stopped for the specified interval.
515
+ *
516
+ * @param {number} interval - Number of minutes after which a continuously stopped Sandbox will be auto-deleted.
517
+ * Set to negative value to disable auto-delete. Set to 0 to delete immediately upon stopping.
518
+ * By default, auto-delete is disabled.
519
+ * @returns {Promise<void>}
520
+ *
521
+ * @example
522
+ * // Auto-delete after 1 hour
523
+ * await sandbox.setAutoDeleteInterval(60);
524
+ * // Or delete immediately upon stopping
525
+ * await sandbox.setAutoDeleteInterval(0);
526
+ * // Or disable auto-delete
527
+ * await sandbox.setAutoDeleteInterval(-1);
528
+ */
529
+ async setAutoDeleteInterval(interval) {
530
+ await this.sandboxApi.setAutoDeleteInterval(this.id, interval);
531
+ this.autoDeleteInterval = interval;
532
+ }
533
+ /**
534
+ * Updates outbound network policy for this sandbox on the runner (for example block all traffic,
535
+ * restore general internet access, or apply a CIDR allow list) without stopping the sandbox.
536
+ *
537
+ * This maps to the same mechanism as creating a sandbox with `networkBlockAll` / `networkAllowList`:
538
+ * the runner applies iptables rules to the sandbox container.
539
+ *
540
+ * @param {UpdateSandboxNetworkSettings} settings - At least one of `networkBlockAll` or `networkAllowList` must be set.
541
+ * Set `networkBlockAll` to `false` to restore outbound access after a block (and clear a stored allow list).
542
+ *
543
+ * @example
544
+ * // Pause internet (outbound blocked)
545
+ * await sandbox.updateNetworkSettings({ networkBlockAll: true });
546
+ * // Resume internet
547
+ * await sandbox.updateNetworkSettings({ networkBlockAll: false });
548
+ */
549
+ async updateNetworkSettings(settings) {
550
+ if (settings.networkBlockAll === undefined && settings.networkAllowList === undefined) {
551
+ throw new DaytonaValidationError('At least one of networkBlockAll or networkAllowList must be set');
552
+ }
553
+ const response = await this.sandboxApi.updateNetworkSettings(this.id, settings);
554
+ this.processSandboxDto(response.data);
555
+ }
556
+ /**
557
+ * Retrieves the preview link for the sandbox at the specified port. If the port is closed,
558
+ * it will be opened automatically. For private sandboxes, a token is included to grant access
559
+ * to the URL.
560
+ *
561
+ * @param {number} port - The port to open the preview link on.
562
+ * @returns {PortPreviewUrl} The response object for the preview link, which includes the `url`
563
+ * and the `token` (to access private sandboxes).
564
+ *
565
+ * @example
566
+ * const previewLink = await sandbox.getPreviewLink(3000);
567
+ * console.log(`Preview URL: ${previewLink.url}`);
568
+ * console.log(`Token: ${previewLink.token}`);
569
+ */
570
+ async getPreviewLink(port) {
571
+ return (await this.sandboxApi.getPortPreviewUrl(this.id, port)).data;
572
+ }
573
+ /**
574
+ * Retrieves a signed preview url for the sandbox at the specified port.
575
+ *
576
+ * @param {number} port - The port to open the preview link on.
577
+ * @param {number} [expiresInSeconds] - The number of seconds the signed preview url will be valid for. Defaults to 60 seconds.
578
+ * @returns {Promise<SignedPortPreviewUrl>} The response object for the signed preview url.
579
+ */
580
+ async getSignedPreviewUrl(port, expiresInSeconds) {
581
+ return (await this.sandboxApi.getSignedPortPreviewUrl(this.id, port, undefined, expiresInSeconds)).data;
582
+ }
583
+ /**
584
+ * Expires a signed preview url for the sandbox at the specified port.
585
+ *
586
+ * @param {number} port - The port to expire the signed preview url on.
587
+ * @param {string} token - The token to expire the signed preview url on.
588
+ * @returns {Promise<void>}
589
+ */
590
+ async expireSignedPreviewUrl(port, token) {
591
+ await this.sandboxApi.expireSignedPortPreviewUrl(this.id, port, token);
592
+ }
593
+ /**
594
+ * Archives the sandbox, making it inactive and preserving its state. When sandboxes are archived, the entire filesystem
595
+ * state is moved to cost-effective object storage, making it possible to keep sandboxes available for an extended period.
596
+ * The tradeoff between archived and stopped states is that starting an archived sandbox takes more time, depending on its size.
597
+ * Sandbox must be stopped before archiving.
598
+ */
599
+ async archive() {
600
+ await this.sandboxApi.archiveSandbox(this.id);
601
+ await this.refreshData();
602
+ }
603
+ /**
604
+ * Resizes the Sandbox resources.
605
+ *
606
+ * Changes the CPU, memory, or disk allocation for the Sandbox. Hot resize (on running
607
+ * sandbox) only allows CPU/memory increases. Disk resize requires a stopped sandbox.
608
+ *
609
+ * @param {Resources} resources - New resource configuration. Only specified fields will be updated.
610
+ * - cpu: Number of CPU cores (minimum: 1). For hot resize, can only be increased.
611
+ * - memory: Memory in GiB (minimum: 1). For hot resize, can only be increased.
612
+ * - disk: Disk space in GiB (can only be increased, requires stopped sandbox).
613
+ * @param {number} [timeout=60] - Timeout in seconds for the resize operation. 0 means no timeout.
614
+ * @returns {Promise<void>}
615
+ * @throws {DaytonaError} - If hot resize constraints are violated, disk resize attempted on running sandbox,
616
+ * disk size decrease is attempted, no resource changes are specified, or resize operation times out.
617
+ *
618
+ * @example
619
+ * // Increase CPU/memory on running sandbox (hot resize)
620
+ * await sandbox.resize({ cpu: 4, memory: 8 });
621
+ *
622
+ * // Change disk (sandbox must be stopped)
623
+ * await sandbox.stop();
624
+ * await sandbox.resize({ cpu: 2, memory: 4, disk: 30 });
625
+ */
626
+ async resize(resources, timeout = 60) {
627
+ if (timeout < 0) {
628
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
629
+ }
630
+ const startTime = Date.now();
631
+ const resizeRequest = {
632
+ cpu: resources.cpu,
633
+ memory: resources.memory,
634
+ disk: resources.disk,
635
+ };
636
+ const response = await this.sandboxApi.resizeSandbox(this.id, resizeRequest, this.organizationId, {
637
+ timeout: timeout * 1000,
638
+ });
639
+ this.processSandboxDto(response.data);
640
+ const timeElapsed = Date.now() - startTime;
641
+ await this.waitForResizeComplete(timeout ? Math.max(0.001, timeout - timeElapsed / 1000) : timeout);
642
+ }
643
+ /**
644
+ * Waits for the Sandbox resize operation to complete.
645
+ *
646
+ * This method polls the Sandbox status until the state is no longer 'resizing'.
647
+ *
648
+ * @param {number} [timeout=60] - Maximum time to wait in seconds. 0 means no timeout.
649
+ * @returns {Promise<void>}
650
+ * @throws {DaytonaError} - If the sandbox ends up in an error state or resize times out.
651
+ */
652
+ async waitForResizeComplete(timeout = 60) {
653
+ if (timeout < 0) {
654
+ throw new DaytonaValidationError('Timeout must be a non-negative number');
655
+ }
656
+ let checkInterval = 100;
657
+ const startTime = Date.now();
658
+ while (this.state === SandboxState.RESIZING) {
659
+ await this.refreshData();
660
+ // @ts-expect-error this.refreshData() can modify this.state so this check is fine
661
+ if (this.state === SandboxState.ERROR || this.state === SandboxState.BUILD_FAILED) {
662
+ throw new DaytonaError(`Sandbox ${this.id} resize failed with state: ${this.state}, error reason: ${this.errorReason}`);
663
+ }
664
+ if (this.state !== SandboxState.RESIZING) {
665
+ return;
666
+ }
667
+ if (timeout !== 0 && Date.now() - startTime > timeout * 1000) {
668
+ throw new DaytonaTimeoutError('Sandbox resize did not complete within the timeout period');
669
+ }
670
+ await new Promise((resolve) => setTimeout(resolve, checkInterval));
671
+ if (Date.now() - startTime > 5000) {
672
+ checkInterval = Math.min(checkInterval * 1.1, 1000);
673
+ }
674
+ }
675
+ }
676
+ /**
677
+ * Creates an SSH access token for the sandbox.
678
+ *
679
+ * @param {number} expiresInMinutes - The number of minutes the SSH access token will be valid for.
680
+ * @returns {Promise<SshAccessDto>} The SSH access token.
681
+ */
682
+ async createSshAccess(expiresInMinutes) {
683
+ return (await this.sandboxApi.createSshAccess(this.id, undefined, expiresInMinutes)).data;
684
+ }
685
+ /**
686
+ * Revokes an SSH access token for the sandbox.
687
+ *
688
+ * @param {string} token - The token to revoke.
689
+ * @returns {Promise<void>}
690
+ */
691
+ async revokeSshAccess(token) {
692
+ await this.sandboxApi.revokeSshAccess(this.id, undefined, token);
693
+ }
694
+ /**
695
+ * Validates an SSH access token for the sandbox.
696
+ *
697
+ * @param {string} token - The token to validate.
698
+ * @returns {Promise<SshAccessValidationDto>} The SSH access validation result.
699
+ */
700
+ async validateSshAccess(token) {
701
+ return (await this.sandboxApi.validateSshAccess(token)).data;
702
+ }
703
+ /**
704
+ * Assigns the API sandbox data to the Sandbox object.
705
+ *
706
+ * @param {SandboxDto} sandboxDto - The API sandbox instance to assign data from
707
+ * @returns {void}
708
+ */
709
+ processSandboxDto(sandboxDto) {
710
+ this.id = sandboxDto.id;
711
+ this.name = sandboxDto.name;
712
+ this.organizationId = sandboxDto.organizationId;
713
+ this.snapshot = sandboxDto.snapshot;
714
+ this.user = sandboxDto.user;
715
+ this.env = sandboxDto.env;
716
+ this.labels = sandboxDto.labels;
717
+ this.public = sandboxDto.public;
718
+ this.target = sandboxDto.target;
719
+ this.cpu = sandboxDto.cpu;
720
+ this.gpu = sandboxDto.gpu;
721
+ this.memory = sandboxDto.memory;
722
+ this.disk = sandboxDto.disk;
723
+ this.state = sandboxDto.state;
724
+ this.errorReason = sandboxDto.errorReason;
725
+ this.recoverable = sandboxDto.recoverable;
726
+ this.backupState = sandboxDto.backupState;
727
+ this.backupCreatedAt = sandboxDto.backupCreatedAt;
728
+ this.autoStopInterval = sandboxDto.autoStopInterval;
729
+ this.autoArchiveInterval = sandboxDto.autoArchiveInterval;
730
+ this.autoDeleteInterval = sandboxDto.autoDeleteInterval;
731
+ this.volumes = sandboxDto.volumes;
732
+ this.buildInfo = sandboxDto.buildInfo;
733
+ this.createdAt = sandboxDto.createdAt;
734
+ this.updatedAt = sandboxDto.updatedAt;
735
+ this.lastActivityAt = sandboxDto.lastActivityAt;
736
+ this.networkBlockAll = sandboxDto.networkBlockAll;
737
+ this.networkAllowList = sandboxDto.networkAllowList;
738
+ this.toolboxProxyUrl = sandboxDto.toolboxProxyUrl;
739
+ }
740
+ /**
741
+ * Refreshes the Sandbox data from the API, but does not throw an error if the sandbox has been deleted.
742
+ * Instead, it sets the state to destroyed.
743
+ *
744
+ * @returns {Promise<void>}
745
+ */
746
+ async refreshDataSafe() {
747
+ try {
748
+ await this.refreshData();
749
+ }
750
+ catch (error) {
751
+ if (error instanceof DaytonaNotFoundError) {
752
+ this.state = SandboxState.DESTROYED;
753
+ }
754
+ }
755
+ }
756
+ }
757
+ __decorate([
758
+ WithInstrumentation(),
759
+ __metadata("design:type", Function),
760
+ __metadata("design:paramtypes", []),
761
+ __metadata("design:returntype", Promise)
762
+ ], Sandbox.prototype, "getUserHomeDir", null);
763
+ __decorate([
764
+ WithInstrumentation(),
765
+ __metadata("design:type", Function),
766
+ __metadata("design:paramtypes", []),
767
+ __metadata("design:returntype", Promise)
768
+ ], Sandbox.prototype, "getUserRootDir", null);
769
+ __decorate([
770
+ WithInstrumentation(),
771
+ __metadata("design:type", Function),
772
+ __metadata("design:paramtypes", []),
773
+ __metadata("design:returntype", Promise)
774
+ ], Sandbox.prototype, "getWorkDir", null);
775
+ __decorate([
776
+ WithInstrumentation(),
777
+ __metadata("design:type", Function),
778
+ __metadata("design:paramtypes", [String, String]),
779
+ __metadata("design:returntype", Promise)
780
+ ], Sandbox.prototype, "createLspServer", null);
781
+ __decorate([
782
+ WithInstrumentation(),
783
+ __metadata("design:type", Function),
784
+ __metadata("design:paramtypes", [Object]),
785
+ __metadata("design:returntype", Promise)
786
+ ], Sandbox.prototype, "setLabels", null);
787
+ __decorate([
788
+ WithInstrumentation(),
789
+ __metadata("design:type", Function),
790
+ __metadata("design:paramtypes", [Object]),
791
+ __metadata("design:returntype", Promise)
792
+ ], Sandbox.prototype, "start", null);
793
+ __decorate([
794
+ WithInstrumentation(),
795
+ __metadata("design:type", Function),
796
+ __metadata("design:paramtypes", [Object, Object]),
797
+ __metadata("design:returntype", Promise)
798
+ ], Sandbox.prototype, "stop", null);
799
+ __decorate([
800
+ WithInstrumentation(),
801
+ __metadata("design:type", Function),
802
+ __metadata("design:paramtypes", [Object, Object]),
803
+ __metadata("design:returntype", Promise)
804
+ ], Sandbox.prototype, "_experimental_fork", null);
805
+ __decorate([
806
+ WithInstrumentation(),
807
+ __metadata("design:type", Function),
808
+ __metadata("design:paramtypes", [String, Object]),
809
+ __metadata("design:returntype", Promise)
810
+ ], Sandbox.prototype, "_experimental_createSnapshot", null);
811
+ __decorate([
812
+ WithInstrumentation(),
813
+ __metadata("design:type", Function),
814
+ __metadata("design:paramtypes", [Object]),
815
+ __metadata("design:returntype", Promise)
816
+ ], Sandbox.prototype, "delete", null);
817
+ __decorate([
818
+ WithInstrumentation(),
819
+ __metadata("design:type", Function),
820
+ __metadata("design:paramtypes", [Object]),
821
+ __metadata("design:returntype", Promise)
822
+ ], Sandbox.prototype, "waitUntilStarted", null);
823
+ __decorate([
824
+ WithInstrumentation(),
825
+ __metadata("design:type", Function),
826
+ __metadata("design:paramtypes", [Object]),
827
+ __metadata("design:returntype", Promise)
828
+ ], Sandbox.prototype, "waitUntilStopped", null);
829
+ __decorate([
830
+ WithInstrumentation(),
831
+ __metadata("design:type", Function),
832
+ __metadata("design:paramtypes", []),
833
+ __metadata("design:returntype", Promise)
834
+ ], Sandbox.prototype, "refreshData", null);
835
+ __decorate([
836
+ WithInstrumentation(),
837
+ __metadata("design:type", Function),
838
+ __metadata("design:paramtypes", [Number]),
839
+ __metadata("design:returntype", Promise)
840
+ ], Sandbox.prototype, "setAutostopInterval", null);
841
+ __decorate([
842
+ WithInstrumentation(),
843
+ __metadata("design:type", Function),
844
+ __metadata("design:paramtypes", [Number]),
845
+ __metadata("design:returntype", Promise)
846
+ ], Sandbox.prototype, "setAutoArchiveInterval", null);
847
+ __decorate([
848
+ WithInstrumentation(),
849
+ __metadata("design:type", Function),
850
+ __metadata("design:paramtypes", [Number]),
851
+ __metadata("design:returntype", Promise)
852
+ ], Sandbox.prototype, "setAutoDeleteInterval", null);
853
+ __decorate([
854
+ WithInstrumentation(),
855
+ __metadata("design:type", Function),
856
+ __metadata("design:paramtypes", [Object]),
857
+ __metadata("design:returntype", Promise)
858
+ ], Sandbox.prototype, "updateNetworkSettings", null);
859
+ __decorate([
860
+ WithInstrumentation(),
861
+ __metadata("design:type", Function),
862
+ __metadata("design:paramtypes", [Number]),
863
+ __metadata("design:returntype", Promise)
864
+ ], Sandbox.prototype, "getPreviewLink", null);
865
+ __decorate([
866
+ WithInstrumentation(),
867
+ __metadata("design:type", Function),
868
+ __metadata("design:paramtypes", []),
869
+ __metadata("design:returntype", Promise)
870
+ ], Sandbox.prototype, "archive", null);
871
+ __decorate([
872
+ WithInstrumentation(),
873
+ __metadata("design:type", Function),
874
+ __metadata("design:paramtypes", [Object, Object]),
875
+ __metadata("design:returntype", Promise)
876
+ ], Sandbox.prototype, "resize", null);
877
+ __decorate([
878
+ WithInstrumentation(),
879
+ __metadata("design:type", Function),
880
+ __metadata("design:paramtypes", [Object]),
881
+ __metadata("design:returntype", Promise)
882
+ ], Sandbox.prototype, "waitForResizeComplete", null);
883
+ __decorate([
884
+ WithInstrumentation(),
885
+ __metadata("design:type", Function),
886
+ __metadata("design:paramtypes", [Number]),
887
+ __metadata("design:returntype", Promise)
888
+ ], Sandbox.prototype, "createSshAccess", null);
889
+ __decorate([
890
+ WithInstrumentation(),
891
+ __metadata("design:type", Function),
892
+ __metadata("design:paramtypes", [String]),
893
+ __metadata("design:returntype", Promise)
894
+ ], Sandbox.prototype, "revokeSshAccess", null);
895
+ __decorate([
896
+ WithInstrumentation(),
897
+ __metadata("design:type", Function),
898
+ __metadata("design:paramtypes", [String]),
899
+ __metadata("design:returntype", Promise)
900
+ ], Sandbox.prototype, "validateSshAccess", null);
901
+ //# sourceMappingURL=Sandbox.js.map