computesdk 1.9.6 → 1.10.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
@@ -199,6 +199,31 @@ interface ListTemplatesOptions {
199
199
  /** Limit the number of results */
200
200
  limit?: number;
201
201
  }
202
+ /**
203
+ * Options for finding or creating a named sandbox
204
+ */
205
+ interface FindOrCreateSandboxOptions extends CreateSandboxOptions {
206
+ /** User-provided stable identifier (e.g., "my-app", "frontend") */
207
+ name: string;
208
+ /** Isolation scope (e.g., "user-123", "org-456"). Defaults to "default" */
209
+ namespace?: string;
210
+ }
211
+ /**
212
+ * Options for finding a named sandbox (without creating)
213
+ */
214
+ interface FindSandboxOptions {
215
+ /** User-provided stable identifier */
216
+ name: string;
217
+ /** Isolation scope. Defaults to "default" */
218
+ namespace?: string;
219
+ }
220
+ /**
221
+ * Options for extending sandbox timeout
222
+ */
223
+ interface ExtendTimeoutOptions {
224
+ /** Additional time to extend in milliseconds. Defaults to 900000 (15 minutes) */
225
+ duration?: number;
226
+ }
202
227
  /**
203
228
  * Provider sandbox manager interface - handles sandbox lifecycle
204
229
  *
@@ -214,6 +239,12 @@ interface ProviderSandboxManager<TSandbox = any> {
214
239
  list(): Promise<ProviderSandbox<TSandbox>[]>;
215
240
  /** Destroy a sandbox */
216
241
  destroy(sandboxId: string): Promise<void>;
242
+ /** Find existing or create new sandbox by (namespace, name) */
243
+ findOrCreate?(options: FindOrCreateSandboxOptions): Promise<ProviderSandbox<TSandbox>>;
244
+ /** Find existing sandbox by (namespace, name) without creating */
245
+ find?(options: FindSandboxOptions): Promise<ProviderSandbox<TSandbox> | null>;
246
+ /** Extend sandbox timeout/expiration */
247
+ extendTimeout?(sandboxId: string, options?: ExtendTimeoutOptions): Promise<void>;
217
248
  }
218
249
  /**
219
250
  * Provider template manager interface - handles template/blueprint lifecycle
@@ -306,6 +337,12 @@ interface ComputeAPI {
306
337
  list(provider?: Provider): Promise<ProviderSandbox[]>;
307
338
  /** Destroy a sandbox via a provider (or default provider if configured) */
308
339
  destroy(providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void>;
340
+ /** Find existing or create new sandbox by (namespace, name) */
341
+ findOrCreate(options: FindOrCreateSandboxOptions): Promise<ProviderSandbox>;
342
+ /** Find existing sandbox by (namespace, name) without creating */
343
+ find(options: FindSandboxOptions): Promise<ProviderSandbox | null>;
344
+ /** Extend sandbox timeout/expiration */
345
+ extendTimeout(sandboxId: string, options?: ExtendTimeoutOptions): Promise<void>;
309
346
  };
310
347
  }
311
348
  /**
@@ -326,6 +363,12 @@ interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, '
326
363
  list(): Promise<TypedProviderSandbox<TProvider>[]>;
327
364
  /** Destroy a sandbox via the configured provider */
328
365
  destroy(sandboxId: string): Promise<void>;
366
+ /** Find existing or create new sandbox by (namespace, name) */
367
+ findOrCreate(options: FindOrCreateSandboxOptions): Promise<TypedProviderSandbox<TProvider>>;
368
+ /** Find existing sandbox by (namespace, name) without creating */
369
+ find(options: FindSandboxOptions): Promise<TypedProviderSandbox<TProvider> | null>;
370
+ /** Extend sandbox timeout/expiration */
371
+ extendTimeout(sandboxId: string, options?: ExtendTimeoutOptions): Promise<void>;
329
372
  };
330
373
  }
