@alibaba-group/opensandbox 0.1.1-dev0 → 0.1.2-dev0

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 (131) hide show
  1. package/dist/chunk-NFNOESEY.js +926 -0
  2. package/dist/chunk-NFNOESEY.js.map +1 -0
  3. package/dist/cjs/index.cjs +1625 -0
  4. package/dist/cjs/index.cjs.map +1 -0
  5. package/dist/cjs/internal.cjs +920 -0
  6. package/dist/cjs/internal.cjs.map +1 -0
  7. package/dist/index.d.ts +367 -22
  8. package/dist/index.js +678 -20
  9. package/dist/index.js.map +1 -1
  10. package/dist/internal.d.ts +2513 -19
  11. package/dist/internal.js +18 -30
  12. package/dist/internal.js.map +1 -1
  13. package/dist/sandboxes-HBCO9ttf.d.ts +352 -0
  14. package/package.json +7 -2
  15. package/src/api/lifecycle.ts +32 -0
  16. package/src/config/connection.ts +3 -1
  17. package/src/core/constants.ts +1 -1
  18. package/dist/adapters/commandsAdapter.d.ts +0 -22
  19. package/dist/adapters/commandsAdapter.d.ts.map +0 -1
  20. package/dist/adapters/commandsAdapter.js +0 -77
  21. package/dist/adapters/commandsAdapter.js.map +0 -1
  22. package/dist/adapters/filesystemAdapter.d.ts +0 -52
  23. package/dist/adapters/filesystemAdapter.d.ts.map +0 -1
  24. package/dist/adapters/filesystemAdapter.js +0 -443
  25. package/dist/adapters/filesystemAdapter.js.map +0 -1
  26. package/dist/adapters/healthAdapter.d.ts +0 -8
  27. package/dist/adapters/healthAdapter.d.ts.map +0 -1
  28. package/dist/adapters/healthAdapter.js +0 -26
  29. package/dist/adapters/healthAdapter.js.map +0 -1
  30. package/dist/adapters/metricsAdapter.d.ts +0 -9
  31. package/dist/adapters/metricsAdapter.d.ts.map +0 -1
  32. package/dist/adapters/metricsAdapter.js +0 -44
  33. package/dist/adapters/metricsAdapter.js.map +0 -1
  34. package/dist/adapters/openapiError.d.ts +0 -5
  35. package/dist/adapters/openapiError.d.ts.map +0 -1
  36. package/dist/adapters/openapiError.js +0 -34
  37. package/dist/adapters/openapiError.js.map +0 -1
  38. package/dist/adapters/sandboxesAdapter.d.ts +0 -18
  39. package/dist/adapters/sandboxesAdapter.d.ts.map +0 -1
  40. package/dist/adapters/sandboxesAdapter.js +0 -147
  41. package/dist/adapters/sandboxesAdapter.js.map +0 -1
  42. package/dist/adapters/sse.d.ts +0 -9
  43. package/dist/adapters/sse.d.ts.map +0 -1
  44. package/dist/adapters/sse.js +0 -87
  45. package/dist/adapters/sse.js.map +0 -1
  46. package/dist/api/execd.d.ts +0 -1555
  47. package/dist/api/execd.d.ts.map +0 -1
  48. package/dist/api/execd.js +0 -15
  49. package/dist/api/execd.js.map +0 -1
  50. package/dist/api/lifecycle.d.ts +0 -787
  51. package/dist/api/lifecycle.d.ts.map +0 -1
  52. package/dist/api/lifecycle.js +0 -15
  53. package/dist/api/lifecycle.js.map +0 -1
  54. package/dist/config/connection.d.ts +0 -69
  55. package/dist/config/connection.d.ts.map +0 -1
  56. package/dist/config/connection.js +0 -281
  57. package/dist/config/connection.js.map +0 -1
  58. package/dist/core/constants.d.ts +0 -9
  59. package/dist/core/constants.d.ts.map +0 -1
  60. package/dist/core/constants.js +0 -25
  61. package/dist/core/constants.js.map +0 -1
  62. package/dist/core/exceptions.d.ts +0 -74
  63. package/dist/core/exceptions.d.ts.map +0 -1
  64. package/dist/core/exceptions.js +0 -104
  65. package/dist/core/exceptions.js.map +0 -1
  66. package/dist/factory/adapterFactory.d.ts +0 -33
  67. package/dist/factory/adapterFactory.d.ts.map +0 -1
  68. package/dist/factory/adapterFactory.js +0 -15
  69. package/dist/factory/adapterFactory.js.map +0 -1
  70. package/dist/factory/defaultAdapterFactory.d.ts +0 -7
  71. package/dist/factory/defaultAdapterFactory.d.ts.map +0 -1
  72. package/dist/factory/defaultAdapterFactory.js +0 -61
  73. package/dist/factory/defaultAdapterFactory.js.map +0 -1
  74. package/dist/index.d.ts.map +0 -1
  75. package/dist/internal.d.ts.map +0 -1
  76. package/dist/manager.d.ts +0 -42
  77. package/dist/manager.d.ts.map +0 -1
  78. package/dist/manager.js +0 -86
  79. package/dist/manager.js.map +0 -1
  80. package/dist/models/execd.d.ts +0 -54
  81. package/dist/models/execd.d.ts.map +0 -1
  82. package/dist/models/execd.js +0 -15
  83. package/dist/models/execd.js.map +0 -1
  84. package/dist/models/execution.d.ts +0 -52
  85. package/dist/models/execution.d.ts.map +0 -1
  86. package/dist/models/execution.js +0 -15
  87. package/dist/models/execution.js.map +0 -1
  88. package/dist/models/executionEventDispatcher.d.ts +0 -15
  89. package/dist/models/executionEventDispatcher.d.ts.map +0 -1
  90. package/dist/models/executionEventDispatcher.js +0 -96
  91. package/dist/models/executionEventDispatcher.js.map +0 -1
  92. package/dist/models/filesystem.d.ts +0 -77
  93. package/dist/models/filesystem.d.ts.map +0 -1
  94. package/dist/models/filesystem.js +0 -15
  95. package/dist/models/filesystem.js.map +0 -1
  96. package/dist/models/sandboxes.d.ts +0 -105
  97. package/dist/models/sandboxes.d.ts.map +0 -1
  98. package/dist/models/sandboxes.js +0 -16
  99. package/dist/models/sandboxes.js.map +0 -1
  100. package/dist/openapi/execdClient.d.ts +0 -25
  101. package/dist/openapi/execdClient.d.ts.map +0 -1
  102. package/dist/openapi/execdClient.js +0 -22
  103. package/dist/openapi/execdClient.js.map +0 -1
  104. package/dist/openapi/lifecycleClient.d.ts +0 -28
  105. package/dist/openapi/lifecycleClient.d.ts.map +0 -1
  106. package/dist/openapi/lifecycleClient.js +0 -36
  107. package/dist/openapi/lifecycleClient.js.map +0 -1
  108. package/dist/sandbox.d.ts +0 -136
  109. package/dist/sandbox.d.ts.map +0 -1
  110. package/dist/sandbox.js +0 -303
  111. package/dist/sandbox.js.map +0 -1
  112. package/dist/services/execdCommands.d.ts +0 -19
  113. package/dist/services/execdCommands.d.ts.map +0 -1
  114. package/dist/services/execdCommands.js +0 -15
  115. package/dist/services/execdCommands.js.map +0 -1
  116. package/dist/services/execdHealth.d.ts +0 -4
  117. package/dist/services/execdHealth.d.ts.map +0 -1
  118. package/dist/services/execdHealth.js +0 -15
  119. package/dist/services/execdHealth.js.map +0 -1
  120. package/dist/services/execdMetrics.d.ts +0 -5
  121. package/dist/services/execdMetrics.d.ts.map +0 -1
  122. package/dist/services/execdMetrics.js +0 -15
  123. package/dist/services/execdMetrics.js.map +0 -1
  124. package/dist/services/filesystem.d.ts +0 -30
  125. package/dist/services/filesystem.d.ts.map +0 -1
  126. package/dist/services/filesystem.js +0 -15
  127. package/dist/services/filesystem.js.map +0 -1
  128. package/dist/services/sandboxes.d.ts +0 -12
  129. package/dist/services/sandboxes.d.ts.map +0 -1
  130. package/dist/services/sandboxes.js +0 -15
  131. package/dist/services/sandboxes.js.map +0 -1
