@@ -19,6 +19,7 @@ import {
1919 SandboxListOpts ,
2020 SandboxPaginator ,
2121 SandboxBetaCreateOpts ,
22+ SandboxBetaConnectOpts ,
2223} from './sandboxApi'
2324import { getSignature } from './signature'
2425import { compareVersions } from 'compare-versions'
@@ -250,6 +251,8 @@ export class Sandbox extends SandboxApi {
250251 }
251252
252253 /**
254+ * [BETA] This feature is in beta and may change in the future.
255+ *
253256 * Create a new sandbox from the default `base` sandbox template.
254257 *
255258 * @param opts connection options.
@@ -268,6 +271,8 @@ export class Sandbox extends SandboxApi {
268271 ) : Promise < InstanceType < S > >
269272
270273 /**
274+ * [BETA] This feature is in beta and may change in the future.
275+ *
271276 * Create a new sandbox from the specified sandbox template.
272277 *
273278 * @param template sandbox template name or ID.
@@ -349,27 +354,73 @@ export class Sandbox extends SandboxApi {
349354 } ) as InstanceType < S >
350355 }
351356
357+ /**
358+ * [BETA] This feature is in beta and may change in the future.
359+ *
360+ * Connect to a sandbox. If the sandbox is paused, it will be automatically resumed.
361+ * Sandbox must be either running or be paused.
362+ * With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
363+ *
364+ * @param sandboxId sandbox ID.
365+ * @param opts connection options.
366+ *
367+ * @returns sandbox instance for the existing sandbox.
368+ *
369+ * @example
370+ * ```ts
371+ * const sandbox = await Sandbox.create()
372+ * const sandboxId = sandbox.sandboxId
373+ * await Sandbox.betaPause()
374+ *
375+ * // Connect to the same sandbox.
376+ * const sameSandbox = await Sandbox.betaConnect(sandboxId)
377+ * ```
378+ */
352379 static async betaConnect < S extends typeof Sandbox > (
353380 this : S ,
354381 sandboxId : string ,
355- timeoutMs : number ,
356- opts ?: SandboxConnectOpts
382+ opts ?: SandboxBetaConnectOpts
357383 ) : Promise < InstanceType < S > > {
358384 try {
359- await SandboxApi . setTimeout ( sandboxId , timeoutMs , opts )
385+ await SandboxApi . setTimeout (
386+ sandboxId ,
387+ opts ?. timeoutMs || DEFAULT_SANDBOX_TIMEOUT_MS ,
388+ opts
389+ )
360390 } catch ( e ) {
361391 await SandboxApi . resumeSandbox ( sandboxId , opts )
362392 }
363393
364394 return await this . connect ( sandboxId , opts )
365395 }
366396
367- async betaConnect (
368- timeoutMs : number ,
369- opts ?: SandboxConnectOpts
370- ) : Promise < this> {
397+ /**
398+ * [BETA] This feature is in beta and may change in the future.
399+ *
400+ * Connect to a sandbox. If the sandbox is paused, it will be automatically resumed.
401+ * Sandbox must be either running or be paused.
402+ * With sandbox ID you can connect to the same sandbox from different places or environments (serverless functions, etc).
403+ *
404+ * @param opts connection options.
405+ *
406+ * @returns sandbox instance for the existing sandbox.
407+ *
408+ * @example
409+ * ```ts
410+ * const sandbox = await Sandbox.create()
411+ * await sandbox.betaPause()
412+ *
413+ * // Connect to the same sandbox.
414+ * const sameSandbox = await sandbox.betaConnect()
415+ * ```
416+ */
417+ async betaConnect ( opts ?: SandboxBetaCreateOpts ) : Promise < this> {
371418 try {
372- await SandboxApi . setTimeout ( this . sandboxId , timeoutMs , opts )
419+ await SandboxApi . setTimeout (
420+ this . sandboxId ,
421+ opts ?. timeoutMs || DEFAULT_SANDBOX_TIMEOUT_MS ,
422+ opts
423+ )
373424 } catch ( e ) {
374425 await SandboxApi . resumeSandbox ( this . sandboxId , opts )
375426 }
@@ -477,8 +528,13 @@ export class Sandbox extends SandboxApi {
477528 }
478529
479530 /**
480- * Pause the sandbox.
531+ * [BETA] This feature is in beta and may change in the future.
532+ *
533+ * Pause a sandbox by its ID.
534+ *
535+ * @param opts connection options.
481536 *
537+ * @returns sandbox ID that can be used to resume the sandbox.
482538 */
483539 async betaPause ( opts ?: ConnectionOpts ) : Promise < boolean > {
484540 return await SandboxApi . betaPause ( this . sandboxId , opts )
0 commit comments