Skip to content

Commit d940f89

Browse files
committed
Add docstrings
1 parent 7498b28 commit d940f89

6 files changed

Lines changed: 131 additions & 66 deletions

File tree

packages/js-sdk/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type {
4040
SandboxApiOpts,
4141
SandboxConnectOpts,
4242
SandboxBetaCreateOpts,
43-
SandboxResumeOpts,
43+
SandboxBetaConnectOpts,
4444
SandboxMetricsOpts,
4545
SandboxState,
4646
SandboxListOpts,

packages/js-sdk/src/sandbox/index.ts

Lines changed: 65 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
SandboxListOpts,
2020
SandboxPaginator,
2121
SandboxBetaCreateOpts,
22+
SandboxBetaConnectOpts,
2223
} from './sandboxApi'
2324
import { getSignature } from './signature'
2425
import { 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)

packages/js-sdk/src/sandbox/sandboxApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ export type SandboxBetaCreateOpts = SandboxOpts & { autoPause?: boolean }
6868
/**
6969
* Options for resuming a paused Sandbox.
7070
*/
71-
export type SandboxResumeOpts = Omit<SandboxOpts, 'metadata' | 'envs'>
71+
export type SandboxBetaConnectOpts = Omit<SandboxOpts, 'metadata' | 'envs'>
7272

7373
/**
7474
* Options for connecting to a Sandbox.
7575
*/
76-
export type SandboxConnectOpts = Omit<SandboxResumeOpts, 'timeoutMs'>
76+
export type SandboxConnectOpts = Omit<SandboxBetaConnectOpts, 'timeoutMs'>
7777

7878
/**
7979
* State of the sandbox.
@@ -483,7 +483,7 @@ export class SandboxApi {
483483

484484
protected static async resumeSandbox(
485485
sandboxId: string,
486-
opts?: SandboxResumeOpts
486+
opts?: SandboxBetaConnectOpts
487487
): Promise<boolean> {
488488
const timeoutMs = opts?.timeoutMs ?? DEFAULT_SANDBOX_TIMEOUT_MS
489489

packages/python-sdk/e2b/sandbox_async/main.py

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ async def beta_create(
528528
**opts: Unpack[ApiParams],
529529
) -> Self:
530530
"""
531+
[BETA] This feature is in beta and may change in the future.
532+
531533
Create a new sandbox.
532534
533535
By default, the sandbox is created from the default `base` sandbox template.
@@ -554,6 +556,8 @@ async def beta_pause(
554556
**opts: Unpack[ApiParams],
555557
) -> None:
556558
"""
559+
[BETA] This feature is in beta and may change in the future.
560+
557561
Pause the sandbox.
558562
559563
:return: Sandbox ID that can be used to resume the sandbox
@@ -567,6 +571,8 @@ async def beta_pause(
567571
**opts: Unpack[ApiParams],
568572
) -> None:
569573
"""
574+
[BETA] This feature is in beta and may change in the future.
575+
570576
Pause the sandbox specified by sandbox ID.
571577
572578
:param sandbox_id: Sandbox ID
@@ -581,9 +587,9 @@ async def beta_pause(
581587
**opts: Unpack[ApiParams],
582588
) -> None:
583589
"""
584-
Pause the sandbox.
590+
[BETA] This feature is in beta and may change in the future.
585591
586-
:param request_timeout: Timeout for the request in **seconds**
592+
Pause the sandbox.
587593
588594
:return: Sandbox ID that can be used to resume the sandbox
589595
"""
@@ -600,46 +606,49 @@ async def beta_connect(
600606
**opts: Unpack[ApiParams],
601607
) -> Self:
602608
"""
609+
[BETA] This feature is in beta and may change in the future.
610+
603611
Connect to a sandbox. Sandbox must be either running or be paused
604612
605613
:param timeout: Timeout for the sandbox in **seconds**
606-
:return: A Sandbox instance
614+
:return: A running sandbox instance
607615
608616
@example
609617
```python
610618
sandbox = await AsyncSandbox.create()
611-
await sandbox.beta.pause()
619+
await sandbox.beta_pause()
612620
613621
# Another code block
614-
same_sandbox = await AsyncSandbox.beta.connect()
615-
616-
:return: A running sandbox instance
622+
same_sandbox = await sandbox.beta_connect()
623+
```
617624
"""
618625
...
619626

620627
@overload
621-
@staticmethod
628+
@classmethod
622629
async def beta_connect(
630+
cls,
623631
sandbox_id: str,
624632
timeout: Optional[int] = None,
625633
**opts: Unpack[ApiParams],
626634
) -> Self:
627635
"""
636+
[BETA] This feature is in beta and may change in the future.
637+
628638
Connect to a sandbox. Sandbox must be either running or be paused
629639
630640
:param sandbox_id: Sandbox ID
631641
:param timeout: Timeout for the sandbox in **seconds**
632-
:return: A Sandbox instance
642+
:return: A running sandbox instance
633643
634644
@example
635645
```python
636646
sandbox = await AsyncSandbox.create()
637-
await sandbox.beta.pause()
647+
await AsyncSandbox.beta_pause(sandbox.sandbox_id)
638648
639649
# Another code block
640-
same_sandbox = await AsyncSandbox.beta.connect()
641-
642-
:return: A running sandbox instance
650+
same_sandbox = await AsyncSandbox.beta_connect(sandbox.sandbox_id))
651+
```
643652
"""
644653
...
645654

@@ -650,20 +659,21 @@ async def beta_connect(
650659
**opts: Unpack[ApiParams],
651660
) -> Self:
652661
"""
662+
[BETA] This feature is in beta and may change in the future.
663+
653664
Connect to a sandbox. Sandbox must be either running or be paused
654665
655666
:param timeout: Timeout for the sandbox in **seconds**
656-
:return: A Sandbox instance
667+
:return: A running sandbox instance
657668
658669
@example
659670
```python
660671
sandbox = await AsyncSandbox.create()
661-
await sandbox.beta.pause()
672+
await sandbox.beta_pause()
662673
663674
# Another code block
664-
same_sandbox = await AsyncSandbox.beta.connect()
665-
666-
:return: A running sandbox instance
675+
same_sandbox = await sandbox.beta_connect()
676+
```
667677
"""
668678
return await self._cls_beta_connect(
669679
sandbox_id=self.sandbox_id, timeout=timeout, **opts

0 commit comments

Comments
 (0)