331
374
  /**
@@ -539,6 +582,15 @@ interface SandboxMethods<TSandbox = any, TConfig = any> {
539
582
  sandboxId: string;
540
583
  }>>;
541
584
  destroy: (config: TConfig, sandboxId: string) => Promise<void>;
585
+ findOrCreate?: (config: TConfig, options: FindOrCreateSandboxOptions) => Promise<{
586
+ sandbox: TSandbox;
587
+ sandboxId: string;
588
+ }>;
589
+ find?: (config: TConfig, options: FindSandboxOptions) => Promise<{
590
+ sandbox: TSandbox;
591
+ sandboxId: string;
592
+ } | null>;
593
+ extendTimeout?: (config: TConfig, sandboxId: string, options?: ExtendTimeoutOptions) => Promise<void>;
542
594
  runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<CodeResult>;
543
595
  runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<CommandResult>;
544
596
  getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;
@@ -801,4 +853,4 @@ interface HandleComputeRequestParams {
801
853
  provider: Provider;
802
854
  }
803
855
 
804
- export { type BaseProviderConfig, type BlaxelProviderConfig, type CallableCompute, type CloudflareProviderConfig, type CodesandboxProviderConfig, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type DaytonaProviderConfig, type E2BProviderConfig, type ExplicitComputeConfig, type ProviderName as ExplicitProviderName, type ExtractProviderSandboxType, GATEWAY_URL, type GatewayConfig, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type ModalProviderConfig, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type Provider, type ProviderConfig, type ProviderMode, type ProviderName, type ProviderSandbox, type ProviderSandboxManager, type ProviderSnapshotManager, type ProviderTemplateManager, type RailwayProviderConfig, type RunloopProviderConfig, type SandboxInfo, type SandboxMethods, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedProviderSandbox, type VercelProviderConfig, autoConfigureCompute, buildProviderHeaders, calculateBackoff, compute, createCompute, createProvider, createProviderFromConfig, detectProvider, gateway, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, handleComputeRequest, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
856
+ export { type BaseProviderConfig, type BlaxelProviderConfig, type CallableCompute, type CloudflareProviderConfig, type CodesandboxProviderConfig, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type DaytonaProviderConfig, type E2BProviderConfig, type ExplicitComputeConfig, type ProviderName as ExplicitProviderName, type ExtendTimeoutOptions, type ExtractProviderSandboxType, type FindOrCreateSandboxOptions, type FindSandboxOptions, GATEWAY_URL, type GatewayConfig, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type ModalProviderConfig, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type Provider, type ProviderConfig, type ProviderMode, type ProviderName, type ProviderSandbox, type ProviderSandboxManager, type ProviderSnapshotManager, type ProviderTemplateManager, type RailwayProviderConfig, type RunloopProviderConfig, type SandboxInfo, type SandboxMethods, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedProviderSandbox, type VercelProviderConfig, autoConfigureCompute, buildProviderHeaders, calculateBackoff, compute, createCompute, createProvider, createProviderFromConfig, detectProvider, gateway, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, handleComputeRequest, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
package/dist/index.d.ts CHANGED
@@ -199,6 +199,31 @@ interface ListTemplatesOptions {
199
199
  /** Limit the number of results */
200
200
  limit?: number;
201
201
  }
202
+ /**
203
+ * Options for finding or creating a named sandbox
204
+ */
205
+ interface FindOrCreateSandboxOptions extends CreateSandboxOptions {
206
+ /** User-provided stable identifier (e.g., "my-app", "frontend") */
207
+ name: string;
208
+ /** Isolation scope (e.g., "user-123", "org-456"). Defaults to "default" */
209
+ namespace?: string;
210
+ }
211
+ /**
212
+ * Options for finding a named sandbox (without creating)
213
+ */
214
+ interface FindSandboxOptions {
215
+ /** User-provided stable identifier */
216
+ name: string;
217
+ /** Isolation scope. Defaults to "default" */
218
+ namespace?: string;
219
+ }
220
+ /**
221
+ * Options for extending sandbox timeout
222
+ */
223
+ interface ExtendTimeoutOptions {
224
+ /** Additional time to extend in milliseconds. Defaults to 900000 (15 minutes) */
225
+ duration?: number;
226
+ }
202
227
  /**
203
228
  * Provider sandbox manager interface - handles sandbox lifecycle
204
229
  *
@@ -214,6 +239,12 @@ interface ProviderSandboxManager<TSandbox = any> {
214
239
  list(): Promise<ProviderSandbox<TSandbox>[]>;
215
240
  /** Destroy a sandbox */
