Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
feat (api): Sandbox info lifecycle network (#1213)
Matt Brockman7c8d29839ace
diff --git a/.changeset/quiet-flowers-roll.md b/.changeset/quiet-flowers-roll.mdnew file mode 100644index 000000000..7a06ca8a3--- /dev/null+++ b/.changeset/quiet-flowers-roll.md@@ -0,0 +1,6 @@+---+'@e2b/python-sdk': minor+'e2b': minor+---++adds network configs and lifecycle handling to info responsesdiff --git a/packages/js-sdk/src/api/schema.gen.ts b/packages/js-sdk/src/api/schema.gen.tsindex df7730a49..53413b0f9 100644--- a/packages/js-sdk/src/api/schema.gen.ts+++ b/packages/js-sdk/src/api/schema.gen.ts@@ -2017,6 +2017,8 @@ export interface components {SandboxDetail: {/** @description Alias of the template */alias?: string;+ /** @description Whether internet access was explicitly enabled or disabled for the sandbox. Null means it was not explicitly set. */+ allowInternetAccess?: boolean | null;/*** @deprecated* @description Identifier of the client@@ -2034,8 +2036,10 @@ export interface components {/** @description Access token used for envd communication */envdAccessToken?: string;envdVersion: components["schemas"]["EnvdVersion"];+ lifecycle?: components["schemas"]["SandboxLifecycle"];memoryMB: components["schemas"]["MemoryMB"];metadata?: components["schemas"]["SandboxMetadata"];+ network?: components["schemas"]["SandboxNetworkConfig"];/** @description Identifier of the sandbox */sandboxID: string;/**@@ -2053,6 +2057,12 @@ export interface components {[key: string]: components["schemas"]["SandboxMetric"];};};+ /** @description Sandbox lifecycle policy returned by sandbox info. */+ SandboxLifecycle: {+ /** @description Whether the sandbox can auto-resume. */+ autoResume: boolean;+ onTimeout: components["schemas"]["SandboxOnTimeout"];+ };/** @description Log entry with timestamp and line */SandboxLog: {/** @description Log line content */@@ -2149,6 +2159,11 @@ export interface components {/** @description Specify host mask which will be used for all sandbox requests */maskRequestHost?: string;};+ /**+ * @description Action taken when the sandbox times out.+ * @enum {string}+ */+ SandboxOnTimeout: "kill" | "pause";/*** @description State of the sandbox* @enum {string}diff --git a/packages/js-sdk/src/index.ts b/packages/js-sdk/src/index.tsindex d3a93d68d..5d3bfa58a 100644--- a/packages/js-sdk/src/index.ts+++ b/packages/js-sdk/src/index.ts@@ -52,6 +52,7 @@ export type {SandboxPaginator,SandboxNetworkOpts,SandboxLifecycle,+ SandboxInfoLifecycle,SnapshotInfo,SnapshotListOpts,SnapshotPaginator,diff --git a/packages/js-sdk/src/sandbox/sandboxApi.ts b/packages/js-sdk/src/sandbox/sandboxApi.tsindex f608a9b5b..f65398de9 100644--- a/packages/js-sdk/src/sandbox/sandboxApi.ts+++ b/packages/js-sdk/src/sandbox/sandboxApi.ts@@ -79,6 +79,18 @@ export type SandboxLifecycle = {autoResume?: boolean}+export type SandboxInfoLifecycle = {+ /**+ * Action to take when sandbox timeout is reached.+ */+ onTimeout: 'pause' | 'kill'++ /**+ * Whether the sandbox can auto-resume.+ */+ autoResume: boolean+}+/*** Options for request to the Sandbox API.*/@@ -310,6 +322,21 @@ export interface SandboxInfo {* Envd version.*/envdVersion: string++ /**+ * Whether internet access was explicitly enabled or disabled for the sandbox.+ */+ allowInternetAccess?: boolean | undefined++ /**+ * Sandbox network configuration.+ */+ network?: SandboxNetworkOpts++ /**+ * Sandbox lifecycle configuration.+ */+ lifecycle?: SandboxInfoLifecycle}/**@@ -552,6 +579,7 @@ export class SandboxApi {templateId: res.data.templateID,...(res.data.alias && { name: res.data.alias }),metadata: res.data.metadata ?? {},+ allowInternetAccess: res.data.allowInternetAccess ?? undefined,envdVersion: res.data.envdVersion,envdAccessToken: res.data.envdAccessToken,startedAt: new Date(res.data.startedAt),@@ -559,6 +587,20 @@ export class SandboxApi {state: res.data.state,cpuCount: res.data.cpuCount,memoryMB: res.data.memoryMB,+ network: res.data.network+ ? {+ allowOut: res.data.network.allowOut,+ denyOut: res.data.network.denyOut,+ allowPublicTraffic: res.data.network.allowPublicTraffic,+ maskRequestHost: res.data.network.maskRequestHost,+ }+ : undefined,+ lifecycle: res.data.lifecycle+ ? {+ onTimeout: res.data.lifecycle.onTimeout,+ autoResume: res.data.lifecycle.autoResume,+ }+ : undefined,sandboxDomain: res.data.domain || undefined,}}diff --git a/packages/python-sdk/e2b/__init__.py b/packages/python-sdk/e2b/__init__.pyindex cb89f394a..b8711a5ca 100644--- a/packages/python-sdk/e2b/__init__.py+++ b/packages/python-sdk/e2b/__init__.py@@ -69,6 +69,7 @@ from .sandbox.sandbox_api import (GitHubMcpServerConfig,McpServer,SandboxInfo,+ SandboxInfoLifecycle,SandboxMetrics,SandboxLifecycle,SandboxNetworkOpts,@@ -136,6 +137,7 @@ __all__ = ["FileUploadException",# Sandbox API"SandboxInfo",+ "SandboxInfoLifecycle","SandboxMetrics","ProcessInfo","SandboxQuery",diff --git a/packages/python-sdk/e2b/api/client/models/__init__.py b/packages/python-sdk/e2b/api/client/models/__init__.pyindex ee88093d7..dc1cc3344 100644--- a/packages/python-sdk/e2b/api/client/models/__init__.py+++ b/packages/python-sdk/e2b/api/client/models/__init__.py@@ -45,6 +45,7 @@ from .resumed_sandbox import ResumedSandboxfrom .sandbox import Sandboxfrom .sandbox_auto_resume_config import SandboxAutoResumeConfigfrom .sandbox_detail import SandboxDetail+from .sandbox_lifecycle import SandboxLifecyclefrom .sandbox_log import SandboxLogfrom .sandbox_log_entry import SandboxLogEntryfrom .sandbox_log_entry_fields import SandboxLogEntryFields@@ -52,6 +53,7 @@ from .sandbox_logs import SandboxLogsfrom .sandbox_logs_v2_response import SandboxLogsV2Responsefrom .sandbox_metric import SandboxMetricfrom .sandbox_network_config import SandboxNetworkConfig+from .sandbox_on_timeout import SandboxOnTimeoutfrom .sandbox_state import SandboxStatefrom .sandbox_volume_mount import SandboxVolumeMountfrom .sandboxes_with_metrics import SandboxesWithMetrics@@ -124,6 +126,7 @@ __all__ = ("SandboxAutoResumeConfig","SandboxDetail","SandboxesWithMetrics",+ "SandboxLifecycle","SandboxLog","SandboxLogEntry","SandboxLogEntryFields",@@ -131,6 +134,7 @@ __all__ = ("SandboxLogsV2Response","SandboxMetric","SandboxNetworkConfig",+ "SandboxOnTimeout","SandboxState","SandboxVolumeMount","SnapshotInfo",diff --git a/packages/python-sdk/e2b/api/client/models/sandbox_detail.py b/packages/python-sdk/e2b/api/client/models/sandbox_detail.pyindex 46455fc88..1078d2b7a 100644--- a/packages/python-sdk/e2b/api/client/models/sandbox_detail.py+++ b/packages/python-sdk/e2b/api/client/models/sandbox_detail.py@@ -10,6 +10,8 @@ from ..models.sandbox_state import SandboxStatefrom ..types import UNSET, Unsetif TYPE_CHECKING:+ from ..models.sandbox_lifecycle import SandboxLifecycle+ from ..models.sandbox_network_config import SandboxNetworkConfigfrom ..models.sandbox_volume_mount import SandboxVolumeMount@@ -31,9 +33,13 @@ class SandboxDetail:state (SandboxState): State of the sandboxtemplate_id (str): Identifier of the template from which is the sandbox createdalias (Union[Unset, str]): Alias of the template+ allow_internet_access (Union[None, Unset, bool]): Whether internet access was explicitly enabled or disabled for+ the sandbox. Null means it was not explicitly set.domain (Union[None, Unset, str]): Base domain where the sandbox traffic is accessibleenvd_access_token (Union[Unset, str]): Access token used for envd communication+ lifecycle (Union[Unset, SandboxLifecycle]): Sandbox lifecycle policy returned by sandbox info.metadata (Union[Unset, Any]):+ network (Union[Unset, SandboxNetworkConfig]):volume_mounts (Union[Unset, list['SandboxVolumeMount']]):"""@@ -48,9 +54,12 @@ class SandboxDetail:state: SandboxStatetemplate_id: stralias: Union[Unset, str] = UNSET+ allow_internet_access: Union[None, Unset, bool] = UNSETdomain: Union[None, Unset, str] = UNSETenvd_access_token: Union[Unset, str] = UNSET+ lifecycle: Union[Unset, "SandboxLifecycle"] = UNSETmetadata: Union[Unset, Any] = UNSET+ network: Union[Unset, "SandboxNetworkConfig"] = UNSETvolume_mounts: Union[Unset, list["SandboxVolumeMount"]] = UNSETadditional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)@@ -77,6 +86,12 @@ class SandboxDetail:alias = self.alias+ allow_internet_access: Union[None, Unset, bool]+ if isinstance(self.allow_internet_access, Unset):+ allow_internet_access = UNSET+ else:+ allow_internet_access = self.allow_internet_access+domain: Union[None, Unset, str]if isinstance(self.domain, Unset):domain = UNSET@@ -85,8 +100,16 @@ class SandboxDetail:envd_access_token = self.envd_access_token+ lifecycle: Union[Unset, dict[str, Any]] = UNSET+ if not isinstance(self.lifecycle, Unset):+ lifecycle = self.lifecycle.to_dict()+metadata = self.metadata+ network: Union[Unset, dict[str, Any]] = UNSET+ if not isinstance(self.network, Unset):+ network = self.network.to_dict()+volume_mounts: Union[Unset, list[dict[str, Any]]] = UNSETif not isinstance(self.volume_mounts, Unset):volume_mounts = []@@ -112,12 +135,18 @@ class SandboxDetail:)if alias is not UNSET:field_dict["alias"] = alias+ if allow_internet_access is not UNSET:+ field_dict["allowInternetAccess"] = allow_internet_accessif domain is not UNSET:field_dict["domain"] = domainif envd_access_token is not UNSET:field_dict["envdAccessToken"] = envd_access_token+ if lifecycle is not UNSET:+ field_dict["lifecycle"] = lifecycleif metadata is not UNSET:field_dict["metadata"] = metadata+ if network is not UNSET:+ field_dict["network"] = networkif volume_mounts is not UNSET:field_dict["volumeMounts"] = volume_mounts@@ -125,6 +154,8 @@ class SandboxDetail:@classmethoddef from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:+ from ..models.sandbox_lifecycle import SandboxLifecycle+ from ..models.sandbox_network_config import SandboxNetworkConfigfrom ..models.sandbox_volume_mount import SandboxVolumeMountd = dict(src_dict)@@ -150,6 +181,17 @@ class SandboxDetail:alias = d.pop("alias", UNSET)+ def _parse_allow_internet_access(data: object) -> Union[None, Unset, bool]:+ if data is None:+ return data+ if isinstance(data, Unset):+ return data+ return cast(Union[None, Unset, bool], data)++ allow_internet_access = _parse_allow_internet_access(+ d.pop("allowInternetAccess", UNSET)+ )+def _parse_domain(data: object) -> Union[None, Unset, str]:if data is None:return data@@ -161,8 +203,22 @@ class SandboxDetail:envd_access_token = d.pop("envdAccessToken", UNSET)+ _lifecycle = d.pop("lifecycle", UNSET)+ lifecycle: Union[Unset, SandboxLifecycle]+ if isinstance(_lifecycle, Unset):+ lifecycle = UNSET+ else:+ lifecycle = SandboxLifecycle.from_dict(_lifecycle)+metadata = d.pop("metadata", UNSET)+ _network = d.pop("network", UNSET)+ network: Union[Unset, SandboxNetworkConfig]+ if isinstance(_network, Unset):+ network = UNSET+ else:+ network = SandboxNetworkConfig.from_dict(_network)+volume_mounts = []_volume_mounts = d.pop("volumeMounts", UNSET)for volume_mounts_item_data in _volume_mounts or []:@@ -182,9 +238,12 @@ class SandboxDetail:state=state,template_id=template_id,alias=alias,+ allow_internet_access=allow_internet_access,domain=domain,envd_access_token=envd_access_token,+ lifecycle=lifecycle,metadata=metadata,+ network=network,volume_mounts=volume_mounts,)diff --git a/packages/python-sdk/e2b/api/client/models/sandbox_lifecycle.py b/packages/python-sdk/e2b/api/client/models/sandbox_lifecycle.pynew file mode 100644index 000000000..2912b7326--- /dev/null+++ b/packages/python-sdk/e2b/api/client/models/sandbox_lifecycle.py@@ -0,0 +1,70 @@+from collections.abc import Mapping+from typing import Any, TypeVar++from attrs import define as _attrs_define+from attrs import field as _attrs_field++from ..models.sandbox_on_timeout import SandboxOnTimeout++T = TypeVar("T", bound="SandboxLifecycle")+++@_attrs_define+class SandboxLifecycle:+ """Sandbox lifecycle policy returned by sandbox info.++ Attributes:+ auto_resume (bool): Whether the sandbox can auto-resume.+ on_timeout (SandboxOnTimeout): Action taken when the sandbox times out.+ """++ auto_resume: bool+ on_timeout: SandboxOnTimeout+ additional_properties: dict[str, Any] = _attrs_field(init=False, factory=dict)++ def to_dict(self) -> dict[str, Any]:+ auto_resume = self.auto_resume++ on_timeout = self.on_timeout.value++ field_dict: dict[str, Any] = {}+ field_dict.update(self.additional_properties)+ field_dict.update(+ {+ "autoResume": auto_resume,+ "onTimeout": on_timeout,+ }+ )++ return field_dict++ @classmethod+ def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T:+ d = dict(src_dict)+ auto_resume = d.pop("autoResume")++ on_timeout = SandboxOnTimeout(d.pop("onTimeout"))++ sandbox_lifecycle = cls(+ auto_resume=auto_resume,+ on_timeout=on_timeout,+ )++ sandbox_lifecycle.additional_properties = d+ return sandbox_lifecycle++ @property+ def additional_keys(self) -> list[str]:+ return list(self.additional_properties.keys())++ def __getitem__(self, key: str) -> Any:+ return self.additional_properties[key]++ def __setitem__(self, key: str, value: Any) -> None:+ self.additional_properties[key] = value++ def __delitem__(self, key: str) -> None:+ del self.additional_properties[key]++ def __contains__(self, key: str) -> bool:+ return key in self.additional_propertiesdiff --git a/packages/python-sdk/e2b/api/client/models/sandbox_on_timeout.py b/packages/python-sdk/e2b/api/client/models/sandbox_on_timeout.pynew file mode 100644index 000000000..8cd4cbafa--- /dev/null+++ b/packages/python-sdk/e2b/api/client/models/sandbox_on_timeout.py@@ -0,0 +1,9 @@+from enum import Enum+++class SandboxOnTimeout(str, Enum):+ KILL = "kill"+ PAUSE = "pause"++ def __str__(self) -> str:+ return str(self.value)diff --git a/packages/python-sdk/e2b/sandbox/sandbox_api.py b/packages/python-sdk/e2b/sandbox/sandbox_api.pyindex 7339db3b9..3ff92ce94 100644--- a/packages/python-sdk/e2b/sandbox/sandbox_api.py+++ b/packages/python-sdk/e2b/sandbox/sandbox_api.py@@ -5,7 +5,14 @@ from typing import Any, Dict, List, Literal, Optional, TypedDict, Union, castfrom typing_extensions import NotRequired, Unpackfrom e2b import ConnectionConfig-from e2b.api.client.models import ListedSandbox, SandboxDetail, SandboxState+from e2b.api.client.models import (+ ListedSandbox,+ SandboxDetail,+ SandboxLifecycle as ClientSandboxLifecycle,+ SandboxNetworkConfig as ClientSandboxNetworkConfig,+ SandboxState,+)+from e2b.api.client.types import Unsetfrom e2b.connection_config import ApiParamsfrom e2b.sandbox.mcp import McpServer as BaseMcpServer@@ -94,6 +101,22 @@ class SandboxLifecycle(TypedDict):"""+class SandboxInfoLifecycle(TypedDict):+ """+ Sandbox lifecycle configuration returned by sandbox info.+ """++ on_timeout: Literal["pause", "kill"]+ """+ What should happen to the sandbox when timeout is reached.+ """++ auto_resume: bool+ """+ Whether activity should cause the sandbox to resume when paused.+ """++def get_auto_resume_enabled(lifecycle: Optional[SandboxLifecycle]) -> Optional[bool]:if lifecycle is None or lifecycle.get("on_timeout") != "pause":return None@@ -101,6 +124,40 @@ def get_auto_resume_enabled(lifecycle: Optional[SandboxLifecycle]) -> Optional[breturn lifecycle.get("auto_resume", False)+def from_client_network_config(+ network: Union[Unset, ClientSandboxNetworkConfig],+) -> Optional[SandboxNetworkOpts]:+ if isinstance(network, Unset):+ return None++ result: SandboxNetworkOpts = {}++ if not isinstance(network.allow_out, Unset):+ result["allow_out"] = list(network.allow_out)+ if not isinstance(network.deny_out, Unset):+ result["deny_out"] = list(network.deny_out)+ if not isinstance(network.allow_public_traffic, Unset):+ result["allow_public_traffic"] = network.allow_public_traffic+ if not isinstance(network.mask_request_host, Unset):+ result["mask_request_host"] = network.mask_request_host++ return result+++def from_client_lifecycle(+ lifecycle: Union[Unset, ClientSandboxLifecycle],+) -> Optional[SandboxInfoLifecycle]:+ if isinstance(lifecycle, Unset):+ return None++ result: SandboxInfoLifecycle = {+ "on_timeout": cast(Literal["pause", "kill"], lifecycle.on_timeout),+ "auto_resume": lifecycle.auto_resume,+ }++ return result++@dataclassclass SandboxInfo:"""Information about a sandbox."""@@ -129,6 +186,12 @@ class SandboxInfo:"""Envd version."""_envd_access_token: Optional[str]"""Envd access token."""+ allow_internet_access: Optional[bool] = None+ """Whether internet access was explicitly enabled or disabled for the sandbox."""+ network: Optional[SandboxNetworkOpts] = None+ """Sandbox network configuration."""+ lifecycle: Optional[SandboxInfoLifecycle] = None+ """Sandbox lifecycle configuration."""@classmethoddef _from_sandbox_data(@@ -136,6 +199,9 @@ class SandboxInfo:sandbox: Union[ListedSandbox, SandboxDetail],envd_access_token: Optional[str] = None,sandbox_domain: Optional[str] = None,+ allow_internet_access: Optional[bool] = None,+ network: Optional[SandboxNetworkOpts] = None,+ lifecycle: Optional[SandboxInfoLifecycle] = None,):return cls(sandbox_domain=sandbox_domain,@@ -153,6 +219,9 @@ class SandboxInfo:memory_mb=sandbox.memory_mb,envd_version=sandbox.envd_version,_envd_access_token=envd_access_token,+ allow_internet_access=allow_internet_access,+ network=network,+ lifecycle=lifecycle,)@classmethod@@ -173,6 +242,13 @@ class SandboxInfo:if isinstance(sandbox_detail.domain, str)else None),+ allow_internet_access=(+ sandbox_detail.allow_internet_access+ if isinstance(sandbox_detail.allow_internet_access, bool)+ else None+ ),+ network=from_client_network_config(sandbox_detail.network),+ lifecycle=from_client_lifecycle(sandbox_detail.lifecycle),)diff --git a/spec/openapi.yml b/spec/openapi.ymlindex 0d4df3453..fccbde234 100644--- a/spec/openapi.yml+++ b/spec/openapi.yml@@ -297,6 +297,26 @@ components:enabled:$ref: "#/components/schemas/SandboxAutoResumeEnabled"+ SandboxOnTimeout:+ type: string+ description: Action taken when the sandbox times out.+ enum:+ - kill+ - pause++ SandboxLifecycle:+ type: object+ description: Sandbox lifecycle policy returned by sandbox info.+ required:+ - autoResume+ - onTimeout+ properties:+ autoResume:+ type: boolean+ description: Whether the sandbox can auto-resume.+ onTimeout:+ $ref: "#/components/schemas/SandboxOnTimeout"+SandboxLog:description: Log entry with timestamp and linerequired:@@ -491,6 +511,10 @@ components:envdAccessToken:type: stringdescription: Access token used for envd communication+ allowInternetAccess:+ type: boolean+ nullable: true+ description: Whether internet access was explicitly enabled or disabled for the sandbox. Null means it was not explicitly set.domain:type: stringnullable: true@@ -505,6 +529,10 @@ components:$ref: "#/components/schemas/SandboxMetadata"state:$ref: "#/components/schemas/SandboxState"+ network:+ $ref: "#/components/schemas/SandboxNetworkConfig"+ lifecycle:+ $ref: "#/components/schemas/SandboxLifecycle"volumeMounts:type: arrayitems: