Skip to content

Commit f15223a

Browse files
keeping the autoresume config as a boolean on the API now isntead of converting to enum
1 parent 616ffb9 commit f15223a

11 files changed

Lines changed: 58 additions & 80 deletions

File tree

packages/js-sdk/src/api/schema.gen.ts

Lines changed: 5 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export type SandboxLifecycle = {
7272
onTimeout: 'pause' | 'kill'
7373

7474
/**
75-
* Auto-resume policy.
75+
* Auto-resume enabled flag.
7676
* @default false
7777
* Can be `true` only when `onTimeout` is `pause`.
7878
*/
@@ -150,7 +150,7 @@ export interface SandboxOpts extends ConnectionOpts {
150150
sandboxUrl?: string
151151

152152
/**
153-
* Sandbox lifecycle policy.
153+
* Sandbox lifecycle configuration.
154154
*/
155155
lifecycle?: SandboxLifecycle
156156
}
@@ -713,11 +713,9 @@ export class SandboxApi {
713713
const client = new ApiClient(config)
714714
const lifecycle = getLifecycle(opts)
715715
const autoPause = lifecycle.onTimeout === 'pause'
716-
const autoResumePolicy =
716+
const autoResumeEnabled =
717717
lifecycle.onTimeout === 'pause'
718-
? lifecycle.autoResume
719-
? 'any'
720-
: 'off'
718+
? (lifecycle.autoResume ?? false)
721719
: undefined
722720

723721
const body: components['schemas']['NewSandbox'] = {
@@ -730,8 +728,8 @@ export class SandboxApi {
730728
allow_internet_access: opts?.allowInternetAccess ?? true,
731729
network: opts?.network,
732730
...(autoPause !== undefined ? { autoPause } : {}),
733-
...(autoResumePolicy !== undefined
734-
? { autoResume: { policy: autoResumePolicy } }
731+
...(autoResumeEnabled !== undefined
732+
? { autoResume: { enabled: autoResumeEnabled } }
735733
: {}),
736734
}
737735

packages/python-sdk/e2b/api/client/models/__init__.py

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/python-sdk/e2b/api/client/models/new_sandbox.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/python-sdk/e2b/api/client/models/sandbox_auto_resume_config.py

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/python-sdk/e2b/api/client/models/sandbox_auto_resume_policy.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/python-sdk/e2b/sandbox/sandbox_api.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class SandboxNetworkOpts(TypedDict):
7878

7979
class SandboxLifecycle(TypedDict):
8080
"""
81-
Sandbox lifecycle configuration; defines post-timeout behavior and auto-resume policies.
81+
Sandbox lifecycle configuration; defines post-timeout behavior and auto-resume settings.
8282
Defaults to `on_timeout="kill"` and `auto_resume=False`.
8383
"""
8484

@@ -90,17 +90,15 @@ class SandboxLifecycle(TypedDict):
9090
auto_resume: NotRequired[bool]
9191
"""
9292
Whether activity should cause the sandbox to resume when paused. Defaults to `False`.
93-
Maps to API policy: `True -> "any"`, `False -> "off"`.
9493
Can be `True` only when `on_timeout` is `pause`.
9594
"""
9695

9796

98-
def get_auto_resume_policy(lifecycle: Optional[SandboxLifecycle]) -> Optional[str]:
97+
def get_auto_resume_enabled(lifecycle: Optional[SandboxLifecycle]) -> Optional[bool]:
9998
if lifecycle is None or lifecycle.get("on_timeout") != "pause":
10099
return None
101100

102-
auto_resume = lifecycle.get("auto_resume")
103-
return "any" if auto_resume else "off"
101+
return lifecycle.get("auto_resume", False)
104102

105103

106104
@dataclass

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
PostSandboxesSandboxIDTimeoutBody,
2525
Sandbox,
2626
SandboxAutoResumeConfig,
27-
SandboxAutoResumePolicy,
2827
SandboxNetworkConfig,
2928
)
3029
from e2b.api.client.types import UNSET
@@ -38,7 +37,7 @@
3837
from e2b.sandbox.main import SandboxBase
3938
from e2b.sandbox.sandbox_api import (
4039
SandboxLifecycle,
41-
get_auto_resume_policy,
40+
get_auto_resume_enabled,
4241
McpServer,
4342
SandboxInfo,
4443
SandboxMetrics,
@@ -179,7 +178,7 @@ async def _create_sandbox(
179178
should_auto_pause = (
180179
lifecycle["on_timeout"] == "pause" if lifecycle is not None else auto_pause
181180
)
182-
auto_resume_policy = get_auto_resume_policy(lifecycle)
181+
auto_resume_enabled = get_auto_resume_enabled(lifecycle)
183182
body = NewSandbox(
184183
template_id=template,
185184
auto_pause=(should_auto_pause if should_auto_pause is not None else UNSET),
@@ -191,9 +190,9 @@ async def _create_sandbox(
191190
allow_internet_access=allow_internet_access,
192191
network=SandboxNetworkConfig(**network) if network else UNSET,
193192
)
194-
if auto_resume_policy is not None:
193+
if auto_resume_enabled is not None:
195194
body.auto_resume = SandboxAutoResumeConfig(
196-
policy=SandboxAutoResumePolicy(auto_resume_policy)
195+
enabled=auto_resume_enabled
197196
)
198197

199198
api_client = get_api_client(config)

packages/python-sdk/e2b/sandbox_sync/sandbox_api.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
PostSandboxesSandboxIDTimeoutBody,
2525
Sandbox,
2626
SandboxAutoResumeConfig,
27-
SandboxAutoResumePolicy,
2827
SandboxNetworkConfig,
2928
)
3029
from e2b.api.client.types import UNSET
@@ -37,7 +36,7 @@
3736
from e2b.sandbox.main import SandboxBase
3837
from e2b.sandbox.sandbox_api import (
3938
SandboxLifecycle,
40-
get_auto_resume_policy,
39+
get_auto_resume_enabled,
4140
McpServer,
4241
SandboxInfo,
4342
SandboxMetrics,
@@ -178,7 +177,7 @@ def _create_sandbox(
178177
should_auto_pause = (
179178
lifecycle["on_timeout"] == "pause" if lifecycle is not None else auto_pause
180179
)
181-
auto_resume_policy = get_auto_resume_policy(lifecycle)
180+
auto_resume_enabled = get_auto_resume_enabled(lifecycle)
182181
body = NewSandbox(
183182
template_id=template,
184183
auto_pause=(should_auto_pause if should_auto_pause is not None else UNSET),
@@ -190,9 +189,9 @@ def _create_sandbox(
190189
allow_internet_access=allow_internet_access,
191190
network=SandboxNetworkConfig(**network) if network else UNSET,
192191
)
193-
if auto_resume_policy is not None:
192+
if auto_resume_enabled is not None:
194193
body.auto_resume = SandboxAutoResumeConfig(
195-
policy=SandboxAutoResumePolicy(auto_resume_policy)
194+
enabled=auto_resume_enabled
196195
)
197196

198197
api_client = get_api_client(config)

packages/python-sdk/tests/async/sandbox_async/test_create.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77
from e2b.api.client.models import (
88
NewSandbox,
99
SandboxAutoResumeConfig,
10-
SandboxAutoResumePolicy,
1110
)
12-
from e2b.sandbox.sandbox_api import get_auto_resume_policy
11+
from e2b.sandbox.sandbox_api import get_auto_resume_enabled
1312

1413

1514
@pytest.mark.skip_debug()
@@ -36,39 +35,39 @@ async def test_metadata(async_sandbox_factory):
3635
assert False, "Sandbox not found"
3736

3837

39-
def test_lifecycle_auto_resume_policy_mapping():
40-
assert get_auto_resume_policy({"on_timeout": "pause", "auto_resume": True}) == "any"
38+
def test_lifecycle_auto_resume_enabled_mapping():
39+
assert get_auto_resume_enabled({"on_timeout": "pause", "auto_resume": True}) is True
4140
assert (
42-
get_auto_resume_policy({"on_timeout": "pause", "auto_resume": False}) == "off"
41+
get_auto_resume_enabled({"on_timeout": "pause", "auto_resume": False}) is False
4342
)
44-
assert get_auto_resume_policy({"on_timeout": "pause"}) == "off"
45-
assert get_auto_resume_policy({"on_timeout": "kill", "auto_resume": False}) is None
46-
assert get_auto_resume_policy({"on_timeout": "kill"}) is None
47-
assert get_auto_resume_policy(None) is None
43+
assert get_auto_resume_enabled({"on_timeout": "pause"}) is False
44+
assert get_auto_resume_enabled({"on_timeout": "kill", "auto_resume": False}) is None
45+
assert get_auto_resume_enabled({"on_timeout": "kill"}) is None
46+
assert get_auto_resume_enabled(None) is None
4847

4948

50-
def test_create_payload_serializes_auto_resume_policy():
49+
def test_create_payload_serializes_auto_resume_enabled():
5150
body = NewSandbox(
5251
template_id="template-id",
5352
auto_pause=True,
54-
auto_resume=SandboxAutoResumeConfig(policy=SandboxAutoResumePolicy.ANY),
53+
auto_resume=SandboxAutoResumeConfig(enabled=True),
5554
)
5655

5756
assert body.to_dict()["autoPause"] is True
58-
assert body.to_dict()["autoResume"] == {"policy": "any"}
57+
assert body.to_dict()["autoResume"] == {"enabled": True}
5958

6059

61-
def test_create_payload_deserializes_auto_resume_policy():
60+
def test_create_payload_deserializes_auto_resume_enabled():
6261
body = NewSandbox.from_dict(
6362
{
6463
"templateID": "template-id",
6564
"autoPause": False,
66-
"autoResume": {"policy": "off"},
65+
"autoResume": {"enabled": False},
6766
}
6867
)
6968

7069
assert isinstance(body.auto_resume, SandboxAutoResumeConfig)
71-
assert body.auto_resume.to_dict() == {"policy": "off"}
70+
assert body.auto_resume.to_dict() == {"enabled": False}
7271

7372

7473
@pytest.mark.skip_debug()

0 commit comments

Comments
 (0)