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