Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Always return string from sandbox.id

Tomas Valenta3d2b898e45cb
diff --git a/.changeset/heavy-camels-add.md b/.changeset/heavy-camels-add.md
new file mode 100644
index 000000000..5c5e9dae8
--- /dev/null
+++ b/.changeset/heavy-camels-add.md
@@ -0,0 +1,5 @@
+---
+"@e2b/python-sdk": patch
+---
+
+Improve Python SDK sandbox property type
diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
index 5218104c1..2be5aea7c 100644
--- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py
+++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
@@ -45,14 +45,14 @@ class SandboxConnection:
_on_close_child: Optional[Callable[[], Any]] = None
@property
- def id(self):
+ def id(self) -> str:
"""
The sandbox ID.
You can use this ID to reconnect to the sandbox later.
"""
if not self._sandbox:
- return None
+ raise SandboxException("Sandbox is not running.")
return f"{self._sandbox.instance_id}-{self._sandbox.client_id}"
@property
diff --git a/packages/python-sdk/example.py b/packages/python-sdk/example.py
index 9e0f3cc72..a9593bd68 100644
--- a/packages/python-sdk/example.py
+++ b/packages/python-sdk/example.py
@@ -1,26 +1,11 @@
import logging
-from os import getenv
from dotenv import load_dotenv
-
from e2b import Sandbox
load_dotenv()
-id = "Python3"
-E2B_API_KEY = getenv("E2B_API_KEY")
logging.basicConfig(level=logging.ERROR)
-
-def main():
- s = Sandbox(api_key=E2B_API_KEY)
-
- a = s.process.start("ls -la /var")
- a.wait()
- print(a.stdout)
- print(a.stderr)
- s.close()
- return
-
-
-main()
+with Sandbox() as sandbox:
+ print(sandbox.id)