computesdk 1.18.1 → 1.19.0

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.
package/dist/index.d.mts CHANGED
@@ -113,8 +113,36 @@ interface CreateSandboxOptions$1 {
113
113
  envs?: Record<string, string>;
114
114
  name?: string;
115
115
  namespace?: string;
116
+ directory?: string;
117
+ overlays?: SandboxOverlayConfig[];
118
+ servers?: SandboxServerConfig[];
116
119
  [key: string]: any;
117
120
  }
121
+ interface SandboxOverlayConfig {
122
+ source: string;
123
+ target: string;
124
+ ignore?: string[];
125
+ strategy?: 'copy' | 'smart';
126
+ }
127
+ type SandboxRestartPolicy = 'never' | 'on-failure' | 'always';
128
+ interface SandboxServerConfig {
129
+ slug: string;
130
+ start: string;
131
+ install?: string;
132
+ path?: string;
133
+ port?: number;
134
+ strict_port?: boolean;
135
+ autostart?: boolean;
136
+ env_file?: string;
137
+ environment?: Record<string, string>;
138
+ restart_policy?: SandboxRestartPolicy;
139
+ max_restarts?: number;
140
+ restart_delay_ms?: number;
141
+ stop_timeout_ms?: number;
142
+ depends_on?: string[];
143
+ overlay?: SandboxOverlayConfig;
144
+ overlays?: SandboxOverlayConfig[];
145
+ }
118
146
  /**
119
147
  * Universal Sandbox Interface
120
148
  *
@@ -1099,6 +1127,212 @@ declare class Terminal {
1099
1127
  destroy(id: string): Promise<void>;
1100
1128
  }
1101
1129
 
1130
+ /**
1131
+ * Overlay - Resource namespace for filesystem overlay operations
1132
+ *
1133
+ * Overlays enable instant sandbox setup from template directories by copying
1134
+ * files directly for isolation, with heavy directories copied in the background.
1135
+ */
1136
+ /**
1137
+ * Options for waiting for overlay copy completion
1138
+ */
1139
+ interface WaitForCompletionOptions {
1140
+ /** Maximum number of retry attempts (default: 60) */
1141
+ maxRetries?: number;
1142
+ /** Initial delay between retries in milliseconds (default: 500) */
1143
+ initialDelayMs?: number;
1144
+ /** Maximum delay between retries in milliseconds (default: 5000) */
1145
+ maxDelayMs?: number;
1146
+ /** Backoff multiplier for exponential backoff (default: 1.5) */
1147
+ backoffFactor?: number;
1148
+ }
1149
+ /**
1150
+ * Strategy for creating an overlay
1151
+ * - 'copy': Full copy of all files (standard behavior)
1152
+ * - 'smart': Use symlinks for immutable packages (e.g. node_modules) for instant creation
1153
+ */
1154
+ type OverlayStrategy = 'copy' | 'smart';
1155
+ /**
1156
+ * Options for creating an overlay
1157
+ */
1158
+ interface CreateOverlayOptions {
1159
+ /** Absolute path to source directory (template) */
1160
+ source: string;
1161
+ /** Relative path in sandbox where overlay will be mounted */
1162
+ target: string;
1163
+ /** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
1164
+ ignore?: string[];
1165
+ /** Strategy to use (default: 'smart') */
1166
+ strategy?: OverlayStrategy;
1167
+ /** If true, wait for background copy to complete before returning (default: false) */
1168
+ waitForCompletion?: boolean | WaitForCompletionOptions;
1169
+ }
1170
+ /**
1171
+ * Copy status for overlay background operations
1172
+ */
1173
+ type OverlayCopyStatus = 'pending' | 'in_progress' | 'complete' | 'failed';
1174
+ /**
1175
+ * Statistics about an overlay
1176
+ */
1177
+ interface OverlayStats {
1178
+ /** Number of copied files */
1179
+ copiedFiles: number;
1180
+ /** Number of copied directories (heavy dirs copied in background) */
1181
+ copiedDirs: number;
1182
+ /** Paths that were skipped (e.g., .git, ignored patterns) */
1183
+ skipped: string[];
1184
+ }
1185
+ /**
1186
+ * Overlay information (client-side normalized type)
1187
+ */
1188
+ interface OverlayInfo {
1189
+ /** Unique overlay identifier */
1190
+ id: string;
1191
+ /** Absolute path to source directory */
1192
+ source: string;
1193
+ /** Relative path in sandbox */
1194
+ target: string;
1195
+ /** Strategy used for the overlay */
1196
+ strategy: OverlayStrategy;
1197
+ /** When the overlay was created */
1198
+ createdAt: string;
1199
+ /** Statistics about the overlay */
1200
+ stats: OverlayStats;
1201
+ /** Copy status for background operations */
1202
+ copyStatus: OverlayCopyStatus;
1203
+ /** Error message if copy failed */
1204
+ copyError?: string;
1205
+ }
1206
+ /**
1207
+ * API response for overlay operations (snake_case from server)
1208
+ */
1209
+ interface OverlayResponse {
1210
+ id: string;
1211
+ source: string;
1212
+ target: string;
1213
+ strategy?: string;
1214
+ created_at: string;
1215
+ stats: {
1216
+ copied_files: number;
1217
+ copied_dirs: number;
1218
+ skipped: string[];
1219
+ };
1220
+ copy_status: string;
1221
+ copy_error?: string;
1222
+ }
1223
+ /**
1224
+ * API response for listing overlays
1225
+ */
1226
+ interface OverlayListResponse {
1227
+ overlays: OverlayResponse[];
1228
+ }
1229
+ /**
1230
+ * Overlay resource namespace
1231
+ *
1232
+ * @example
1233
+ * ```typescript
1234
+ * // Create an overlay from a template directory
1235
+ * const overlay = await sandbox.filesystem.overlay.create({
1236
+ * source: '/templates/nextjs',
1237
+ * target: 'project',
1238
+ * });
1239
+ * console.log(overlay.copyStatus); // 'pending' | 'in_progress' | 'complete' | 'failed'
1240
+ *
1241
+ * // Create an overlay and wait for background copy to complete
1242
+ * const overlay = await sandbox.filesystem.overlay.create({
1243
+ * source: '/templates/nextjs',
1244
+ * target: 'project',
1245
+ * waitForCompletion: true, // blocks until copy is complete
1246
+ * });
1247
+ *
1248
+ * // Wait for an existing overlay's copy to complete
1249
+ * const overlay = await sandbox.filesystem.overlay.waitForCompletion('overlay-id');
1250
+ *
1251
+ * // List all overlays
1252
+ * const overlays = await sandbox.filesystem.overlay.list();
1253
+ *
1254
+ * // Get a specific overlay (useful for polling copy status)
1255
+ * const overlay = await sandbox.filesystem.overlay.retrieve('overlay-id');
1256
+ * if (overlay.copyStatus === 'complete') {
1257
+ * console.log('Background copy finished!');
1258
+ * }
1259
+ *
1260
+ * // Delete an overlay
1261
+ * await sandbox.filesystem.overlay.destroy('overlay-id');
1262
+ * ```
1263
+ */
1264
+ declare class Overlay {
1265
+ private createHandler;
1266
+ private listHandler;
1267
+ private retrieveHandler;
1268
+ private destroyHandler;
1269
+ constructor(handlers: {
1270
+ create: (options: CreateOverlayOptions) => Promise<OverlayResponse>;
1271
+ list: () => Promise<OverlayListResponse>;
1272
+ retrieve: (id: string) => Promise<OverlayResponse>;
1273
+ destroy: (id: string) => Promise<void>;
1274
+ });
1275
+ /**
1276
+ * Create a new overlay from a template directory
1277
+ *
1278
+ * The overlay copies files from the source directory into the target path
1279
+ * for better isolation. Heavy directories (node_modules, .venv, etc.) are
1280
+ * copied in the background. Use the `ignore` option to exclude files/directories.
1281
+ *
1282
+ * @param options - Overlay creation options
1283
+ * @param options.source - Absolute path to source directory
1284
+ * @param options.target - Relative path in sandbox
1285
+ * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
1286
+ * @param options.strategy - Strategy to use ('copy' or 'smart')
1287
+ * @param options.waitForCompletion - If true or options object, wait for background copy to complete
1288
+ * @returns Overlay info with copy status
1289
+ */
1290
+ create(options: CreateOverlayOptions): Promise<OverlayInfo>;
1291
+ /**
1292
+ * List all overlays for the current sandbox
1293
+ * @returns Array of overlay info
1294
+ */
1295
+ list(): Promise<OverlayInfo[]>;
1296
+ /**
1297
+ * Retrieve a specific overlay by ID
1298
+ *
1299
+ * Useful for polling the copy status of an overlay.
1300
+ *
1301
+ * @param id - Overlay ID
1302
+ * @returns Overlay info
1303
+ */
1304
+ retrieve(id: string): Promise<OverlayInfo>;
1305
+ /**
1306
+ * Destroy (delete) an overlay
1307
+ * @param id - Overlay ID
1308
+ */
1309
+ destroy(id: string): Promise<void>;
1310
+ /**
1311
+ * Wait for an overlay's background copy to complete
1312
+ *
1313
+ * Polls the overlay status with exponential backoff until the copy
1314
+ * is complete or fails. Throws an error if the copy fails or times out.
1315
+ *
1316
+ * @param id - Overlay ID
1317
+ * @param options - Polling options
1318
+ * @returns Overlay info with final copy status
1319
+ * @throws Error if copy fails or times out
1320
+ */
1321
+ waitForCompletion(id: string, options?: WaitForCompletionOptions): Promise<OverlayInfo>;
1322
+ /**
1323
+ * Convert API response to OverlayInfo
1324
+ */
1325
+ private toOverlayInfo;
1326
+ /**
1327
+ * Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
1328
+ */
1329
+ private validateStrategy;
1330
+ /**
1331
+ * Validate and return copy status, defaulting to 'pending' for unknown values
1332
+ */
1333
+ private validateCopyStatus;
1334
+ }
1335
+
1102
1336
  /**
1103
1337
  * Server - Resource namespace for managed server operations
1104
1338
  */