216
241
  destroy(sandboxId: string): Promise<void>;
242
+ /** Find existing or create new sandbox by (namespace, name) */
243
+ findOrCreate?(options: FindOrCreateSandboxOptions): Promise<ProviderSandbox<TSandbox>>;
244
+ /** Find existing sandbox by (namespace, name) without creating */
245
+ find?(options: FindSandboxOptions): Promise<ProviderSandbox<TSandbox> | null>;
246
+ /** Extend sandbox timeout/expiration */
247
+ extendTimeout?(sandboxId: string, options?: ExtendTimeoutOptions): Promise<void>;
217
248
  }
218
249
  /**
219
250
  * Provider template manager interface - handles template/blueprint lifecycle
@@ -306,6 +337,12 @@ interface ComputeAPI {
306
337
  list(provider?: Provider): Promise<ProviderSandbox[]>;
307
338
  /** Destroy a sandbox via a provider (or default provider if configured) */
308
339
  destroy(providerOrSandboxId: Provider | string, sandboxId?: string): Promise<void>;
340
+ /** Find existing or create new sandbox by (namespace, name) */
341
+ findOrCreate(options: FindOrCreateSandboxOptions): Promise<ProviderSandbox>;
342
+ /** Find existing sandbox by (namespace, name) without creating */
343
+ find(options: FindSandboxOptions): Promise<ProviderSandbox | null>;
344
+ /** Extend sandbox timeout/expiration */
345
+ extendTimeout(sandboxId: string, options?: ExtendTimeoutOptions): Promise<void>;
309
346
  };
310
347
  }
311
348
  /**
@@ -326,6 +363,12 @@ interface TypedComputeAPI<TProvider extends Provider> extends Omit<ComputeAPI, '
326
363
  list(): Promise<TypedProviderSandbox<TProvider>[]>;
327
364
  /** Destroy a sandbox via the configured provider */
328
365
  destroy(sandboxId: string): Promise<void>;
366
+ /** Find existing or create new sandbox by (namespace, name) */
367
+ findOrCreate(options: FindOrCreateSandboxOptions): Promise<TypedProviderSandbox<TProvider>>;
368
+ /** Find existing sandbox by (namespace, name) without creating */
369
+ find(options: FindSandboxOptions): Promise<TypedProviderSandbox<TProvider> | null>;
370
+ /** Extend sandbox timeout/expiration */
371
+ extendTimeout(sandboxId: string, options?: ExtendTimeoutOptions): Promise<void>;
329
372
  };
330
373
  }
