@alibaba-group/opensandbox 0.1.3 → 0.1.5

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.
@@ -103,6 +103,246 @@ interface SandboxFiles {
103
103
  setPermissions(entries: SetPermissionEntry[]): Promise<void>;
104
104
  }
105
105
 
106
+ /**
107
+ * Domain models for sandbox lifecycle.
108
+ *
109
+ * IMPORTANT:
110
+ * - These are NOT OpenAPI-generated types.
111
+ * - They are intentionally stable and JS-friendly.
112
+ *
113
+ * The internal OpenAPI schemas may change frequently; adapters map responses into these models.
114
+ */
115
+ type SandboxId = string;
116
+ interface ImageAuth extends Record<string, unknown> {
117
+ username?: string;
118
+ password?: string;
119
+ token?: string;
120
+ }
121
+ interface ImageSpec {
122
+ uri: string;
123
+ auth?: ImageAuth;
124
+ }
125
+ type ResourceLimits = Record<string, string>;
126
+ type NetworkRuleAction = "allow" | "deny";
127
+ interface NetworkRule extends Record<string, unknown> {
128
+ /**
129
+ * Whether to allow or deny matching targets.
130
+ */
131
+ action: NetworkRuleAction;
132
+ /**
133
+ * FQDN or wildcard domain (e.g., "example.com", "*.example.com").
134
+ * IP/CIDR is not supported in the egress MVP.
135
+ */
136
+ target: string;
137
+ }
138
+ interface NetworkPolicy extends Record<string, unknown> {
139
+ /**
140
+ * Default action when no egress rule matches. Defaults to "deny".
141
+ */
142
+ defaultAction?: NetworkRuleAction;
143
+ /**
144
+ * List of egress rules evaluated in order.
145
+ */
146
+ egress?: NetworkRule[];
147
+ }
148
+ /**
149
+ * Host path bind mount backend.
150
+ *
151
+ * Maps a directory on the host filesystem into the container.
152
+ * Only available when the runtime supports host mounts.
153
+ */
154
+ interface Host extends Record<string, unknown> {
155
+ /**
156
+ * Absolute path on the host filesystem to mount.
157
+ */
158
+ path: string;
159
+ }
160
+ /**
161
+ * Kubernetes PersistentVolumeClaim mount backend.
162
+ *
163
+ * References an existing PVC in the same namespace as the sandbox pod.
164
+ * Only available in Kubernetes runtime.
165
+ */
166
+ interface PVC extends Record<string, unknown> {
167
+ /**
168
+ * Name of the PersistentVolumeClaim in the same namespace.
169
+ */
170
+ claimName: string;
171
+ }
172
+ /**
173
+ * Alibaba Cloud OSS mount backend via ossfs.
174
+ *
175
+ * The runtime mounts a host-side OSS path under `storage.ossfs_mount_root`
176
+ * so the container sees the bucket contents at the specified mount path.
177
+ *
178
+ * In Docker runtime, OSSFS backend requires OpenSandbox Server to run on a Linux host with FUSE support.
179
+ */
180
+ interface OSSFS extends Record<string, unknown> {
181
+ /**
182
+ * OSS bucket name.
183
+ */
184
+ bucket: string;
185
+ /**
186
+ * OSS endpoint (e.g., "oss-cn-hangzhou.aliyuncs.com").
187
+ */
188
+ endpoint: string;
189
+ /**
190
+ * ossfs major version used by runtime mount integration.
191
+ * @default "2.0"
192
+ */
193
+ version?: "1.0" | "2.0";
194
+ /**
195
+ * Additional ossfs mount options.
196
+ *
197
+ * - `1.0`: mounts with `ossfs ... -o <option>`
198
+ * - `2.0`: mounts with `ossfs2 mount ... -c <config-file>` and encodes options as `--<option>` lines in the config file
199
+ */
200
+ options?: string[];
201
+ /**
202
+ * OSS access key ID for inline credentials mode.
203
+ */
204
+ accessKeyId: string;
205
+ /**
206
+ * OSS access key secret for inline credentials mode.
207
+ */
208
+ accessKeySecret: string;
209
+ }
210
+ /**
211
+ * Storage mount definition for a sandbox.
212
+ *
213
+ * Each volume entry contains:
214
+ * - A unique name identifier
215
+ * - Exactly one backend (host, pvc, ossfs) with backend-specific fields
216
+ * - Common mount settings (mountPath, readOnly, subPath)
217
+ */
218
+ interface Volume extends Record<string, unknown> {
219
+ /**
220
+ * Unique identifier for the volume within the sandbox.
221
+ */
222
+ name: string;
223
+ /**
224
+ * Host path bind mount backend (mutually exclusive with pvc, ossfs).
225
+ */
226
+ host?: Host;
227
+ /**
228
+ * Kubernetes PVC mount backend (mutually exclusive with host, ossfs).
229
+ */
230
+ pvc?: PVC;
231
+ /**
232
+ * Alibaba Cloud OSSFS mount backend (mutually exclusive with host, pvc).
233
+ */
234
+ ossfs?: OSSFS;
235
+ /**
236
+ * Absolute path inside the container where the volume is mounted.
237
+ */
238
+ mountPath: string;
239
+ /**
240
+ * If true, the volume is mounted as read-only. Defaults to false (read-write).
241
+ */
242
+ readOnly?: boolean;
243
+ /**
244
+ * Optional subdirectory under the backend path to mount.
245
+ */
246
+ subPath?: string;
247
+ }
248
+ type SandboxState = "Creating" | "Running" | "Pausing" | "Paused" | "Resuming" | "Deleting" | "Deleted" | "Error" | string;
249
+ interface SandboxStatus extends Record<string, unknown> {
250
+ state: SandboxState;
251
+ reason?: string;
252
+ message?: string;
253
+ }
254
+ interface SandboxInfo extends Record<string, unknown> {
255
+ id: SandboxId;
256
+ image: ImageSpec;
257
+ entrypoint: string[];
258
+ metadata?: Record<string, string>;
259
+ status: SandboxStatus;
260
+ /**
261
+ * Sandbox creation time.
262
+ */
263
+ createdAt: Date;
264
+ /**
265
+ * Sandbox expiration time (server-side TTL).
266
+ */
267
+ expiresAt: Date | null;
268
+ }
269
+ interface CreateSandboxRequest extends Record<string, unknown> {
270
+ image: ImageSpec;
271
+ entrypoint: string[];
272
+ /**
273
+ * Timeout in seconds (server semantics).
274
+ */
275
+ timeout?: number | null;
276
+ resourceLimits: ResourceLimits;
277
+ env?: Record<string, string>;
278
+ metadata?: Record<string, string>;
279
+ /**
280
+ * Optional outbound network policy for the sandbox.
281
+ */
282
+ networkPolicy?: NetworkPolicy;
283
+ /**
284
+ * Optional list of volume mounts for persistent storage.
285
+ */
286
+ volumes?: Volume[];
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 | null;
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
+ * Headers that must be included on every request targeting this endpoint
327
+ * (e.g. when the server requires them for routing or auth). Omit or empty if not required.
328
+ */
329
+ headers?: Record<string, string>;
330
+ }
331
+ interface ListSandboxesParams {
332
+ /**
333
+ * Filter by lifecycle state (the API supports multiple `state` query params).
334
+ * Example: `{ states: ["Running", "Paused"] }`
335
+ */
336
+ states?: string[];
337
+ /**
338
+ * Filter by metadata key-value pairs.
339
+ * NOTE: This will be encoded to a single `metadata` query parameter as described in the spec.
340
+ */
341
+ metadata?: Record<string, string>;
342
+ page?: number;
343
+ pageSize?: number;
344
+ }
345
+
106
346
  interface OutputMessage {
107
347
  text: string;
108
348
  timestamp: number;
@@ -140,6 +380,7 @@ interface Execution {
140
380
  result: ExecutionResult[];
141
381
  error?: ExecutionError;
142
382
  complete?: ExecutionComplete;
383
+ exitCode?: number | null;
143
384
  }
144
385
  interface ExecutionHandlers {
145
386
  /**
@@ -169,11 +410,6 @@ interface ServerStreamEvent extends Record<string, unknown> {
169
410
  results?: Record<string, unknown>;
170
411
  error?: Record<string, unknown>;
171
412
  }
172
- interface RunCommandRequest extends Record<string, unknown> {
173
- command: string;
174
- cwd?: string;
175
- background?: boolean;
176
- }
177
413
  interface CodeContextRequest extends Record<string, unknown> {
178
414
  language: string;
179
415
  }
@@ -187,6 +423,36 @@ interface RunCommandOpts {
187
423
  * Run command in detached mode.
188
424
  */
189
425
  background?: boolean;
426
+ /**
427
+ * Maximum execution time in seconds; server will terminate the command when reached.
428
+ * If omitted, the server will not enforce any timeout.
429
+ */
430
+ timeoutSeconds?: number;
431
+ /**
432
+ * Unix user ID used to run the command process.
433
+ */
434
+ uid?: number;
435
+ /**
436
+ * Unix group ID used to run the command process. Requires `uid`.
437
+ */
438
+ gid?: number;
439
+ /**
440
+ * Environment variables injected into the command process.
441
+ */
442
+ envs?: Record<string, string>;
443
+ }
444
+ interface CommandStatus {
445
+ id?: string;
446
+ content?: string;
447
+ running?: boolean;
448
+ exitCode?: number | null;
449
+ error?: string;
450
+ startedAt?: Date;
451
+ finishedAt?: Date | null;
452
+ }
453
+ interface CommandLogs {
454
+ content: string;
455
+ cursor?: number;
190
456
  }
191
457
  type CommandExecution = Execution;
192
458
  interface Metrics extends Record<string, unknown> {
@@ -223,145 +489,41 @@ interface ExecdCommands {
223
489
  * Note: Execd spec uses `DELETE /command?id=<sessionId>`.
224
490
  */
225
491
  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 NetworkRuleAction = "allow" | "deny";
257
- interface NetworkRule extends Record<string, unknown> {
258
- /**
259
- * Whether to allow or deny matching targets.
260
- */
261
- action: NetworkRuleAction;
262
492
  /**
263
- * FQDN or wildcard domain (e.g., "example.com", "*.example.com").
264
- * IP/CIDR is not supported in the egress MVP.
493
+ * Get the current running status for a command id.
265
494
  */
266
- target: string;
267
- }
268
- interface NetworkPolicy extends Record<string, unknown> {
495
+ getCommandStatus(commandId: string): Promise<CommandStatus>;
269
496
  /**
270
- * Default action when no egress rule matches. Defaults to "deny".
497
+ * Get background command logs (non-streamed).
271
498
  */
272
- defaultAction?: NetworkRuleAction;
499
+ getBackgroundCommandLogs(commandId: string, cursor?: number): Promise<CommandLogs>;
273
500
  /**
274
- * List of egress rules evaluated in order.
501
+ * Create a bash session with optional working directory.
502
+ * Returns session ID for use with runInSession and deleteSession.
275
503
  */
276
- egress?: NetworkRule[];
277
- }
278
- type SandboxState = "Creating" | "Running" | "Pausing" | "Paused" | "Resuming" | "Deleting" | "Deleted" | "Error" | string;
279
- interface SandboxStatus extends Record<string, unknown> {
280
- state: SandboxState;
281
- reason?: string;
282
- message?: string;
283
- }
284
- interface SandboxInfo extends Record<string, unknown> {
285
- id: SandboxId;
286
- image: ImageSpec;
287
- entrypoint: string[];
288
- metadata?: Record<string, string>;
289
- status: SandboxStatus;
290
- /**
291
- * Sandbox creation time.
292
- */
293
- createdAt: Date;
294
- /**
295
- * Sandbox expiration time (server-side TTL).
296
- */
297
- expiresAt: Date;
298
- }
299
- interface CreateSandboxRequest extends Record<string, unknown> {
300
- image: ImageSpec;
301
- entrypoint: string[];
302
- /**
303
- * Timeout in seconds (server semantics).
304
- */
305
- timeout: number;
306
- resourceLimits: ResourceLimits;
307
- env?: Record<string, string>;
308
- metadata?: Record<string, string>;
309
- /**
310
- * Optional outbound network policy for the sandbox.
311
- */
312
- networkPolicy?: NetworkPolicy;
313
- extensions?: Record<string, unknown>;
314
- }
315
- interface CreateSandboxResponse extends Record<string, unknown> {
316
- id: SandboxId;
317
- status: SandboxStatus;
318
- metadata?: Record<string, string>;
504
+ createSession(options?: {
505
+ workingDirectory?: string;
506
+ }): Promise<string>;
319
507
  /**
320
- * Sandbox expiration time after creation.
508
+ * Run a shell command in an existing bash session (SSE stream, same event shape as run).
509
+ * Optional workingDirectory and timeout apply to this run only; session state (e.g. env) persists.
321
510
  */
322
- expiresAt: Date;
511
+ runInSession(sessionId: string, command: string, options?: {
512
+ workingDirectory?: string;
513
+ timeout?: number;
514
+ }, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
323
515
  /**
324
- * Sandbox creation time.
516
+ * Delete a bash session by ID. Frees resources; session ID must have been returned by createSession.
325
517
  */
326
- createdAt: Date;
327
- entrypoint: string[];
518
+ deleteSession(sessionId: string): Promise<void>;
328
519
  }
329
- interface PaginationInfo extends Record<string, unknown> {
330
- page: number;
331
- pageSize: number;
332
- totalItems: number;
333
- totalPages: number;
334
- hasNextPage: boolean;
335
- }
336
- interface ListSandboxesResponse extends Record<string, unknown> {
337
- items: SandboxInfo[];
338
- pagination?: PaginationInfo;
339
- }
340
- interface RenewSandboxExpirationRequest {
341
- expiresAt: string;
342
- }
343
- interface RenewSandboxExpirationResponse extends Record<string, unknown> {
344
- /**
345
- * Updated expiration time (if the server returns it).
346
- */
347
- expiresAt?: Date;
348
- }
349
- interface Endpoint extends Record<string, unknown> {
350
- endpoint: string;
520
+
521
+ interface ExecdHealth {
522
+ ping(): Promise<boolean>;
351
523
  }
352
- interface ListSandboxesParams {
353
- /**
354
- * Filter by lifecycle state (the API supports multiple `state` query params).
355
- * Example: `{ states: ["Running", "Paused"] }`
356
- */
357
- states?: string[];
358
- /**
359
- * Filter by metadata key-value pairs.
360
- * NOTE: This will be encoded to a single `metadata` query parameter as described in the spec.
361
- */
362
- metadata?: Record<string, string>;
363
- page?: number;
364
- pageSize?: number;
524
+
525
+ interface ExecdMetrics {
526
+ getMetrics(): Promise<SandboxMetrics>;
365
527
  }
366
528
 
367
529
  interface Sandboxes {
@@ -372,7 +534,7 @@ interface Sandboxes {
372
534
  pauseSandbox(sandboxId: SandboxId): Promise<void>;
373
535
  resumeSandbox(sandboxId: SandboxId): Promise<void>;
374
536
  renewSandboxExpiration(sandboxId: SandboxId, req: RenewSandboxExpirationRequest): Promise<RenewSandboxExpirationResponse>;
375
- getSandboxEndpoint(sandboxId: SandboxId, port: number): Promise<Endpoint>;
537
+ getSandboxEndpoint(sandboxId: SandboxId, port: number, useServerProxy?: boolean): Promise<Endpoint>;
376
538
  }
377
539
 
378
- export type { RenewSandboxExpirationRequest as A, ReplaceFileContentItem as B, CodeContextRequest as C, RunCommandOpts as D, ExecdCommands as E, FileInfo as F, RunCommandRequest as G, SearchEntry as H, SearchFilesResponse as I, SetPermissionEntry as J, SupportedLanguage as K, ListSandboxesResponse as L, Metrics as M, NetworkPolicy as N, 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, NetworkRule as w, NetworkRuleAction as x, PingResponse as y, RenameFileItem as z };
540
+ export type { OutputMessage as A, Permission as B, CodeContextRequest as C, PingResponse as D, ExecdCommands as E, FileInfo as F, RenameFileItem as G, Host as H, RenewSandboxExpirationRequest as I, ReplaceFileContentItem as J, RunCommandOpts as K, ListSandboxesResponse as L, Metrics as M, NetworkPolicy as N, OSSFS as O, PVC as P, SearchEntry as Q, RenewSandboxExpirationResponse as R, Sandboxes as S, SearchFilesResponse as T, SetPermissionEntry as U, Volume as V, SupportedLanguage as W, WriteEntry as X, NetworkRule as a, SandboxFiles as b, ExecdHealth as c, ExecdMetrics as d, SandboxId as e, SandboxInfo as f, Execution as g, ExecutionHandlers as h, ServerStreamEvent as i, SandboxMetrics as j, Endpoint as k, CommandExecution as l, CommandLogs as m, CommandStatus as n, ContentReplaceEntry as o, CreateSandboxRequest as p, CreateSandboxResponse as q, ExecutionComplete as r, ExecutionError as s, ExecutionInit as t, ExecutionResult as u, FileMetadata as v, FilesInfoResponse as w, ListSandboxesParams as x, MoveEntry as y, NetworkRuleAction as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alibaba-group/opensandbox",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "OpenSandbox TypeScript/JavaScript SDK (sandbox lifecycle + execd APIs)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -29,7 +29,7 @@
29
29
  "bugs": {
30
30
  "url": "https://github.com/alibaba/OpenSandbox/issues"
31
31
  },
32
- "homepage": "https://github.com/alibaba/OpenSandbox",
32
+ "homepage": "https://open-sandbox.ai",
33
33
  "files": [
34
34
  "dist",
35
35
  "src"
@@ -53,6 +53,7 @@
53
53
  "scripts": {
54
54
  "gen:api": "node ./scripts/generate-api.mjs",
55
55
  "build": "pnpm run gen:api && tsup",
56
+ "test": "pnpm run build && node --test tests/*.test.mjs",
56
57
  "lint": "eslint src scripts --max-warnings 0",
57
58
  "clean": "rm -rf dist"
58
59
  }