@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.
@@ -1,5 +1,5 @@
1
1
  import { Client } from 'openapi-fetch';
2
- import { S as Sandboxes, m as CreateSandboxRequest, n as CreateSandboxResponse, d as SandboxId, e as SandboxInfo, u as ListSandboxesParams, L as ListSandboxesResponse, A as RenewSandboxExpirationRequest, R as RenewSandboxExpirationResponse, j as Endpoint, b as ExecdHealth, c as ExecdMetrics, i as SandboxMetrics, a as SandboxFiles, F as FileInfo, W as WriteEntry, J as SetPermissionEntry, v as MoveEntry, l as ContentReplaceEntry, H as SearchEntry, I as SearchFilesResponse, E as ExecdCommands, D as RunCommandOpts, h as ServerStreamEvent, g as ExecutionHandlers, k as CommandExecution } from './sandboxes-CLy12BN1.js';
2
+ import { S as Sandboxes, p as CreateSandboxRequest, q as CreateSandboxResponse, e as SandboxId, f as SandboxInfo, x as ListSandboxesParams, L as ListSandboxesResponse, I as RenewSandboxExpirationRequest, R as RenewSandboxExpirationResponse, k as Endpoint, c as ExecdHealth, d as ExecdMetrics, j as SandboxMetrics, b as SandboxFiles, F as FileInfo, X as WriteEntry, U as SetPermissionEntry, y as MoveEntry, o as ContentReplaceEntry, Q as SearchEntry, T as SearchFilesResponse, E as ExecdCommands, n as CommandStatus, m as CommandLogs, K as RunCommandOpts, i as ServerStreamEvent, h as ExecutionHandlers, l as CommandExecution } from './sandboxes-DL9uUHGR.js';
3
3
 
4
4
  /**
5
5
  * This file was auto-generated by openapi-typescript.
@@ -382,7 +382,10 @@ interface paths$1 {
382
382
  */
383
383
  get: {
384
384
  parameters: {
385
- query?: never;
385
+ query?: {
386
+ /** @description Whether to return a server-proxied URL */
387
+ use_server_proxy?: boolean;
388
+ };
386
389
  header?: never;
387
390
  path: {
388
391
  /** @description Unique sandbox identifier */
@@ -454,9 +457,9 @@ interface components$1 {
454
457
  };
455
458
  /**
456
459
  * Format: date-time
457
- * @description Timestamp when sandbox will auto-terminate
460
+ * @description Timestamp when sandbox will auto-terminate. Omitted when manual cleanup is enabled.
458
461
  */
459
- expiresAt: string;
462
+ expiresAt?: string;
460
463
  /**
461
464
  * Format: date-time
462
465
  * @description Sandbox creation timestamp
@@ -487,9 +490,9 @@ interface components$1 {
487
490
  entrypoint: string[];
488
491
  /**
489
492
  * Format: date-time
490
- * @description Timestamp when sandbox will auto-terminate
493
+ * @description Timestamp when sandbox will auto-terminate. Omitted when manual cleanup is enabled.
491
494
  */
492
- expiresAt: string;
495
+ expiresAt?: string;
493
496
  /**
494
497
  * Format: date-time
495
498
  * @description Sandbox creation timestamp
@@ -572,9 +575,12 @@ interface components$1 {
572
575
  image: components$1["schemas"]["ImageSpec"];
573
576
  /**
574
577
  * @description Sandbox timeout in seconds. The sandbox will automatically terminate after this duration.
575
- * SDK clients should provide a default value (e.g., 3600 seconds / 1 hour).
578
+ * The maximum is controlled by the server configuration (`server.max_sandbox_timeout_seconds`).
579
+ * Omit this field or set it to null to disable automatic expiration and require explicit cleanup.
580
+ * Note: manual cleanup support is runtime-dependent; Kubernetes providers may reject
581
+ * omitted or null timeout when the underlying workload provider does not support non-expiring sandboxes.
576
582
  */
577
- timeout: number;
583
+ timeout?: number | null;
578
584
  /**
579
585
  * @description Runtime resource constraints for the sandbox instance.
580
586
  * SDK clients should provide sensible defaults (e.g., cpu: "500m", memory: "512Mi").
@@ -629,6 +635,12 @@ interface components$1 {
629
635
  * the sidecar starts in allow-all mode until updated.
630
636
  */
631
637
  networkPolicy?: components$1["schemas"]["NetworkPolicy"];
638
+ /**
639
+ * @description Storage mounts for the sandbox. Each volume entry specifies a named backend-specific
640
+ * storage source and common mount settings. Exactly one backend type must be specified
641
+ * per volume entry.
642
+ */
643
+ volumes?: components$1["schemas"]["Volume"][];
632
644
  /**
633
645
  * @description Opaque container for provider-specific or transient parameters not supported by the core API.
634
646
  *
@@ -637,6 +649,9 @@ interface components$1 {
637
649
  * **Best Practices**:
638
650
  * - **Namespacing**: Use prefixed keys (e.g., `storage.id`) to prevent collisions.
639
651
  * - **Pass-through**: SDKs and middleware must treat this object as opaque and pass it through transparently.
652
+ *
653
+ * **Well-known keys**:
654
+ * - `access.renew.extend.seconds` (optional): Decimal integer string from **300** to **86400** (5 minutes to 24 hours inclusive). Opts the sandbox into OSEP-0009 renew-on-access and sets per-renewal extension seconds. Omit to disable. Invalid values are rejected at creation with HTTP 400 (validated on the lifecycle create endpoint via `validate_extensions` in server `src/extensions/validation.py`).
640
655
  */
641
656
  extensions?: {
642
657
  [key: string]: string;
@@ -702,6 +717,10 @@ interface components$1 {
702
717
  * Example: endpoint.opensandbox.io/sandboxes/abc123/port/8080
703
718
  */
704
719
  endpoint: string;
720
+ /** @description Requests targeting the sandbox must include the corresponding header(s). */
721
+ headers?: {
722
+ [key: string]: string;
723
+ };
705
724
  };
706
725
  /**
707
726
  * @description Egress network policy matching the sidecar `/policy` request body.
@@ -729,6 +748,102 @@ interface components$1 {
729
748
  */
730
749
  target: string;
731
750
  };
751
+ /**
752
+ * @description Storage mount definition for a sandbox. Each volume entry contains:
753
+ * - A unique name identifier
754
+ * - Exactly one backend struct (host, pvc, ossfs, etc.) with backend-specific fields
755
+ * - Common mount settings (mountPath, readOnly, subPath)
756
+ */
757
+ Volume: {
758
+ /**
759
+ * @description Unique identifier for the volume within the sandbox.
760
+ * Must be a valid DNS label (lowercase alphanumeric, hyphens allowed, max 63 chars).
761
+ */
762
+ name: string;
763
+ host?: components$1["schemas"]["Host"];
764
+ pvc?: components$1["schemas"]["PVC"];
765
+ ossfs?: components$1["schemas"]["OSSFS"];
766
+ /**
767
+ * @description Absolute path inside the container where the volume is mounted.
768
+ * Must start with '/'.
769
+ */
770
+ mountPath: string;
771
+ /**
772
+ * @description If true, the volume is mounted as read-only. Defaults to false (read-write).
773
+ * @default false
774
+ */
775
+ readOnly: boolean;
776
+ /**
777
+ * @description Optional subdirectory under the backend path to mount.
778
+ * For `ossfs` backend, this field is used as the bucket prefix.
779
+ * Must be a relative path without '..' components.
780
+ */
781
+ subPath?: string;
782
+ };
783
+ /**
784
+ * @description Host path bind mount backend. Maps a directory on the host filesystem
785
+ * into the container. Only available when the runtime supports host mounts.
786
+ *
787
+ * Security note: Host paths are restricted by server-side allowlist.
788
+ * Users must specify paths under permitted prefixes.
789
+ */
790
+ Host: {
791
+ /**
792
+ * @description Absolute path on the host filesystem to mount.
793
+ * Must start with '/' and be under an allowed prefix.
794
+ */
795
+ path: string;
796
+ };
797
+ /**
798
+ * @description Platform-managed named volume backend. A runtime-neutral abstraction
799
+ * for referencing a pre-existing, platform-managed named volume.
800
+ *
801
+ * - Kubernetes: maps to a PersistentVolumeClaim in the same namespace.
802
+ * - Docker: maps to a Docker named volume (created via `docker volume create`).
803
+ *
804
+ * The volume must already exist on the target platform before sandbox
805
+ * creation.
806
+ */
807
+ PVC: {
808
+ /**
809
+ * @description Name of the volume on the target platform.
810
+ * In Kubernetes this is the PVC name; in Docker this is the named
811
+ * volume name. Must be a valid DNS label.
812
+ */
813
+ claimName: string;
814
+ };
815
+ /**
816
+ * @description Alibaba Cloud OSS mount backend via ossfs.
817
+ *
818
+ * The runtime mounts a host-side OSS path under `storage.ossfs_mount_root`
819
+ * and bind-mounts the resolved path into the sandbox container.
820
+ * Prefix selection is expressed via `Volume.subPath`.
821
+ * In Docker runtime, OSSFS backend requires OpenSandbox Server to run on a Linux host with FUSE support.
822
+ */
823
+ OSSFS: {
824
+ /** @description OSS bucket name. */
825
+ bucket: string;
826
+ /** @description OSS endpoint (e.g., `oss-cn-hangzhou.aliyuncs.com`). */
827
+ endpoint: string;
828
+ /**
829
+ * @description ossfs major version used by runtime mount integration.
830
+ * @default 2.0
831
+ * @enum {string}
832
+ */
833
+ version: "1.0" | "2.0";
834
+ /**
835
+ * @description Additional ossfs mount options.
836
+ * Runtime encodes options by `version`:
837
+ * - `1.0`: mounts with `ossfs ... -o <option>`
838
+ * - `2.0`: mounts with `ossfs2 mount ... -c <config-file>` and encodes options as `--<option>` lines in the config file
839
+ * Option values must be provided as raw payloads without leading `-`.
840
+ */
841
+ options?: string[];
842
+ /** @description OSS access key ID for inline credentials mode. */
843
+ accessKeyId: string;
844
+ /** @description OSS access key secret for inline credentials mode. */
845
+ accessKeySecret: string;
846
+ };
732
847
  };
733
848
  responses: {
734
849
  /** @description Error response envelope */
@@ -847,6 +962,12 @@ declare function createLifecycleClient(opts?: CreateLifecycleClientOptions): Lif
847
962
  * This file was auto-generated by openapi-typescript.
848
963
  * Do not make direct changes to the file.
849
964
  */
965
+ /**
966
+ * NOTE: The session-related path types and operations in this file (e.g. /session, runInSession)
967
+ * are generated from the execd OpenAPI spec. They are not the recommended runtime entry point.
968
+ * Use `sandbox.commands.createSession()`, `sandbox.commands.runInSession()`, and
969
+ * `sandbox.commands.deleteSession()` instead.
970
+ */
850
971
  interface paths {
851
972
  "/ping": {
852
973
  parameters: {
@@ -973,6 +1094,71 @@ interface paths {
973
1094
  patch?: never;
974
1095
  trace?: never;
975
1096
  };
1097
+ "/session": {
1098
+ parameters: {
1099
+ query?: never;
1100
+ header?: never;
1101
+ path?: never;
1102
+ cookie?: never;
1103
+ };
1104
+ get?: never;
1105
+ put?: never;
1106
+ /**
1107
+ * Create bash session (create_session)
1108
+ * @description Creates a new bash session and returns a session ID for subsequent run_in_session requests.
1109
+ * The session maintains shell state (e.g. working directory, environment) across multiple
1110
+ * code executions. Request body is optional; an empty body uses default options (no cwd override).
1111
+ */
1112
+ post: operations["createSession"];
1113
+ delete?: never;
1114
+ options?: never;
1115
+ head?: never;
1116
+ patch?: never;
1117
+ trace?: never;
1118
+ };
1119
+ "/session/{sessionId}/run": {
1120
+ parameters: {
1121
+ query?: never;
1122
+ header?: never;
1123
+ path?: never;
1124
+ cookie?: never;
1125
+ };
1126
+ get?: never;
1127
+ put?: never;
1128
+ /**
1129
+ * Run command in bash session (run_in_session)
1130
+ * @description Executes a shell command in an existing bash session and streams the output in real-time via SSE
1131
+ * (Server-Sent Events). The session must have been created by create_session. Supports
1132
+ * optional working directory override and timeout (milliseconds).
1133
+ */
1134
+ post: operations["runInSession"];
1135
+ delete?: never;
1136
+ options?: never;
1137
+ head?: never;
1138
+ patch?: never;
1139
+ trace?: never;
1140
+ };
1141
+ "/session/{sessionId}": {
1142
+ parameters: {
1143
+ query?: never;
1144
+ header?: never;
1145
+ path?: never;
1146
+ cookie?: never;
1147
+ };
1148
+ get?: never;
1149
+ put?: never;
1150
+ post?: never;
1151
+ /**
1152
+ * Delete bash session (delete_session)
1153
+ * @description Deletes an existing bash session by ID. Terminates the underlying shell process
1154
+ * and releases resources. The session ID must have been returned by create_session.
1155
+ */
1156
+ delete: operations["deleteSession"];
1157
+ options?: never;
1158
+ head?: never;
1159
+ patch?: never;
1160
+ trace?: never;
1161
+ };
976
1162
  "/command": {
977
1163
  parameters: {
978
1164
  query?: never;
@@ -987,6 +1173,9 @@ interface paths {
987
1173
  * @description Executes a shell command and streams the output in real-time using SSE (Server-Sent Events).
988
1174
  * The command can run in foreground or background mode. The response includes stdout, stderr,
989
1175
  * execution status, and completion events.
1176
+ * Optionally specify `timeout` (milliseconds) to enforce a maximum runtime; the server will
1177
+ * terminate the process when the timeout is reached. You can also pass `uid`/`gid` to run
1178
+ * with specific user/group IDs, and `envs` to inject environment variables.
990
1179
  */
991
1180
  post: operations["runCommand"];
992
1181
  /**
@@ -1298,6 +1487,41 @@ interface paths {
1298
1487
  }
1299
1488
  interface components {
1300
1489
  schemas: {
1490
+ /** @description Request to create a bash session (optional body; empty treated as defaults) */
1491
+ CreateSessionRequest: {
1492
+ /**
1493
+ * @description Working directory for the session (optional)
1494
+ * @example /workspace
1495
+ */
1496
+ cwd?: string;
1497
+ };
1498
+ /** @description Response for create_session */
1499
+ CreateSessionResponse: {
1500
+ /**
1501
+ * @description Unique session ID for run_in_session and delete_session
1502
+ * @example session-abc123
1503
+ */
1504
+ session_id: string;
1505
+ };
1506
+ /** @description Request to run a command in an existing bash session */
1507
+ RunInSessionRequest: {
1508
+ /**
1509
+ * @description Shell command to execute in the session
1510
+ * @example echo "Hello"
1511
+ */
1512
+ command: string;
1513
+ /**
1514
+ * @description Working directory override for this run (optional)
1515
+ * @example /workspace
1516
+ */
1517
+ cwd?: string;
1518
+ /**
1519
+ * Format: int64
1520
+ * @description Maximum execution time in milliseconds (optional; server may not enforce if omitted)
1521
+ * @example 30000
1522
+ */
1523
+ timeout?: number;
1524
+ };
1301
1525
  /** @description Request to create a code execution context */
1302
1526
  CodeContextRequest: {
1303
1527
  /**
@@ -1348,6 +1572,34 @@ interface components {
1348
1572
  * @example false
1349
1573
  */
1350
1574
  background: boolean;
1575
+ /**
1576
+ * Format: int64
1577
+ * @description Maximum allowed execution time in milliseconds before the command is forcefully terminated by the server. If omitted, the server will not enforce any timeout.
1578
+ * @example 60000
1579
+ */
1580
+ timeout?: number;
1581
+ /**
1582
+ * Format: int32
1583
+ * @description Unix user ID used to run the command. If `gid` is provided, `uid` is required.
1584
+ * @example 1000
1585
+ */
1586
+ uid?: number;
1587
+ /**
1588
+ * Format: int32
1589
+ * @description Unix group ID used to run the command. Requires `uid` to be provided.
1590
+ * @example 1000
1591
+ */
1592
+ gid?: number;
1593
+ /**
1594
+ * @description Environment variables injected into the command process.
1595
+ * @example {
1596
+ * "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
1597
+ * "PYTHONUNBUFFERED": "1"
1598
+ * }
1599
+ */
1600
+ envs?: {
1601
+ [key: string]: string;
1602
+ };
1351
1603
  };
1352
1604
  /** @description Command execution status (foreground or background) */
1353
1605
  CommandStatusResponse: {
@@ -1866,6 +2118,91 @@ interface operations {
1866
2118
  500: components["responses"]["InternalServerError"];
1867
2119
  };
1868
2120
  };
2121
+ createSession: {
2122
+ parameters: {
2123
+ query?: never;
2124
+ header?: never;
2125
+ path?: never;
2126
+ cookie?: never;
2127
+ };
2128
+ requestBody?: {
2129
+ content: {
2130
+ "application/json": components["schemas"]["CreateSessionRequest"];
2131
+ };
2132
+ };
2133
+ responses: {
2134
+ /** @description Session created successfully */
2135
+ 200: {
2136
+ headers: {
2137
+ [name: string]: unknown;
2138
+ };
2139
+ content: {
2140
+ "application/json": components["schemas"]["CreateSessionResponse"];
2141
+ };
2142
+ };
2143
+ 400: components["responses"]["BadRequest"];
2144
+ 500: components["responses"]["InternalServerError"];
2145
+ };
2146
+ };
2147
+ runInSession: {
2148
+ parameters: {
2149
+ query?: never;
2150
+ header?: never;
2151
+ path: {
2152
+ /**
2153
+ * @description Session ID returned by create_session
2154
+ * @example session-abc123
2155
+ */
2156
+ sessionId: string;
2157
+ };
2158
+ cookie?: never;
2159
+ };
2160
+ requestBody: {
2161
+ content: {
2162
+ "application/json": components["schemas"]["RunInSessionRequest"];
2163
+ };
2164
+ };
2165
+ responses: {
2166
+ /** @description Stream of execution events */
2167
+ 200: {
2168
+ headers: {
2169
+ [name: string]: unknown;
2170
+ };
2171
+ content: {
2172
+ "text/event-stream": components["schemas"]["ServerStreamEvent"];
2173
+ };
2174
+ };
2175
+ 400: components["responses"]["BadRequest"];
2176
+ 500: components["responses"]["InternalServerError"];
2177
+ };
2178
+ };
2179
+ deleteSession: {
2180
+ parameters: {
2181
+ query?: never;
2182
+ header?: never;
2183
+ path: {
2184
+ /**
2185
+ * @description Session ID to delete
2186
+ * @example session-abc123
2187
+ */
2188
+ sessionId: string;
2189
+ };
2190
+ cookie?: never;
2191
+ };
2192
+ requestBody?: never;
2193
+ responses: {
2194
+ /** @description Session deleted successfully */
2195
+ 200: {
2196
+ headers: {
2197
+ [name: string]: unknown;
2198
+ };
2199
+ content?: never;
2200
+ };
2201
+ 400: components["responses"]["BadRequest"];
2202
+ 404: components["responses"]["NotFound"];
2203
+ 500: components["responses"]["InternalServerError"];
2204
+ };
2205
+ };
1869
2206
  runCommand: {
1870
2207
  parameters: {
1871
2208
  query?: never;
@@ -2423,6 +2760,7 @@ declare class SandboxesAdapter implements Sandboxes {
2423
2760
  private readonly client;
2424
2761
  constructor(client: LifecycleClient);
2425
2762
  private parseIsoDate;
2763
+ private parseOptionalIsoDate;
2426
2764
  private mapSandboxInfo;
2427
2765
  createSandbox(req: CreateSandboxRequest): Promise<CreateSandboxResponse>;
2428
2766
  getSandbox(sandboxId: SandboxId): Promise<SandboxInfo>;
@@ -2431,7 +2769,7 @@ declare class SandboxesAdapter implements Sandboxes {
2431
2769
  pauseSandbox(sandboxId: SandboxId): Promise<void>;
2432
2770
  resumeSandbox(sandboxId: SandboxId): Promise<void>;
2433
2771
  renewSandboxExpiration(sandboxId: SandboxId, req: RenewSandboxExpirationRequest): Promise<RenewSandboxExpirationResponse>;
2434
- getSandboxEndpoint(sandboxId: SandboxId, port: number): Promise<Endpoint>;
2772
+ getSandboxEndpoint(sandboxId: SandboxId, port: number, useServerProxy?: boolean): Promise<Endpoint>;
2435
2773
  }
2436
2774
 
2437
2775
  declare class HealthAdapter implements ExecdHealth {
@@ -2508,9 +2846,27 @@ declare class CommandsAdapter implements ExecdCommands {
2508
2846
  private readonly opts;
2509
2847
  private readonly fetch;
2510
2848
  constructor(client: ExecdClient, opts: CommandsAdapterOptions);
2849
+ private buildRunStreamSpec;
2850
+ private buildRunInSessionStreamSpec;
2851
+ private streamExecution;
2852
+ private consumeExecutionStream;
2511
2853
  interrupt(sessionId: string): Promise<void>;
2854
+ getCommandStatus(commandId: string): Promise<CommandStatus>;
2855
+ getBackgroundCommandLogs(commandId: string, cursor?: number): Promise<CommandLogs>;
2512
2856
  runStream(command: string, opts?: RunCommandOpts, signal?: AbortSignal): AsyncIterable<ServerStreamEvent>;
2513
2857
  run(command: string, opts?: RunCommandOpts, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
2858
+ createSession(options?: {
2859
+ workingDirectory?: string;
2860
+ }): Promise<string>;
2861
+ runInSessionStream(sessionId: string, command: string, opts?: {
2862
+ workingDirectory?: string;
2863
+ timeout?: number;
2864
+ }, signal?: AbortSignal): AsyncIterable<ServerStreamEvent>;
2865
+ runInSession(sessionId: string, command: string, options?: {
2866
+ workingDirectory?: string;
2867
+ timeout?: number;
2868
+ }, handlers?: ExecutionHandlers, signal?: AbortSignal): Promise<CommandExecution>;
2869
+ deleteSession(sessionId: string): Promise<void>;
2514
2870
  }
2515
2871
 
2516
2872
  export { CommandsAdapter, type ExecdClient, type paths as ExecdPaths, FilesystemAdapter, HealthAdapter, type LifecycleClient, type paths$1 as LifecyclePaths, MetricsAdapter, SandboxesAdapter, createExecdClient, createLifecycleClient };
package/dist/internal.js CHANGED
@@ -6,7 +6,7 @@ import {
6
6
  SandboxesAdapter,
7
7
  createExecdClient,
8
8
  createLifecycleClient
9
- } from "./chunk-4EF4ODU2.js";
9
+ } from "./chunk-XHEWHFQ6.js";
10
10
  export {
11
11
  CommandsAdapter,
12
12
  FilesystemAdapter,