Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Make the sandbox constructor take named sandbox_id parameter

Tomas Valentafbaa43430661
diff --git a/packages/python-sdk/e2b/sandbox_async/main.py b/packages/python-sdk/e2b/sandbox_async/main.py
index ce07bf726..747739e81 100644
--- a/packages/python-sdk/e2b/sandbox_async/main.py
+++ b/packages/python-sdk/e2b/sandbox_async/main.py
@@ -1,7 +1,8 @@
import logging
import httpx
-from typing import Optional, Dict, overload
+from typing_extensions import Unpack
+from typing import Optional, Dict, TypedDict, overload
from e2b.exceptions import format_request_timeout_error
from e2b.sandbox.utils import class_method_variant
@@ -31,6 +32,11 @@ class AsyncTransportWithLogger(httpx.AsyncHTTPTransport):
return response
+class AsyncSandboxOpts(TypedDict):
+ sandbox_id: str
+ connection_config: ConnectionConfig
+
+
class AsyncSandbox(SandboxSetup, SandboxApi):
@property
def files(self) -> Filesystem:
@@ -52,11 +58,11 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
def connection_config(self) -> ConnectionConfig:
return self._connection_config
- def __init__(self, sandbox_id: str, connection_config: ConnectionConfig):
+ def __init__(self, **opts: Unpack[AsyncSandboxOpts]):
super().__init__()
- self._sandbox_id = sandbox_id
- self._connection_config = connection_config
+ self._sandbox_id = opts["sandbox_id"]
+ self._connection_config = opts["connection_config"]
self._envd_api_url = f"{'http' if self.connection_config.debug else 'https'}://{self.get_host(self.envd_port)}"
@@ -78,9 +84,7 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
self._transport._pool,
)
- async def is_running(
- self, request_timeout: Optional[float] = None
- ) -> bool:
+ async def is_running(self, request_timeout: Optional[float] = None) -> bool:
try:
r = await self._envd_api.get(
ENVD_API_HEALTH_ROUTE,
diff --git a/packages/python-sdk/poetry.lock b/packages/python-sdk/poetry.lock
index fc6aa3241..124b22cca 100644
--- a/packages/python-sdk/poetry.lock
+++ b/packages/python-sdk/poetry.lock
@@ -1,4 +1,4 @@
-# This file is automatically @generated by Poetry 1.8.2 and should not be changed by hand.
+# This file is automatically @generated by Poetry 1.8.3 and should not be changed by hand.
[[package]]
name = "anyio"
@@ -476,4 +476,4 @@ files = [
[metadata]
lock-version = "2.0"
python-versions = "^3.8"
-content-hash = "9fa532d36022f576d8cee54d241648fd79772293136a8aed7ccf5873a973e4bd"
+content-hash = "43860bdef3033dfba1d67cb5e0424567cb2b715f7109f3d38872b80685def057"
diff --git a/packages/python-sdk/pyproject.toml b/packages/python-sdk/pyproject.toml
index 952cedd3a..3308ef84c 100644
--- a/packages/python-sdk/pyproject.toml
+++ b/packages/python-sdk/pyproject.toml
@@ -18,6 +18,7 @@ httpcore = "^1.0.5"
httpx = "^0.27.0"
attrs = "^23.2.0"
packaging = "^24.1"
+typing-extensions = "^4.12.2"
[tool.poetry.group.dev.dependencies]
black = "^23.7.0"