package/dist/internal.js CHANGED
@@ -1,31 +1,19 @@
1
- // Copyright 2026 Alibaba Group Holding Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- /**
15
- * INTERNAL / ADVANCED ENTRYPOINT
16
- *
17
- * This subpath exposes low-level OpenAPI clients and adapters for advanced integrations.
18
- * It is intentionally NOT exported from the root entrypoint (`@alibaba-group/opensandbox`),
19
- * because generated OpenAPI types are not considered stable public API.
20
- *
21
- * Import path:
22
- * - `@alibaba-group/opensandbox/internal`
23
- */
24
- export { createLifecycleClient } from "./openapi/lifecycleClient.js";
25
- export { createExecdClient } from "./openapi/execdClient.js";
26
- export { SandboxesAdapter } from "./adapters/sandboxesAdapter.js";
27
- export { HealthAdapter } from "./adapters/healthAdapter.js";
28
- export { MetricsAdapter } from "./adapters/metricsAdapter.js";
29
- export { FilesystemAdapter } from "./adapters/filesystemAdapter.js";
30
- export { CommandsAdapter } from "./adapters/commandsAdapter.js";
1
+ import {
2
+ CommandsAdapter,
3
+ FilesystemAdapter,
4
+ HealthAdapter,
5
+ MetricsAdapter,
6
+ SandboxesAdapter,
7
+ createExecdClient,
8
+ createLifecycleClient
9
+ } from "./chunk-NFNOESEY.js";
10
+ export {
11
+ CommandsAdapter,
12
+ FilesystemAdapter,
13
+ HealthAdapter,
14
+ MetricsAdapter,
15
+ SandboxesAdapter,
16
+ createExecdClient,
17
+ createLifecycleClient
18
+ };
31
19
  //# sourceMappingURL=internal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"internal.js","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;;;;;;;;;GASG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAErE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAO7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC"}
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,352 @@
1
+ /**
2
+ * Domain models for filesystem.
3
+ *
4
+ * IMPORTANT:
5
+ * - These are NOT OpenAPI-generated types.
6
+ * - They are intentionally stable and JS-friendly.
7
+ */
8
+ interface FileInfo extends Record<string, unknown> {
9
+ path: string;
10
+ size?: number;
11
+ /**
12
+ * Last modification time.
13
+ */
14
+ modifiedAt?: Date;
15
+ /**
16
+ * Creation time.
17
+ */
18
+ createdAt?: Date;
19
+ mode?: number;
20
+ owner?: string;
21
+ group?: string;
22
+ }
23
+ interface Permission extends Record<string, unknown> {
24
+ mode: number;
25
+ owner?: string;
26
+ group?: string;
27
+ }
28
+ interface FileMetadata extends Record<string, unknown> {
29
+ path: string;
30
+ mode?: number;
31
+ owner?: string;
32
+ group?: string;
33
+ }
34
+ interface RenameFileItem extends Record<string, unknown> {
35
+ src: string;
36
+ dest: string;
37
+ }
38
+ interface ReplaceFileContentItem extends Record<string, unknown> {
39
+ old: string;
40
+ new: string;
41
+ }
42
+ type FilesInfoResponse = Record<string, FileInfo>;
43
+ type SearchFilesResponse = FileInfo[];
44
+ interface WriteEntry {
45
+ path: string;
46
+ /**
47
+ * File data to upload.
48
+ *
49
+ * Supports:
50
+ * - string / bytes / Blob (in-memory)
51
+ * - AsyncIterable<Uint8Array> or ReadableStream<Uint8Array> (streaming upload for large files)
52
+ */
53
+ data?: string | Uint8Array | ArrayBuffer | Blob | AsyncIterable<Uint8Array> | ReadableStream<Uint8Array>;
54
+ mode?: number;
55
+ owner?: string;
56
+ group?: string;
57
+ }
58
+ interface SearchEntry {
59
+ path: string;
60
+ pattern?: string;
61
+ }
62
+ interface MoveEntry {
63
+ src: string;
64
+ dest: string;
65
+ }
66
+ interface ContentReplaceEntry {
67
+ path: string;
68
+ oldContent: string;
69
+ newContent: string;
70
+ }
71
+ interface SetPermissionEntry {
72
+ path: string;
73
+ mode: number;
74
+ owner?: string;
75
+ group?: string;
76
+ }
77
+
78
+ /**
79
+ * High-level filesystem facade (JS-friendly).
80
+ *
81
+ * This interface provides a convenience layer over the underlying execd filesystem API:
82
+ * it offers common operations (read/write/search/move/delete) and supports streaming I/O for large files.
83
+ */
84
+ interface SandboxFiles {
85
+ getFileInfo(paths: string[]): Promise<Record<string, FileInfo>>;
86
+ search(entry: SearchEntry): Promise<SearchFilesResponse>;
87
+ createDirectories(entries: Pick<WriteEntry, "path" | "mode" | "owner" | "group">[]): Promise<void>;
88
+ deleteDirectories(paths: string[]): Promise<void>;
89
+ writeFiles(entries: WriteEntry[]): Promise<void>;
90
+ readFile(path: string, opts?: {
91
+ encoding?: string;
92
+ range?: string;
93
+ }): Promise<string>;
94
+ readBytes(path: string, opts?: {
95
+ range?: string;
96
+ }): Promise<Uint8Array>;
97
+ readBytesStream(path: string, opts?: {
98
+ range?: string;
99
+ }): AsyncIterable<Uint8Array>;
100
+ deleteFiles(paths: string[]): Promise<void>;
101
+ moveFiles(entries: MoveEntry[]): Promise<void>;
102
+ replaceContents(entries: ContentReplaceEntry[]): Promise<void>;
103
+ setPermissions(entries: SetPermissionEntry[]): Promise<void>;
104
+ }
105
+
106
+ interface OutputMessage {
107
+ text: string;
108
+ timestamp: number;
109
+ isError?: boolean;
110
+ }
111
+ interface ExecutionResult {
112
+ text?: string;
113
+ timestamp: number;
114
+ /**
115
+ * Raw mime map from execd event (e.g. "text/plain", "text/html", ...)
116
+ */
117
+ raw?: Record<string, unknown>;
118
+ }
119
+ interface ExecutionError {
120
+ name: string;
121
+ value: string;
122
+ timestamp: number;
123
+ traceback: string[];
124
+ }
125
+ interface ExecutionComplete {
126
+ timestamp: number;
127
+ executionTimeMs: number;
128
+ }
129
+ interface ExecutionInit {
130
+ id: string;
131
+ timestamp: number;
132
+ }
133
+ interface Execution {
134
+ id?: string;
135
+ executionCount?: number;
136
+ logs: {
137
+ stdout: OutputMessage[];
138
+ stderr: OutputMessage[];
139
+ };
140
+ result: ExecutionResult[];
141
+ error?: ExecutionError;
142
+ complete?: ExecutionComplete;
143
+ }
144
+ interface ExecutionHandlers {
145
+ /**
146
+ * Optional low-level hook for every server-sent event (SSE) received.
147
+ * Kept as `unknown` to avoid coupling to a specific OpenAPI schema module.
148
+ */
149
+ onEvent?: (ev: unknown) => void | Promise<void>;
150
+ onStdout?: (msg: OutputMessage) => void | Promise<void>;
151
+ onStderr?: (msg: OutputMessage) => void | Promise<void>;
152
+ onResult?: (res: ExecutionResult) => void | Promise<void>;
153
+ onExecutionComplete?: (c: ExecutionComplete) => void | Promise<void>;
154
+ onError?: (err: ExecutionError) => void | Promise<void>;
155
+ onInit?: (init: ExecutionInit) => void | Promise<void>;
156
+ }
157
+
158
+ /**
159
+ * Domain models for execd interactions.
160
+ *
161
+ * IMPORTANT:
162
+ * - These are NOT OpenAPI-generated types.
163
+ * - They are intentionally stable and JS-friendly.
164
+ */
165
+ interface ServerStreamEvent extends Record<string, unknown> {
166
+ type: "init" | "stdout" | "stderr" | "result" | "execution_count" | "execution_complete" | "error" | string;
167
+ timestamp?: number;
168
+ text?: string;
169
+ results?: Record<string, unknown>;
170
+ error?: Record<string, unknown>;
171
+ }
172
+ interface RunCommandRequest extends Record<string, unknown> {
173
+ command: string;
174
+ cwd?: string;
175
+ background?: boolean;
176
+ }
177
+ interface CodeContextRequest extends Record<string, unknown> {
178
+ language: string;
179
+ }
180
+ type SupportedLanguage = "python" | "go" | "javascript" | "typescript" | "bash" | "java";
181
+ interface RunCommandOpts {
182
+ /**
183
+ * Working directory for command execution (maps to API `cwd`).
184
+ */
185
+ workingDirectory?: string;
186
+ /**
187
+ * Run command in detached mode.
188
+ */
189
+ background?: boolean;
190
+ }
191
+ type CommandExecution = Execution;
192
+ interface Metrics extends Record<string, unknown> {
193
+ cpu_count?: number;
194
+ cpu_used_pct?: number;
195
+ mem_total_mib?: number;
196
+ mem_used_mib?: number;
197
+ timestamp?: number;
198
+ }
199
+ /**
200
+ * Normalized, JS-friendly metrics.
201
+ */
202
+ interface SandboxMetrics {
203
+ cpuCount: number;
204
+ cpuUsedPercentage: number;
205
+ memoryTotalMiB: number;
206
+ memoryUsedMiB: number;
207
+ timestamp: number;
208
+ }
209
+ type PingResponse = Record<string, unknown>;
210
+
211
+ interface ExecdCommands {
212
+ /**
213
+ * Run a command and stream server events (SSE). This is the lowest-level API.
214
+ */
215
+ runStream(command: string, opts?: RunCommandOpts, signal?: AbortSignal): AsyncIterable<ServerStreamEvent>;
216
+ /**
217
+ * Convenience: run a command, consume the stream, and build a structured execution result.
218
+ */
219
+ run(command: string, opts?: RunCommandOpts, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
220
+ /**
221
+ * Interrupt the current execution in the given context/session.
222
+ *
223
+ * Note: Execd spec uses `DELETE /command?id=<sessionId>`.
224
+ */
225
+ interrupt(sessionId: string): Promise<void>;
226
+ }
227
+
228
+ interface ExecdHealth {
229
+ ping(): Promise<boolean>;
230
+ }
231
+
232
+ interface ExecdMetrics {
233
+ getMetrics(): Promise<SandboxMetrics>;
234
+ }
235
+
236
+ /**
237
+ * Domain models for sandbox lifecycle.
238
+ *
239
+ * IMPORTANT:
240
+ * - These are NOT OpenAPI-generated types.
241
+ * - They are intentionally stable and JS-friendly.
242
+ *
243
+ * The internal OpenAPI schemas may change frequently; adapters map responses into these models.
244
+ */
245
+ type SandboxId = string;
246
+ interface ImageAuth extends Record<string, unknown> {
247
+ username?: string;
248
+ password?: string;
249
+ token?: string;
250
+ }
251
+ interface ImageSpec {
252
+ uri: string;
253
+ auth?: ImageAuth;
254
+ }
255
+ type ResourceLimits = Record<string, string>;
256
+ type SandboxState = "Creating" | "Running" | "Pausing" | "Paused" | "Resuming" | "Deleting" | "Deleted" | "Error" | string;
257
+ interface SandboxStatus extends Record<string, unknown> {
258
+ state: SandboxState;
259
+ reason?: string;
260
+ message?: string;
261
+ }
262
+ interface SandboxInfo extends Record<string, unknown> {
263
+ id: SandboxId;
264
+ image: ImageSpec;
265
+ entrypoint: string[];
266
+ metadata?: Record<string, string>;
267
+ status: SandboxStatus;
268
+ /**
269
+ * Sandbox creation time.
270
+ */
271
+ createdAt: Date;
272
+ /**
273
+ * Sandbox expiration time (server-side TTL).
274
+ */
275
+ expiresAt: Date;
276
+ }
277
+ interface CreateSandboxRequest extends Record<string, unknown> {
278
+ image: ImageSpec;
279
+ entrypoint: string[];
280
+ /**
281
+ * Timeout in seconds (server semantics).
282
+ */
283
+ timeout: number;
284
+ resourceLimits: ResourceLimits;
285
+ env?: Record<string, string>;
286
+ metadata?: Record<string, string>;
287
+ extensions?: Record<string, unknown>;
288
+ }
289
+ interface CreateSandboxResponse extends Record<string, unknown> {
290
+ id: SandboxId;
291
+ status: SandboxStatus;
292
+ metadata?: Record<string, string>;
293
+ /**
294
+ * Sandbox expiration time after creation.
295
+ */
296
+ expiresAt: Date;
297
+ /**
298
+ * Sandbox creation time.
299
+ */
300
+ createdAt: Date;
301
+ entrypoint: string[];
302
+ }
303
+ interface PaginationInfo extends Record<string, unknown> {
304
+ page: number;
305
+ pageSize: number;
306
+ totalItems: number;
307
+ totalPages: number;
308
+ hasNextPage: boolean;
309
+ }
310
+ interface ListSandboxesResponse extends Record<string, unknown> {
311
+ items: SandboxInfo[];
312
+ pagination?: PaginationInfo;
313
+ }
314
+ interface RenewSandboxExpirationRequest {
315
+ expiresAt: string;
316
+ }
317
+ interface RenewSandboxExpirationResponse extends Record<string, unknown> {
318
+ /**
319
+ * Updated expiration time (if the server returns it).
320
+ */
321
+ expiresAt?: Date;
322
+ }
323
+ interface Endpoint extends Record<string, unknown> {
324
+ endpoint: string;
325
+ }
326
+ interface ListSandboxesParams {
327
+ /**
328
+ * Filter by lifecycle state (the API supports multiple `state` query params).
329
+ * Example: `{ states: ["Running", "Paused"] }`
330
+ */
331
+ states?: string[];
332
+ /**
333
+ * Filter by metadata key-value pairs.
334
+ * NOTE: This will be encoded to a single `metadata` query parameter as described in the spec.
335
+ */
336
+ metadata?: Record<string, string>;
337
+ page?: number;
338
+ pageSize?: number;
339
+ }
340
+
341
+ interface Sandboxes {
342
+ createSandbox(req: CreateSandboxRequest): Promise<CreateSandboxResponse>;
343
+ getSandbox(sandboxId: SandboxId): Promise<SandboxInfo>;
344
+ listSandboxes(params?: ListSandboxesParams): Promise<ListSandboxesResponse>;
345
+ deleteSandbox(sandboxId: SandboxId): Promise<void>;
346
+ pauseSandbox(sandboxId: SandboxId): Promise<void>;
347
+ resumeSandbox(sandboxId: SandboxId): Promise<void>;
348
+ renewSandboxExpiration(sandboxId: SandboxId, req: RenewSandboxExpirationRequest): Promise<RenewSandboxExpirationResponse>;
349
+ getSandboxEndpoint(sandboxId: SandboxId, port: number): Promise<Endpoint>;
350
+ }
351
+
352
+ export type { RunCommandOpts as A, RunCommandRequest as B, CodeContextRequest as C, SearchEntry as D, ExecdCommands as E, FileInfo as F, SearchFilesResponse as G, SetPermissionEntry as H, SupportedLanguage as I, ListSandboxesResponse as L, Metrics as M, OutputMessage as O, Permission as P, RenewSandboxExpirationResponse as R, Sandboxes as S, WriteEntry as W, SandboxFiles as a, ExecdHealth as b, ExecdMetrics as c, SandboxId as d, SandboxInfo as e, Execution as f, ExecutionHandlers as g, ServerStreamEvent as h, SandboxMetrics as i, Endpoint as j, CommandExecution as k, ContentReplaceEntry as l, CreateSandboxRequest as m, CreateSandboxResponse as n, ExecutionComplete as o, ExecutionError as p, ExecutionInit as q, ExecutionResult as r, FileMetadata as s, FilesInfoResponse as t, ListSandboxesParams as u, MoveEntry as v, PingResponse as w, RenameFileItem as x, RenewSandboxExpirationRequest as y, ReplaceFileContentItem as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alibaba-group/opensandbox",
3
- "version": "0.1.1-dev0",
3
+ "version": "0.1.2-dev0",
4
4
  "description": "OpenSandbox TypeScript/JavaScript SDK (sandbox lifecycle + execd APIs)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -9,10 +9,14 @@
9
9
  "exports": {
10
10
  ".": {
11
11
  "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/cjs/index.cjs",
12
14
  "default": "./dist/index.js"
13
15
  },
14
16
  "./internal": {
15
17
  "types": "./dist/internal.d.ts",
18
+ "import": "./dist/internal.js",
19
+ "require": "./dist/cjs/internal.cjs",
16
20
  "default": "./dist/internal.js"
17
21
  }
18
22
  },
@@ -42,12 +46,13 @@
42
46
  "eslint": "^9.39.2",
43
47
  "globals": "^17.0.0",
44
48
  "openapi-typescript": "^7.9.1",
49
+ "tsup": "^8.5.0",
45
50
  "typescript": "^5.7.2",
46
51
  "typescript-eslint": "^8.52.0"
47
52
  },
48
53
  "scripts": {
49
54
  "gen:api": "node ./scripts/generate-api.mjs",
50
- "build": "pnpm run gen:api && tsc -p tsconfig.json",
55
+ "build": "pnpm run gen:api && tsup",
51
56
  "lint": "eslint src scripts --max-warnings 0",
52
57
  "clean": "rm -rf dist"
53
58
  }
@@ -636,6 +636,12 @@ export interface components {
636
636
  * ]
637
637
  */
638
638
  entrypoint: string[];
639
+ /**
640
+ * @description Optional outbound network policy for the sandbox.
641
+ * Shape matches the sidecar `/policy` endpoint. If omitted or empty,
642
+ * the sidecar starts in allow-all mode until updated.
643
+ */
644
+ networkPolicy?: components["schemas"]["NetworkPolicy"];
639
645
  /**
640
646
  * @description Opaque container for provider-specific or transient parameters not supported by the core API.
641
647
  *
@@ -710,6 +716,32 @@ export interface components {
710
716
  */
711
717
  endpoint: string;
712
718
  };
719
+ /**
720
+ * @description Egress network policy matching the sidecar `/policy` request body.
721
+ * If `default_action` is omitted, the sidecar defaults to "deny"; passing an empty
722
+ * object or null results in allow-all behavior at startup.
723
+ */
724
+ NetworkPolicy: {
725
+ /**
726
+ * @description Default action when no egress rule matches. Defaults to "deny".
727
+ * @enum {string}
728
+ */
729
+ default_action?: "allow" | "deny";
730
+ /** @description List of egress rules evaluated in order. */
731
+ egress?: components["schemas"]["NetworkRule"][];
732
+ };
733
+ NetworkRule: {
734
+ /**
735
+ * @description Whether to allow or deny matching targets.
736
+ * @enum {string}
737
+ */
738
+ action: "allow" | "deny";
739
+ /**
740
+ * @description FQDN or wildcard domain (e.g., "example.com", "*.example.com").
741
+ * IP/CIDR not yet supported in the egress MVP.
742
+ */
743
+ target: string;
744
+ };
713
745
  };
714
746
  responses: {
715
747
  /** @description Error response envelope */
@@ -12,6 +12,8 @@
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
14
 
15
+ import {DEFAULT_USER_AGENT} from "../core/constants.js";
16
+
15
17
  export type ConnectionProtocol = "http" | "https";
16
18
 
17
19
  /**
@@ -250,7 +252,7 @@ export class ConnectionConfig {
250
252
  private _sseFetch: typeof fetch | null;
251
253
  readonly requestTimeoutSeconds: number;
252
254
  readonly debug: boolean;
253
- readonly userAgent: string = "OpenSandbox-JS-SDK/0.1.1";
255
+ readonly userAgent: string = DEFAULT_USER_AGENT;
254
256
  private _closeTransport: () => Promise<void>;
255
257
  private _closePromise: Promise<void> | null = null;
256
258
  private _transportInitialized = false;
@@ -26,4 +26,4 @@ export const DEFAULT_READY_TIMEOUT_SECONDS = 30;
26
26
  export const DEFAULT_HEALTH_CHECK_POLLING_INTERVAL_MILLIS = 200;
27
27
 
28
28
  export const DEFAULT_REQUEST_TIMEOUT_SECONDS = 30;
29
- export const DEFAULT_USER_AGENT = "OpenSandbox-JS-SDK/0.1.0";
29
+ export const DEFAULT_USER_AGENT = "OpenSandbox-JS-SDK/0.1.1";
@@ -1,22 +0,0 @@
1
- import type { ExecdClient } from "../openapi/execdClient.js";
2
- import type { CommandExecution, RunCommandOpts, ServerStreamEvent } from "../models/execd.js";
3
- import type { ExecdCommands } from "../services/execdCommands.js";
4
- import type { ExecutionHandlers } from "../models/execution.js";
5
- export interface CommandsAdapterOptions {
6
- /**
7
- * Must match the baseUrl used by the ExecdClient.
8
- */
9
- baseUrl: string;
10
- fetch?: typeof fetch;
11
- headers?: Record<string, string>;
12
- }
13
- export declare class CommandsAdapter implements ExecdCommands {
14
- private readonly client;
15
- private readonly opts;
16
- private readonly fetch;
17
- constructor(client: ExecdClient, opts: CommandsAdapterOptions);
18
- interrupt(sessionId: string): Promise<void>;
19
- runStream(command: string, opts?: RunCommandOpts, signal?: AbortSignal): AsyncIterable<ServerStreamEvent>;
20
- run(command: string, opts?: RunCommandOpts, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
21
- }
22
- //# sourceMappingURL=commandsAdapter.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commandsAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/commandsAdapter.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAI7D,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC9F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAoBhE,MAAM,WAAW,sBAAsB;IACrC;;OAEG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED,qBAAa,eAAgB,YAAW,aAAa;IAIjD,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,IAAI;IAJvB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAe;gBAGlB,MAAM,EAAE,WAAW,EACnB,IAAI,EAAE,sBAAsB;IAKzC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1C,SAAS,CACd,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,cAAc,EACrB,MAAM,CAAC,EAAE,WAAW,GACnB,aAAa,CAAC,iBAAiB,CAAC;IAoB7B,GAAG,CACP,OAAO,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,cAAc,EACrB,QAAQ,CAAC,EAAE,iBAAiB,EAC5B,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,gBAAgB,CAAC;CAgB7B"}
@@ -1,77 +0,0 @@
1
- // Copyright 2026 Alibaba Group Holding Ltd.
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License");
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- import { throwOnOpenApiFetchError } from "./openapiError.js";
15
- import { parseJsonEventStream } from "./sse.js";
16
- import { ExecutionEventDispatcher } from "../models/executionEventDispatcher.js";
17
- function joinUrl(baseUrl, pathname) {
18
- const base = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
19
- const path = pathname.startsWith("/") ? pathname : `/${pathname}`;
20
- return `${base}${path}`;
21
- }
22
- function toRunCommandRequest(command, opts) {
23
- return {
24
- command,
25
- cwd: opts?.workingDirectory,
26
- background: !!opts?.background,
27
- };
28
- }
29
- export class CommandsAdapter {
30
- client;
31
- opts;
32
- fetch;
33
- constructor(client, opts) {
34
- this.client = client;
35
- this.opts = opts;
36
- this.fetch = opts.fetch ?? fetch;
37
- }
38
- async interrupt(sessionId) {
39
- const { error, response } = await this.client.DELETE("/command", {
40
- params: { query: { id: sessionId } },
41
- });
42
- throwOnOpenApiFetchError({ error, response }, "Interrupt command failed");
43
- }
44
- async *runStream(command, opts, signal) {
45
- const url = joinUrl(this.opts.baseUrl, "/command");
46
- const body = JSON.stringify(toRunCommandRequest(command, opts));
47
- const res = await this.fetch(url, {
48
- method: "POST",
49
- headers: {
50
- "accept": "text/event-stream",
51
- "content-type": "application/json",
52
- ...(this.opts.headers ?? {}),
53
- },
54
- body,
55
- signal,
56
- });
57
- for await (const ev of parseJsonEventStream(res, { fallbackErrorMessage: "Run command failed" })) {
58
- yield ev;
59
- }
60
- }
61
- async run(command, opts, handlers, signal) {
62
- const execution = {
63
- logs: { stdout: [], stderr: [] },
64
- result: [],
65
- };
66
- const dispatcher = new ExecutionEventDispatcher(execution, handlers);
67
- for await (const ev of this.runStream(command, opts, signal)) {
68
- // Keep legacy behavior: if server sends "init" with empty id, preserve previous id.
69
- if (ev.type === "init" && (ev.text ?? "") === "" && execution.id) {
70
- ev.text = execution.id;
71
- }
72
- await dispatcher.dispatch(ev);
73
- }
74
- return execution;
75
- }
76
- }
77
- //# sourceMappingURL=commandsAdapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"commandsAdapter.js","sourceRoot":"","sources":["../../src/adapters/commandsAdapter.ts"],"names":[],"mappings":"AAAA,4CAA4C;AAC5C,GAAG;AACH,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,GAAG;AACH,iDAAiD;AACjD,GAAG;AACH,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAKhD,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AAEjF,SAAS,OAAO,CAAC,OAAe,EAAE,QAAgB;IAChD,MAAM,IAAI,GAAG,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;IACpE,MAAM,IAAI,GAAG,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,QAAQ,EAAE,CAAC;IAClE,OAAO,GAAG,IAAI,GAAG,IAAI,EAAE,CAAC;AAC1B,CAAC;AAKD,SAAS,mBAAmB,CAAC,OAAe,EAAE,IAAqB;IACjE,OAAO;QACL,OAAO;QACP,GAAG,EAAE,IAAI,EAAE,gBAAgB;QAC3B,UAAU,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU;KAC/B,CAAC;AACJ,CAAC;AAWD,MAAM,OAAO,eAAe;IAIP;IACA;IAJF,KAAK,CAAe;IAErC,YACmB,MAAmB,EACnB,IAA4B;QAD5B,WAAM,GAAN,MAAM,CAAa;QACnB,SAAI,GAAJ,IAAI,CAAwB;QAE7C,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,KAAK,CAAC;IACnC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,SAAiB;QAC/B,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE;YAC/D,MAAM,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,EAAE;SACrC,CAAC,CAAC;QACH,wBAAwB,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,0BAA0B,CAAC,CAAC;IAC5E,CAAC;IAED,KAAK,CAAC,CAAC,SAAS,CACd,OAAe,EACf,IAAqB,EACrB,MAAoB;QAEpB,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;QACnD,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAEhE,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE;YAChC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,QAAQ,EAAE,mBAAmB;gBAC7B,cAAc,EAAE,kBAAkB;gBAClC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC;aAC7B;YACD,IAAI;YACJ,MAAM;SACP,CAAC,CAAC;QAEH,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,oBAAoB,CAAoB,GAAG,EAAE,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,CAAC,EAAE,CAAC;YACpH,MAAM,EAAE,CAAC;QACX,CAAC;IACH,CAAC;IAED,KAAK,CAAC,GAAG,CACP,OAAe,EACf,IAAqB,EACrB,QAA4B,EAC5B,MAAoB;QAEpB,MAAM,SAAS,GAAqB;YAClC,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE;YAChC,MAAM,EAAE,EAAE;SACX,CAAC;QACF,MAAM,UAAU,GAAG,IAAI,wBAAwB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QACrE,IAAI,KAAK,EAAE,MAAM,EAAE,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;YAC7D,oFAAoF;YACpF,IAAI,EAAE,CAAC,IAAI,KAAK,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC,KAAK,EAAE,IAAI,SAAS,CAAC,EAAE,EAAE,CAAC;gBAChE,EAAU,CAAC,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC;YAClC,CAAC;YACD,MAAM,UAAU,CAAC,QAAQ,CAAC,EAAS,CAAC,CAAC;QACvC,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
@@ -1,52 +0,0 @@
1
- import type { ExecdClient } from "../openapi/execdClient.js";
2
- import type { SandboxFiles } from "../services/filesystem.js";
3
- import type { ContentReplaceEntry, FileInfo, MoveEntry, SearchEntry, SearchFilesResponse, SetPermissionEntry, WriteEntry } from "../models/filesystem.js";
4
- export interface FilesystemAdapterOptions {
5
- /**
6
- * Must match the baseUrl used by the ExecdClient, used for binary endpoints
7
- * like download/upload where we bypass JSON parsing.
8
- */
9
- baseUrl: string;
10
- fetch?: typeof fetch;
11
- headers?: Record<string, string>;
12
- }
13
- /**
14
- * Filesystem adapter that exposes user-facing file APIs (`sandbox.files`).
15
- *
16
- * This adapter owns all request/response conversions:
17
- * - Maps friendly method shapes to API payloads
18
- * - Parses timestamps into `Date`
19
- * - Implements streaming upload/download helpers
20
- */
21
- export declare class FilesystemAdapter implements SandboxFiles {
22
- private readonly client;
23
- private readonly opts;
24
- private readonly fetch;
25
- private static readonly Api;
26
- constructor(client: ExecdClient, opts: FilesystemAdapterOptions);
27
- private parseIsoDate;
28
- private static readonly _ApiFileInfo;
29
- private mapApiFileInfo;
30
- getFileInfo(paths: string[]): Promise<Record<string, FileInfo>>;
31
- deleteFiles(paths: string[]): Promise<void>;
32
- createDirectories(entries: Pick<WriteEntry, "path" | "mode" | "owner" | "group">[]): Promise<void>;
33
- deleteDirectories(paths: string[]): Promise<void>;
34
- setPermissions(entries: SetPermissionEntry[]): Promise<void>;
35
- moveFiles(entries: MoveEntry[]): Promise<void>;
36
- replaceContents(entries: ContentReplaceEntry[]): Promise<void>;
37
- search(entry: SearchEntry): Promise<SearchFilesResponse>;
38
- private uploadFile;
39
- readBytes(path: string, opts?: {
40
- range?: string;
41
- }): Promise<Uint8Array>;
42
- readBytesStream(path: string, opts?: {
43
- range?: string;
44
- }): AsyncIterable<Uint8Array>;
45
- private downloadStream;
46
- readFile(path: string, opts?: {
47
- encoding?: string;
48
- range?: string;
49
- }): Promise<string>;
50
- writeFiles(entries: WriteEntry[]): Promise<void>;
51
- }
52
- //# sourceMappingURL=filesystemAdapter.d.ts.map