331
374
  /**
@@ -539,6 +582,15 @@ interface SandboxMethods<TSandbox = any, TConfig = any> {
539
582
  sandboxId: string;
540
583
  }>>;
541
584
  destroy: (config: TConfig, sandboxId: string) => Promise<void>;
585
+ findOrCreate?: (config: TConfig, options: FindOrCreateSandboxOptions) => Promise<{
586
+ sandbox: TSandbox;
587
+ sandboxId: string;
588
+ }>;
589
+ find?: (config: TConfig, options: FindSandboxOptions) => Promise<{
590
+ sandbox: TSandbox;
591
+ sandboxId: string;
592
+ } | null>;
593
+ extendTimeout?: (config: TConfig, sandboxId: string, options?: ExtendTimeoutOptions) => Promise<void>;
542
594
  runCode: (sandbox: TSandbox, code: string, runtime?: Runtime, config?: TConfig) => Promise<CodeResult>;
543
595
  runCommand: (sandbox: TSandbox, command: string, args?: string[], options?: RunCommandOptions) => Promise<CommandResult>;
544
596
  getInfo: (sandbox: TSandbox) => Promise<SandboxInfo>;
@@ -801,4 +853,4 @@ interface HandleComputeRequestParams {
801
853
  provider: Provider;
802
854
  }
803
855
 
804
- export { type BaseProviderConfig, type BlaxelProviderConfig, type CallableCompute, type CloudflareProviderConfig, type CodesandboxProviderConfig, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type DaytonaProviderConfig, type E2BProviderConfig, type ExplicitComputeConfig, type ProviderName as ExplicitProviderName, type ExtractProviderSandboxType, GATEWAY_URL, type GatewayConfig, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type ModalProviderConfig, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type Provider, type ProviderConfig, type ProviderMode, type ProviderName, type ProviderSandbox, type ProviderSandboxManager, type ProviderSnapshotManager, type ProviderTemplateManager, type RailwayProviderConfig, type RunloopProviderConfig, type SandboxInfo, type SandboxMethods, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedProviderSandbox, type VercelProviderConfig, autoConfigureCompute, buildProviderHeaders, calculateBackoff, compute, createCompute, createProvider, createProviderFromConfig, detectProvider, gateway, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, handleComputeRequest, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
856
+ export { type BaseProviderConfig, type BlaxelProviderConfig, type CallableCompute, type CloudflareProviderConfig, type CodesandboxProviderConfig, type ComputeAPI, type ComputeConfig, type ComputeRequest, type ComputeResponse, type CreateSandboxParams, type CreateSandboxParamsWithOptionalProvider, type CreateSnapshotOptions, type CreateTemplateOptions, type DaytonaProviderConfig, type E2BProviderConfig, type ExplicitComputeConfig, type ProviderName as ExplicitProviderName, type ExtendTimeoutOptions, type ExtractProviderSandboxType, type FindOrCreateSandboxOptions, type FindSandboxOptions, GATEWAY_URL, type GatewayConfig, type HandleComputeRequestParams, type ListSnapshotsOptions, type ListTemplatesOptions, type ModalProviderConfig, PROVIDER_AUTH, PROVIDER_DASHBOARD_URLS, PROVIDER_ENV_MAP, PROVIDER_ENV_VARS, PROVIDER_HEADERS, PROVIDER_NAMES, PROVIDER_PRIORITY, type Provider, type ProviderConfig, type ProviderMode, type ProviderName, type ProviderSandbox, type ProviderSandboxManager, type ProviderSnapshotManager, type ProviderTemplateManager, type RailwayProviderConfig, type RunloopProviderConfig, type SandboxInfo, type SandboxMethods, type SnapshotMethods, type TemplateMethods, type TypedComputeAPI, type TypedProviderSandbox, type VercelProviderConfig, autoConfigureCompute, buildProviderHeaders, calculateBackoff, compute, createCompute, createProvider, createProviderFromConfig, detectProvider, gateway, getMissingEnvVars, getProviderConfigFromEnv, getProviderHeaders, handleComputeRequest, isGatewayModeEnabled, isProviderAuthComplete, isValidProvider };
package/dist/index.js CHANGED
@@ -405,6 +405,54 @@ var GeneratedSandboxManager = class {
405
405
  async destroy(sandboxId) {
406
406
  await this.methods.destroy(this.config, sandboxId);
407
407
  }
408
+ async findOrCreate(options) {
409
+ if (!this.methods.findOrCreate) {
410
+ throw new Error(
411
+ `Provider '${this.providerName}' does not support findOrCreate.
412
+ This feature requires gateway provider with named sandbox support.`
413
+ );
414
+ }
415
+ const result = await this.methods.findOrCreate(this.config, options);
416
+ return new GeneratedSandbox(
417
+ result.sandbox,
418
+ result.sandboxId,
419
+ this.providerName,
420
+ this.methods,
421
+ this.config,
422
+ this.methods.destroy,
423
+ this.providerInstance
424
+ );
425
+ }
426
+ async find(options) {
427
+ if (!this.methods.find) {
428
+ throw new Error(
429
+ `Provider '${this.providerName}' does not support find.
430
+ This feature requires gateway provider with named sandbox support.`
431
+ );
432
+ }
433
+ const result = await this.methods.find(this.config, options);
434
+ if (!result) {
435
+ return null;
436
+ }
437
+ return new GeneratedSandbox(
438
+ result.sandbox,
439
+ result.sandboxId,
440
+ this.providerName,
441
+ this.methods,
442
+ this.config,
443
+ this.methods.destroy,
444
+ this.providerInstance
445
+ );
446
+ }
447
+ async extendTimeout(sandboxId, options) {
448
+ if (!this.methods.extendTimeout) {
449
+ throw new Error(
450
+ `Provider '${this.providerName}' does not support extendTimeout.
451
+ This feature requires gateway provider with timeout extension support.`
452
+ );
453
+ }
454
+ await this.methods.extendTimeout(this.config, sandboxId, options);
455
+ }
408
456
  };
409
457
  var GeneratedTemplateManager = class {
410
458
  constructor(config, methods) {
@@ -651,14 +699,14 @@ var gateway = createProvider({
651
699
  sandbox: {
652
700
  create: async (config, options) => {
653
701
  const gatewayUrl = config.gatewayUrl || DEFAULT_GATEWAY_URL;
654
- const result = await gatewayFetch(`${gatewayUrl}/v1/sandbox`, config, {
702
+ const result = await gatewayFetch(`${gatewayUrl}/v1/sandboxes`, config, {
655
703
  method: "POST",
656
704
  body: JSON.stringify(options || {})
657
705
  });
658
706
  if (!result.success || !result.data) {
659
707
  throw new Error(`Gateway returned invalid response: ${JSON.stringify(result)}`);
660
708
  }
661
- const { sandboxId, url, token, provider, metadata } = result.data;
709
+ const { sandboxId, url, token, provider, metadata, name, namespace } = result.data;
662
710
  if (process.env.COMPUTESDK_DEBUG) {
663
711
  console.log(`[Gateway] Sandbox created:`, {
664
712
  sandboxId,
@@ -680,7 +728,11 @@ var gateway = createProvider({
680
728
  provider,
681
729
  token: token || config.apiKey,
682
730
  // Use token from gateway, fallback to API key
683
- metadata,
731
+ metadata: {
732
+ ...metadata,
733
+ ...name && { name },
734
+ ...namespace && { namespace }
735
+ },
684
736
  WebSocket: globalThis.WebSocket
685
737
  });
686
738
  await waitForComputeReady(sandbox);
@@ -688,7 +740,7 @@ var gateway = createProvider({
688
740
  },
689
741
  getById: async (config, sandboxId) => {
690
742
  const gatewayUrl = config.gatewayUrl || DEFAULT_GATEWAY_URL;
691
- const result = await gatewayFetch(`${gatewayUrl}/v1/sandbox/${sandboxId}`, config);
743
+ const result = await gatewayFetch(`${gatewayUrl}/v1/sandboxes/${sandboxId}`, config);
692
744
  if (!result.success || !result.data) {
693
745
  return null;
694
746
  }
@@ -718,10 +770,97 @@ var gateway = createProvider({
718
770
  },
719
771
  destroy: async (config, sandboxId) => {
720
772
  const gatewayUrl = config.gatewayUrl || DEFAULT_GATEWAY_URL;
721
- await gatewayFetch(`${gatewayUrl}/v1/sandbox/${sandboxId}`, config, {
773
+ await gatewayFetch(`${gatewayUrl}/v1/sandboxes/${sandboxId}`, config, {
722
774
  method: "DELETE"
723
775
  });
724
776
  },
777
+ findOrCreate: async (config, options) => {
778
+ const gatewayUrl = config.gatewayUrl || DEFAULT_GATEWAY_URL;
779
+ const { name: requestedName, namespace: requestedNamespace, ...restOptions } = options;
780
+ const result = await gatewayFetch(`${gatewayUrl}/v1/sandboxes/find-or-create`, config, {
781
+ method: "POST",
782
+ body: JSON.stringify({
783
+ namespace: requestedNamespace || "default",
784
+ name: requestedName,
785
+ ...restOptions
786
+ })
787
+ });
788
+ if (!result.success || !result.data) {
789
+ throw new Error(`Gateway returned invalid response: ${JSON.stringify(result)}`);
790
+ }
791
+ const { sandboxId, url, token, provider, metadata, name, namespace } = result.data;
792
+ if (process.env.COMPUTESDK_DEBUG) {
793
+ console.log(`[Gateway] Named sandbox found/created:`, {
794
+ sandboxId,
795
+ name,
796
+ namespace,
797
+ url,
798
+ hasToken: !!token,
799
+ provider
800
+ });
801
+ }
802
+ const sandbox = new import_client3.Sandbox({
803
+ sandboxUrl: url,
804
+ sandboxId,
805
+ provider,
806
+ token: token || config.apiKey,
807
+ metadata: {
808
+ ...metadata,
809
+ name,
810
+ namespace
811
+ },
812
+ WebSocket: globalThis.WebSocket
813
+ });
814
+ await waitForComputeReady(sandbox);
815
+ return { sandbox, sandboxId };
816
+ },
817
+ find: async (config, options) => {
818
+ const gatewayUrl = config.gatewayUrl || DEFAULT_GATEWAY_URL;
819
+ const result = await gatewayFetch(`${gatewayUrl}/v1/sandboxes/find`, config, {
820
+ method: "POST",
821
+ body: JSON.stringify({
822
+ namespace: options.namespace || "default",
823
+ name: options.name
824
+ })
825
+ });
826
+ if (!result.success || !result.data) {
827
+ return null;
828
+ }
829
+ const { sandboxId, url, token, provider, metadata, name, namespace } = result.data;
830
+ if (process.env.COMPUTESDK_DEBUG) {
831
+ console.log(`[Gateway] Named sandbox found:`, {
832
+ sandboxId,
833
+ name,
834
+ namespace,
835
+ url
836
+ });
837
+ }
838
+ const sandbox = new import_client3.Sandbox({
839
+ sandboxUrl: url,
840
+ sandboxId,
841
+ provider,
842
+ token: token || config.apiKey,
843
+ metadata: {
844
+ ...metadata,
845
+ name,
846
+ namespace
847
+ },
848
+ WebSocket: globalThis.WebSocket
849
+ });
850
+ await waitForComputeReady(sandbox);
851
+ return { sandbox, sandboxId };
852
+ },
853
+ extendTimeout: async (config, sandboxId, options) => {
854
+ const gatewayUrl = config.gatewayUrl || DEFAULT_GATEWAY_URL;
855
+ const duration = options?.duration ?? 9e5;
856
+ if (process.env.COMPUTESDK_DEBUG) {
857
+ console.log(`[Gateway] Extending timeout for sandbox ${sandboxId} by ${duration}ms`);
858
+ }
859
+ await gatewayFetch(`${gatewayUrl}/v1/sandboxes/${sandboxId}/extend`, config, {
860
+ method: "POST",
861
+ body: JSON.stringify({ duration })
862
+ });
863
+ },
725
864
  // All operations delegate directly to ClientSandbox
726
865
  runCode: async (sandbox, code, runtime) => sandbox.runCode(code, runtime),
727
866
  runCommand: async (sandbox, command, args) => sandbox.runCommand(command, args),
@@ -1075,6 +1214,79 @@ var ComputeManager = class {
1075
1214
  }
1076
1215
  return await providerOrSandboxId.sandbox.destroy(sandboxId);
1077
1216
  }
1217
+ },
1218
+ /**
1219
+ * Find existing or create new sandbox by (namespace, name)
1220
+ *
1221
+ * @example
1222
+ * ```typescript
1223
+ * // Find or create sandbox for a user's project
1224
+ * const sandbox = await compute.sandbox.findOrCreate({
1225
+ * name: 'my-app',
1226
+ * namespace: 'user-123',
1227
+ * timeout: 1800000
1228
+ * });
1229
+ * ```
1230
+ */
1231
+ findOrCreate: async (options) => {
1232
+ const provider = this.getDefaultProvider();
1233
+ if (!provider.sandbox.findOrCreate) {
1234
+ throw new Error(
1235
+ `Provider '${provider.name}' does not support findOrCreate.
1236
+ This feature requires gateway provider with named sandbox support.`
1237
+ );
1238
+ }
1239
+ return await provider.sandbox.findOrCreate(options);
1240
+ },
1241
+ /**
1242
+ * Find existing sandbox by (namespace, name) without creating
1243
+ *
1244
+ * @example
1245
+ * ```typescript
1246
+ * // Find existing sandbox
1247
+ * const sandbox = await compute.sandbox.find({
1248
+ * name: 'my-app',
1249
+ * namespace: 'user-123'
1250
+ * });
1251
+ *
1252
+ * if (sandbox) {
1253
+ * console.log('Found sandbox:', sandbox.sandboxId);
1254
+ * }
1255
+ * ```
1256
+ */
1257
+ find: async (options) => {
1258
+ const provider = this.getDefaultProvider();
1259
+ if (!provider.sandbox.find) {
1260
+ throw new Error(
1261
+ `Provider '${provider.name}' does not support find.
1262
+ This feature requires gateway provider with named sandbox support.`
1263
+ );
1264
+ }
1265
+ return await provider.sandbox.find(options);
1266
+ },
1267
+ /**
1268
+ * Extend sandbox timeout/expiration
1269
+ *
1270
+ * @example
1271
+ * ```typescript
1272
+ * // Extend timeout by 15 minutes (default)
1273
+ * await compute.sandbox.extendTimeout('sandbox-123');
1274
+ *
1275
+ * // Extend timeout by custom duration
1276
+ * await compute.sandbox.extendTimeout('sandbox-123', {
1277
+ * duration: 1800000 // 30 minutes
1278
+ * });
1279
+ * ```
1280
+ */
1281
+ extendTimeout: async (sandboxId, options) => {
1282
+ const provider = this.getDefaultProvider();
1283
+ if (!provider.sandbox.extendTimeout) {
1284
+ throw new Error(
1285
+ `Provider '${provider.name}' does not support extendTimeout.
1286
+ This feature requires gateway provider with timeout extension support.`
1287
+ );
1288
+ }
1289
+ return await provider.sandbox.extendTimeout(sandboxId, options);
1078
1290
  }
1079
1291
  };
1080
1292
  }
@@ -1186,6 +1398,18 @@ function createCompute(config) {
1186
1398
  },
1187
1399
  destroy: async (sandboxId) => {
1188
1400
  return await manager.sandbox.destroy(sandboxId);
1401
+ },
1402
+ findOrCreate: async (options) => {
1403
+ const sandbox = await manager.sandbox.findOrCreate(options);
1404
+ return sandbox;
1405
+ },
1406
+ find: async (options) => {
1407
+ const sandbox = await manager.sandbox.find(options);
1408
+ if (!sandbox) return null;
1409
+ return sandbox;
1410
+ },
1411
+ extendTimeout: async (sandboxId, options) => {
1412
+ return await manager.sandbox.extendTimeout(sandboxId, options);
1189
1413
  }
1190
1414
  }
1191
1415
  };