@@ -1119,6 +1353,18 @@ interface ServerStartOptions {
1119
1353
  env_file?: string;
1120
1354
  /** Inline environment variables (merged with env_file if both provided) */
1121
1355
  environment?: Record<string, string>;
1356
+ /** Requested port number (preallocated before start) */
1357
+ port?: number;
1358
+ /** If true, fail instead of auto-incrementing when port is taken */
1359
+ strict_port?: boolean;
1360
+ /** Whether to auto-start the server on daemon boot (default: true) */
1361
+ autostart?: boolean;
1362
+ /** Inline overlay to create before starting the server */
1363
+ overlay?: Omit<CreateOverlayOptions, 'waitForCompletion'>;
1364
+ /** Additional overlays to create before starting the server */
1365
+ overlays?: Array<Omit<CreateOverlayOptions, 'waitForCompletion'>>;
1366
+ /** Overlay IDs this server depends on (waits for copy completion) */
1367
+ depends_on?: string[];
1122
1368
  /**
1123
1369
  * When to automatically restart the server:
1124
1370
  * - `never`: No automatic restart (default)
@@ -1164,6 +1410,18 @@ interface ServerStartOptions {
1164
1410
  * restart_delay_ms: 2000,
1165
1411
  * });
1166
1412
  *
1413
+ * // Start with inline overlay dependencies
1414
+ * const server = await sandbox.server.start({
1415
+ * slug: 'web',
1416
+ * start: 'npm run dev',
1417
+ * path: '/app',
1418
+ * overlay: {
1419
+ * source: '/templates/nextjs',
1420
+ * target: 'app',
1421
+ * strategy: 'smart',
1422
+ * },
1423
+ * });
1424
+ *
1167
1425
  * // List all servers
1168
1426
  * const servers = await sandbox.server.list();
1169
1427
  *
@@ -1173,6 +1431,9 @@ interface ServerStartOptions {
1173
1431
  * // Stop a server (graceful shutdown with SIGTERM → SIGKILL)
1174
1432
  * await sandbox.server.stop('api');
1175
1433
  *
1434
+ * // Delete a server config
1435
+ * await sandbox.server.delete('api');
1436
+ *
1176
1437
  * // Restart a server
1177
1438
  * await sandbox.server.restart('api');
1178
1439
  * ```
@@ -1200,6 +1461,7 @@ declare class Server {
1200
1461
  private listHandler;
1201
1462
  private retrieveHandler;
1202
1463
  private stopHandler;
1464
+ private deleteHandler;
1203
1465
  private restartHandler;
1204
1466
  private updateStatusHandler;
1205
1467
  private logsHandler;
@@ -1208,6 +1470,7 @@ declare class Server {
1208
1470
  list: () => Promise<ServersListResponse>;
1209
1471
  retrieve: (slug: string) => Promise<ServerResponse>;
1210
1472
  stop: (slug: string) => Promise<ServerStopResponse | void>;
1473
+ delete: (slug: string) => Promise<void>;
1211
1474
  restart: (slug: string) => Promise<ServerResponse>;
1212
1475
  updateStatus: (slug: string, status: ServerStatus) => Promise<void>;
1213
1476
  logs: (slug: string, options?: ServerLogsOptions) => Promise<ServerLogsResponse>;
@@ -1264,10 +1527,15 @@ declare class Server {
1264
1527
  */
1265
1528
  retrieve(slug: string): Promise<ServerInfo>;
1266
1529
  /**
1267
- * Stop a server by slug
1530
+ * Stop a server by slug (non-destructive)
1268
1531
  * @param slug - The server slug
1269
1532
  */
1270
1533
  stop(slug: string): Promise<void>;
1534
+ /**
1535
+ * Delete a server config by slug (stops + removes persistence)
1536
+ * @param slug - The server slug
1537
+ */
1538
+ delete(slug: string): Promise<void>;
1271
1539
  /**
1272
1540
  * Restart a server by slug
1273
1541
  * @param slug - The server slug
@@ -1955,30 +2223,99 @@ declare class Run {
1955
2223
  }
1956
2224
 
1957
2225
  /**
1958
- * Child - Resource namespace for child sandbox operations
2226
+ * Client Types
2227
+ *
2228
+ * Types specific to the gateway Sandbox client implementation.
2229
+ * Core universal types are imported from ../types/universal-sandbox
1959
2230
  */
1960
2231
 
1961
2232
  /**
1962
- * Child resource namespace for managing child sandboxes
1963
- *
1964
- * Child sandboxes are isolated environments within the parent sandbox,
1965
- * each with their own filesystem. Available only in multi-tenant mode.
1966
- *
1967
- * @example
1968
- * ```typescript
1969
- * // Create a new child sandbox
1970
- * const child = await sandbox.child.create();
1971
- * console.log(child.url); // https://sandbox-12345.sandbox.computesdk.com
1972
- *
1973
- * // List all children
1974
- * const all = await sandbox.child.list();
1975
- *
1976
- * // Get a specific child
1977
- * const info = await sandbox.child.retrieve('sandbox-12345');
1978
- *
1979
- * // Delete a child sandbox
1980
- * await sandbox.child.destroy('sandbox-12345');
1981
- *
2233
+ * Sandbox status types (client-specific, more limited than universal)
2234
+ */
2235
+ type SandboxStatus = 'running' | 'stopped' | 'error';
2236
+ /**
2237
+ * Provider-agnostic sandbox info (alias for SandboxInfo for backward compatibility)
2238
+ */
2239
+ interface ProviderSandboxInfo {
2240
+ /** Unique identifier for the sandbox */
2241
+ id: string;
2242
+ /** Provider hosting the sandbox */
2243
+ provider: string;
2244
+ /** Runtime environment in the sandbox */
2245
+ runtime: Runtime;
2246
+ /** Current status of the sandbox */
2247
+ status: SandboxStatus;
2248
+ /** When the sandbox was created */
2249
+ createdAt: Date;
2250
+ /** Execution timeout in milliseconds */
2251
+ timeout: number;
2252
+ /** Additional provider-specific metadata */
2253
+ metadata?: Record<string, any>;
2254
+ }
2255
+ /**
2256
+ * Error thrown when a command exits with a non-zero status
2257
+ */
2258
+ declare class CommandExitError extends Error {
2259
+ result: {
2260
+ exitCode: number;
2261
+ stdout: string;
2262
+ stderr: string;
2263
+ error: boolean;
2264
+ };
2265
+ name: string;
2266
+ constructor(result: {
2267
+ exitCode: number;
2268
+ stdout: string;
2269
+ stderr: string;
2270
+ error: boolean;
2271
+ });
2272
+ }
2273
+ /**
2274
+ * Type guard to check if an error is a CommandExitError
2275
+ */
2276
+ declare function isCommandExitError(error: unknown): error is CommandExitError;
2277
+
2278
+ /**
2279
+ * Child - Resource namespace for child sandbox operations
2280
+ */
2281
+
2282
+ /**
2283
+ * Child resource namespace for managing child sandboxes
2284
+ *
2285
+ * Child sandboxes are isolated environments within the parent sandbox,
2286
+ * each with their own filesystem. Available only in multi-tenant mode.
2287
+ *
2288
+ * @example
2289
+ * ```typescript
2290
+ * // Create a new child sandbox
2291
+ * const child = await sandbox.child.create({
2292
+ * directory: '/custom/path',
2293
+ * overlays: [
2294
+ * {
2295
+ * source: '/templates/nextjs',
2296
+ * target: 'app',
2297
+ * strategy: 'smart',
2298
+ * },
2299
+ * ],
2300
+ * servers: [
2301
+ * {
2302
+ * slug: 'web',
2303
+ * start: 'npm run dev',
2304
+ * path: '/app',
2305
+ * },
2306
+ * ],
2307
+ * });
2308
+ * console.log(child.url); // https://sandbox-12345.sandbox.computesdk.com
2309
+ *
2310
+ * // List all children
2311
+ * const all = await sandbox.child.list();
2312
+ *
2313
+ * // Get a specific child
2314
+ * const info = await sandbox.child.retrieve('sandbox-12345');
2315
+ *
2316
+ * // Delete a child sandbox
2317
+ * await sandbox.child.destroy('sandbox-12345');
2318
+ *
1982
2319
  * // Delete child and its files
1983
2320
  * await sandbox.child.destroy('sandbox-12345', { deleteFiles: true });
1984
2321
  * ```
@@ -1989,7 +2326,7 @@ declare class Child {
1989
2326
  private retrieveHandler;
1990
2327
  private destroyHandler;
1991
2328
  constructor(handlers: {
1992
- create: () => Promise<SandboxInfo>;
2329
+ create: (options?: CreateSandboxOptions$1) => Promise<SandboxInfo>;
1993
2330
  list: () => Promise<SandboxesListResponse>;
1994
2331
  retrieve: (subdomain: string) => Promise<SandboxInfo>;
1995
2332
  destroy: (subdomain: string, deleteFiles: boolean) => Promise<void>;
@@ -1998,7 +2335,7 @@ declare class Child {
1998
2335
  * Create a new child sandbox
1999
2336
  * @returns Child sandbox info including URL and subdomain
2000
2337
  */
2001
- create(): Promise<SandboxInfo>;
2338
+ create(options?: CreateSandboxOptions$1): Promise<SandboxInfo>;
2002
2339
  /**
2003
2340
  * List all child sandboxes
2004
2341
  * @returns Array of child sandbox info
@@ -2022,209 +2359,36 @@ declare class Child {
2022
2359
  }
2023
2360
 
2024
2361
  /**
2025
- * Overlay - Resource namespace for filesystem overlay operations
2026
- *
2027
- * Overlays enable instant sandbox setup from template directories by copying
2028
- * files directly for isolation, with heavy directories copied in the background.
2362
+ * Ready - Resource namespace for gateway readiness
2029
2363
  */
2364
+
2030
2365
  /**
2031
- * Options for waiting for overlay copy completion
2032
- */
2033
- interface WaitForCompletionOptions {
2034
- /** Maximum number of retry attempts (default: 60) */
2035
- maxRetries?: number;
2036
- /** Initial delay between retries in milliseconds (default: 500) */
2037
- initialDelayMs?: number;
2038
- /** Maximum delay between retries in milliseconds (default: 5000) */
2039
- maxDelayMs?: number;
2040
- /** Backoff multiplier for exponential backoff (default: 1.5) */
2041
- backoffFactor?: number;
2042
- }
2043
- /**
2044
- * Strategy for creating an overlay
2045
- * - 'copy': Full copy of all files (standard behavior)
2046
- * - 'smart': Use symlinks for immutable packages (e.g. node_modules) for instant creation
2047
- */
2048
- type OverlayStrategy = 'copy' | 'smart';
2049
- /**
2050
- * Options for creating an overlay
2051
- */
2052
- interface CreateOverlayOptions {
2053
- /** Absolute path to source directory (template) */
2054
- source: string;
2055
- /** Relative path in sandbox where overlay will be mounted */
2056
- target: string;
2057
- /** Glob patterns to ignore (e.g., ["node_modules", "*.log"]) */
2058
- ignore?: string[];
2059
- /** Strategy to use (default: 'smart') */
2060
- strategy?: OverlayStrategy;
2061
- /** If true, wait for background copy to complete before returning (default: false) */
2062
- waitForCompletion?: boolean | WaitForCompletionOptions;
2063
- }
2064
- /**
2065
- * Copy status for overlay background operations
2066
- */
2067
- type OverlayCopyStatus = 'pending' | 'in_progress' | 'complete' | 'failed';
2068
- /**
2069
- * Statistics about an overlay
2070
- */
2071
- interface OverlayStats {
2072
- /** Number of copied files */
2073
- copiedFiles: number;
2074
- /** Number of copied directories (heavy dirs copied in background) */
2075
- copiedDirs: number;
2076
- /** Paths that were skipped (e.g., .git, ignored patterns) */
2077
- skipped: string[];
2078
- }
2079
- /**
2080
- * Overlay information (client-side normalized type)
2081
- */
2082
- interface OverlayInfo {
2083
- /** Unique overlay identifier */
2084
- id: string;
2085
- /** Absolute path to source directory */
2086
- source: string;
2087
- /** Relative path in sandbox */
2088
- target: string;
2089
- /** Strategy used for the overlay */
2090
- strategy: OverlayStrategy;
2091
- /** When the overlay was created */
2092
- createdAt: string;
2093
- /** Statistics about the overlay */
2094
- stats: OverlayStats;
2095
- /** Copy status for background operations */
2096
- copyStatus: OverlayCopyStatus;
2097
- /** Error message if copy failed */
2098
- copyError?: string;
2099
- }
2100
- /**
2101
- * API response for overlay operations (snake_case from server)
2102
- */
2103
- interface OverlayResponse {
2104
- id: string;
2105
- source: string;
2106
- target: string;
2107
- strategy?: string;
2108
- created_at: string;
2109
- stats: {
2110
- copied_files: number;
2111
- copied_dirs: number;
2112
- skipped: string[];
2113
- };
2114
- copy_status: string;
2115
- copy_error?: string;
2116
- }
2117
- /**
2118
- * API response for listing overlays
2366
+ * Ready info returned by readiness endpoint
2119
2367
  */
2120
- interface OverlayListResponse {
2121
- overlays: OverlayResponse[];
2368
+ interface ReadyInfo {
2369
+ ready: boolean;
2370
+ servers: ReadyResponse['servers'];
2371
+ overlays: ReadyResponse['overlays'];
2122
2372
  }
2123
2373
  /**
2124
- * Overlay resource namespace
2374
+ * Ready resource namespace
2125
2375
  *
2126
2376
  * @example
2127
2377
  * ```typescript
2128
- * // Create an overlay from a template directory
2129
- * const overlay = await sandbox.filesystem.overlay.create({
2130
- * source: '/templates/nextjs',
2131
- * target: 'project',
2132
- * });
2133
- * console.log(overlay.copyStatus); // 'pending' | 'in_progress' | 'complete' | 'failed'
2134
- *
2135
- * // Create an overlay and wait for background copy to complete
2136
- * const overlay = await sandbox.filesystem.overlay.create({
2137
- * source: '/templates/nextjs',
2138
- * target: 'project',
2139
- * waitForCompletion: true, // blocks until copy is complete
2140
- * });
2141
- *
2142
- * // Wait for an existing overlay's copy to complete
2143
- * const overlay = await sandbox.filesystem.overlay.waitForCompletion('overlay-id');
2144
- *
2145
- * // List all overlays
2146
- * const overlays = await sandbox.filesystem.overlay.list();
2147
- *
2148
- * // Get a specific overlay (useful for polling copy status)
2149
- * const overlay = await sandbox.filesystem.overlay.retrieve('overlay-id');
2150
- * if (overlay.copyStatus === 'complete') {
2151
- * console.log('Background copy finished!');
2152
- * }
2153
- *
2154
- * // Delete an overlay
2155
- * await sandbox.filesystem.overlay.destroy('overlay-id');
2378
+ * const status = await sandbox.ready.get();
2379
+ * console.log(status.ready);
2380
+ * console.log(status.servers);
2156
2381
  * ```
2157
2382
  */
2158
- declare class Overlay {
2159
- private createHandler;
2160
- private listHandler;
2161
- private retrieveHandler;
2162
- private destroyHandler;
2383
+ declare class Ready {
2384
+ private getHandler;
2163
2385
  constructor(handlers: {
2164
- create: (options: CreateOverlayOptions) => Promise<OverlayResponse>;
2165
- list: () => Promise<OverlayListResponse>;
2166
- retrieve: (id: string) => Promise<OverlayResponse>;
2167
- destroy: (id: string) => Promise<void>;
2386
+ get: () => Promise<ReadyResponse>;
2168
2387
  });
2169
2388
  /**
2170
- * Create a new overlay from a template directory
2171
- *
2172
- * The overlay copies files from the source directory into the target path
2173
- * for better isolation. Heavy directories (node_modules, .venv, etc.) are
2174
- * copied in the background. Use the `ignore` option to exclude files/directories.
2175
- *
2176
- * @param options - Overlay creation options
2177
- * @param options.source - Absolute path to source directory
2178
- * @param options.target - Relative path in sandbox
2179
- * @param options.ignore - Glob patterns to ignore (e.g., ["node_modules", "*.log"])
2180
- * @param options.strategy - Strategy to use ('copy' or 'smart')
2181
- * @param options.waitForCompletion - If true or options object, wait for background copy to complete
2182
- * @returns Overlay info with copy status
2183
- */
2184
- create(options: CreateOverlayOptions): Promise<OverlayInfo>;
2185
- /**
2186
- * List all overlays for the current sandbox
2187
- * @returns Array of overlay info
2389
+ * Get readiness status for autostarted servers and overlays
2188
2390
  */
2189
- list(): Promise<OverlayInfo[]>;
2190
- /**
2191
- * Retrieve a specific overlay by ID
2192
- *
2193
- * Useful for polling the copy status of an overlay.
2194
- *
2195
- * @param id - Overlay ID
2196
- * @returns Overlay info
2197
- */
2198
- retrieve(id: string): Promise<OverlayInfo>;
2199
- /**
2200
- * Destroy (delete) an overlay
2201
- * @param id - Overlay ID
2202
- */
2203
- destroy(id: string): Promise<void>;
2204
- /**
2205
- * Wait for an overlay's background copy to complete
2206
- *
2207
- * Polls the overlay status with exponential backoff until the copy
2208
- * is complete or fails. Throws an error if the copy fails or times out.
2209
- *
2210
- * @param id - Overlay ID
2211
- * @param options - Polling options
2212
- * @returns Overlay info with final copy status
2213
- * @throws Error if copy fails or times out
2214
- */
2215
- waitForCompletion(id: string, options?: WaitForCompletionOptions): Promise<OverlayInfo>;
2216
- /**
2217
- * Convert API response to OverlayInfo
2218
- */
2219
- private toOverlayInfo;
2220
- /**
2221
- * Validate and return strategy, defaulting to 'copy' for unknown/missing values (legacy support)
2222
- */
2223
- private validateStrategy;
2224
- /**
2225
- * Validate and return copy status, defaulting to 'pending' for unknown values
2226
- */
2227
- private validateCopyStatus;
2391
+ get(): Promise<ReadyInfo>;
2228
2392
  }
2229
2393
 
2230
2394
  /**
@@ -2271,59 +2435,6 @@ declare function encodeBinaryMessage(message: any): ArrayBuffer;
2271
2435
  */
2272
2436
  declare function decodeBinaryMessage(buffer: ArrayBuffer | Uint8Array): any;
2273
2437
 
2274
- /**
2275
- * Client Types
2276
- *
2277
- * Types specific to the gateway Sandbox client implementation.
2278
- * Core universal types are imported from ../types/universal-sandbox
2279
- */
2280
-
2281
- /**
2282
- * Sandbox status types (client-specific, more limited than universal)
2283
- */
2284
- type SandboxStatus = 'running' | 'stopped' | 'error';
2285
- /**
2286
- * Provider-agnostic sandbox info (alias for SandboxInfo for backward compatibility)
2287
- */
2288
- interface ProviderSandboxInfo {
2289
- /** Unique identifier for the sandbox */
2290
- id: string;
2291
- /** Provider hosting the sandbox */
2292
- provider: string;
2293
- /** Runtime environment in the sandbox */
2294
- runtime: Runtime;
2295
- /** Current status of the sandbox */
2296
- status: SandboxStatus;
2297
- /** When the sandbox was created */
2298
- createdAt: Date;
2299
- /** Execution timeout in milliseconds */
2300
- timeout: number;
2301
- /** Additional provider-specific metadata */
2302
- metadata?: Record<string, any>;
2303
- }
2304
- /**
2305
- * Error thrown when a command exits with a non-zero status
2306
- */
2307
- declare class CommandExitError extends Error {
2308
- result: {
2309
- exitCode: number;
2310
- stdout: string;
2311
- stderr: string;
2312
- error: boolean;
2313
- };
2314
- name: string;
2315
- constructor(result: {
2316
- exitCode: number;
2317
- stdout: string;
2318
- stderr: string;
2319
- error: boolean;
2320
- });
2321
- }
2322
- /**
2323
- * Type guard to check if an error is a CommandExitError
2324
- */
2325
- declare function isCommandExitError(error: unknown): error is CommandExitError;
2326
-
2327
2438
  /**
2328
2439
  * ComputeSDK Client - Universal Sandbox Implementation
2329
2440
  *
@@ -2703,6 +2814,12 @@ interface ServerInfo {
2703
2814
  env_file?: string;
2704
2815
  /** Inline environment variables */
2705
2816
  environment?: Record<string, string>;
2817
+ /** Whether to auto-start the server on daemon boot */
2818
+ autostart?: boolean;
2819
+ /** If true, port allocation is strict (no auto-increment) */
2820
+ strict_port?: boolean;
2821
+ /** Overlay IDs this server depends on */
2822
+ depends_on?: string[];
2706
2823
  /** Auto-detected port number (populated when port monitor detects listening port) */
2707
2824
  port?: number;
2708
2825
  /** Generated URL from subdomain + port (populated when port is detected) */
@@ -2728,6 +2845,32 @@ interface ServerInfo {
2728
2845
  /** When the server was last updated */
2729
2846
  updated_at: string;
2730
2847
  }
2848
+ /**
2849
+ * Ready server info returned by readiness endpoint
2850
+ */
2851
+ interface ReadyServerInfo {
2852
+ slug: string;
2853
+ port?: number;
2854
+ url?: string;
2855
+ status: ServerStatus;
2856
+ }
2857
+ /**
2858
+ * Ready overlay info returned by readiness endpoint
2859
+ */
2860
+ interface ReadyOverlayInfo {
2861
+ id: string;
2862
+ source: string;
2863
+ target: string;
2864
+ copy_status: string;
2865
+ }
2866
+ /**
2867
+ * Ready response (public endpoint)
2868
+ */
2869
+ interface ReadyResponse {
2870
+ ready: boolean;
2871
+ servers: ReadyServerInfo[];
2872
+ overlays: ReadyOverlayInfo[];
2873
+ }
2731
2874
  /**
2732
2875
  * Servers list response
2733
2876
  */
@@ -2933,6 +3076,7 @@ declare class Sandbox {
2933
3076
  readonly sessionToken: SessionToken;
2934
3077
  readonly magicLink: MagicLink;
2935
3078
  readonly signal: Signal;
3079
+ readonly ready: Ready;
2936
3080
  readonly file: File;
2937
3081
  readonly env: Env;
2938
3082
  readonly auth: Auth;
@@ -3381,6 +3525,12 @@ declare class Sandbox {
3381
3525
  * @param options.path - Working directory (optional)
3382
3526
  * @param options.env_file - Path to .env file relative to path (optional)
3383
3527
  * @param options.environment - Inline environment variables (merged with env_file if both provided)
3528
+ * @param options.port - Requested port (preallocated before start)
3529
+ * @param options.strict_port - If true, fail instead of auto-incrementing when port is taken
3530
+ * @param options.autostart - Auto-start on daemon boot (default: true)
3531
+ * @param options.overlay - Inline overlay to create before starting
3532
+ * @param options.overlays - Additional overlays to create before starting
3533
+ * @param options.depends_on - Overlay IDs this server depends on
3384
3534
  * @param options.restart_policy - When to automatically restart: 'never' (default), 'on-failure', 'always'
3385
3535
  * @param options.max_restarts - Maximum restart attempts, 0 = unlimited (default: 0)
3386
3536
  * @param options.restart_delay_ms - Delay between restart attempts in milliseconds (default: 1000)
@@ -3407,6 +3557,18 @@ declare class Sandbox {
3407
3557
  * restart_delay_ms: 2000,
3408
3558
  * stop_timeout_ms: 5000,
3409
3559
  * });
3560
+ *
3561
+ * // With inline overlay dependencies
3562
+ * await sandbox.startServer({
3563
+ * slug: 'web',
3564
+ * start: 'npm run dev',
3565
+ * path: '/app',
3566
+ * overlay: {
3567
+ * source: '/templates/nextjs',
3568
+ * target: 'app',
3569
+ * strategy: 'smart',
3570
+ * },
3571
+ * });
3410
3572
  * ```
3411
3573
  */
3412
3574
  startServer(options: {
@@ -3416,6 +3578,12 @@ declare class Sandbox {
3416
3578
  path?: string;
3417
3579
  env_file?: string;
3418
3580
  environment?: Record<string, string>;
3581
+ port?: number;
3582
+ strict_port?: boolean;
3583
+ autostart?: boolean;
3584
+ overlay?: Omit<CreateOverlayOptions, 'waitForCompletion'>;
3585
+ overlays?: Array<Omit<CreateOverlayOptions, 'waitForCompletion'>>;
3586
+ depends_on?: string[];
3419
3587
  restart_policy?: RestartPolicy;
3420
3588
  max_restarts?: number;
3421
3589
  restart_delay_ms?: number;
@@ -3427,10 +3595,15 @@ declare class Sandbox {
3427
3595
  */
3428
3596
  getServer(slug: string): Promise<ServerResponse>;
3429
3597
  /**
3430
- * Stop a managed server
3598
+ * Stop a managed server (non-destructive)
3431
3599
  * @param slug - Server slug
3432
3600
  */
3433
3601
  stopServer(slug: string): Promise<ServerStopResponse>;
3602
+ /**
3603
+ * Delete a managed server configuration
3604
+ * @param slug - Server slug
3605
+ */
3606
+ deleteServer(slug: string): Promise<void>;
3434
3607
  /**
3435
3608
  * Restart a managed server
3436
3609
  * @param slug - Server slug
@@ -3450,10 +3623,14 @@ declare class Sandbox {
3450
3623
  * @param status - New server status
3451
3624
  */
3452
3625
  updateServerStatus(slug: string, status: ServerStatus): Promise<ServerStatusUpdateResponse>;
3626
+ /**
3627
+ * Get readiness status for autostarted servers and overlays
3628
+ */
3629
+ getReady(): Promise<ReadyResponse>;
3453
3630
  /**
3454
3631
  * Create a new sandbox environment
3455
3632
  */
3456
- createSandbox(): Promise<SandboxInfo>;
3633
+ createSandbox(options?: CreateSandboxOptions$1): Promise<SandboxInfo>;
3457
3634
  /**
3458
3635
  * List all sandboxes
3459
3636
  */
@@ -3584,6 +3761,28 @@ declare class Sandbox {
3584
3761
  disconnect(): Promise<void>;
3585
3762
  }
3586
3763
 
3764
+ /**
3765
+ * Helpers for building setup payloads used by COMPUTESDK_SETUP_B64 or POST /sandboxes
3766
+ */
3767
+
3768
+ type SetupOverlayConfig = Omit<CreateOverlayOptions, 'waitForCompletion'>;
3769
+ interface SetupPayload {
3770
+ overlays?: SetupOverlayConfig[];
3771
+ servers?: ServerStartOptions[];
3772
+ }
3773
+ interface BuildSetupPayloadOptions {
3774
+ overlays?: CreateOverlayOptions[];
3775
+ servers?: ServerStartOptions[];
3776
+ }
3777
+ /**
3778
+ * Build a setup payload for COMPUTESDK_SETUP_B64 or POST /sandboxes
3779
+ */
3780
+ declare const buildSetupPayload: (options: BuildSetupPayloadOptions) => SetupPayload;
3781
+ /**
3782
+ * Build and base64-encode a setup payload for COMPUTESDK_SETUP_B64
3783
+ */
3784
+ declare const encodeSetupPayload: (options: BuildSetupPayloadOptions) => string;
3785
+
3587
3786
  /**
3588
3787
  * Unified Provider Configuration
3589
3788
  *
@@ -3611,6 +3810,7 @@ declare const PROVIDER_AUTH: {
3611
3810
  readonly cloudflare: readonly [readonly ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"]];
3612
3811
  readonly codesandbox: readonly [readonly ["CSB_API_KEY"]];
3613
3812
  readonly blaxel: readonly [readonly ["BL_API_KEY", "BL_WORKSPACE"]];
3813
+ readonly namespace: readonly [readonly ["NSC_TOKEN"]];
3614
3814
  };
3615
3815
  /**
3616
3816
  * All supported provider names (excluding gateway which is special)
@@ -3726,6 +3926,9 @@ interface ExplicitComputeConfig {
3726
3926
  apiKey?: string;
3727
3927
  workspace?: string;
3728
3928
  };
3929
+ namespace?: {
3930
+ token?: string;
3931
+ };
3729
3932
  }
3730
3933
  /**
3731
3934
  * Options for creating a sandbox via the gateway
@@ -3740,8 +3943,13 @@ interface CreateSandboxOptions {
3740
3943
  envs?: Record<string, string>;
3741
3944
  name?: string;
3742
3945
  namespace?: string;
3946
+ directory?: string;
3947
+ overlays?: SetupOverlayConfig[];
3948
+ servers?: ServerStartOptions[];
3743
3949
  /** Docker image to use for the sandbox (for infrastructure providers like Railway) */
3744
3950
  image?: string;
3951
+ /** Provider-specific snapshot to create from (e.g., Vercel snapshots) */
3952
+ snapshotId?: string;
3745
3953
  }
3746
3954
  /**
3747
3955
  * Options for finding or creating a named sandbox
@@ -3797,6 +4005,27 @@ declare class ComputeManager {
3797
4005
  sandbox: {
3798
4006
  /**
3799
4007
  * Create a new sandbox
4008
+ *
4009
+ * @example
4010
+ * ```typescript
4011
+ * const sandbox = await compute.sandbox.create({
4012
+ * directory: '/custom/path',
4013
+ * overlays: [
4014
+ * {
4015
+ * source: '/templates/nextjs',
4016
+ * target: 'app',
4017
+ * strategy: 'smart',
4018
+ * },
4019
+ * ],
4020
+ * servers: [
4021
+ * {
4022
+ * slug: 'web',
4023
+ * start: 'npm run dev',
4024
+ * path: '/app',
4025
+ * },
4026
+ * ],
4027
+ * });
4028
+ * ```
3800
4029
  */
3801
4030
  create: (options?: CreateSandboxOptions) => Promise<Sandbox>;
3802
4031
  /**
@@ -3917,7 +4146,7 @@ declare const GATEWAY_URL = "https://gateway.computesdk.com";
3917
4146
  * Provider detection priority order
3918
4147
  * When multiple provider credentials are detected, use the first one in this list
3919
4148
  */
3920
- declare const PROVIDER_PRIORITY: readonly ["e2b", "railway", "render", "daytona", "modal", "runloop", "vercel", "cloudflare", "codesandbox", "blaxel"];
4149
+ declare const PROVIDER_PRIORITY: readonly ["e2b", "railway", "render", "daytona", "modal", "runloop", "vercel", "cloudflare", "codesandbox", "blaxel", "namespace"];
3921
4150
  /**
3922
4151
  * Required environment variables for each provider
3923
4152
  * @deprecated Use PROVIDER_AUTH from provider-config instead
@@ -3933,6 +4162,7 @@ declare const PROVIDER_ENV_VARS: {
3933
4162
  readonly cloudflare: readonly ["CLOUDFLARE_API_TOKEN", "CLOUDFLARE_ACCOUNT_ID"];
3934
4163
  readonly codesandbox: readonly ["CSB_API_KEY"];
3935
4164
  readonly blaxel: readonly ["BL_API_KEY", "BL_WORKSPACE"];
4165
+ readonly namespace: readonly ["NSC_TOKEN"];
3936
4166
  };
3937
4167
 
3938
- export { type CallableCompute, type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type CreateSandboxOptions$1 as CreateSandboxOptions, type ExplicitComputeConfig, type FileEntry, FileWatcher, GATEWAY_URL, Sandbox as GatewaySandbox, MessageType, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type ProviderName, type ProviderSandboxInfo, type RunCommandOptions, type Runtime, Sandbox, type SandboxFileSystem, type SandboxInfo$1 as SandboxInfo, type Sandbox$1 as SandboxInterface, type SandboxStatus, SignalService, TerminalInstance, type WebSocketConstructor, autoConfigureCompute, buildProviderHeaders, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
4168
+ export { type CallableCompute, type CodeResult$1 as CodeResult, CommandExitError, type CommandResult$1 as CommandResult, type CreateSandboxOptions$1 as CreateSandboxOptions, type ExplicitComputeConfig, type FileEntry, FileWatcher, GATEWAY_URL, Sandbox as GatewaySandbox, MessageType, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type ProviderName, type ProviderSandboxInfo, type RunCommandOptions, type Runtime, Sandbox, type SandboxFileSystem, type SandboxInfo$1 as SandboxInfo, type Sandbox$1 as SandboxInterface, type SandboxStatus, type SetupOverlayConfig, type SetupPayload, SignalService, TerminalInstance, type WebSocketConstructor, autoConfigureCompute, buildProviderHeaders, buildSetupPayload, compute, decodeBinaryMessage, detectProvider, encodeBinaryMessage, encodeSetupPayload, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, isCommandExitError, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };