Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add testing python setup

Tomas Valentaf5764d165402
diff --git a/packages/python-sdk/e2b/grpc/main.py b/packages/python-sdk/e2b/grpc/main.py
index d8142774b..2166c8054 100644
--- a/packages/python-sdk/e2b/grpc/main.py
+++ b/packages/python-sdk/e2b/grpc/main.py
@@ -7,14 +7,13 @@ import filesystem_pb2
import filesystem_pb2_grpc
-def call_grpc():
+def call_grpc(url: str):
print("Will try to greet world ...")
- with grpc.insecure_channel("localhost:50051") as channel:
-
- filesystem_pb2_grpc.Filesystem.ReadFile()
+ with grpc.insecure_channel(url) as channel:
stub = filesystem_pb2_grpc.FilesystemStub(channel)
- response = stub.ReadFile(filesystem_pb2.ReadFileRequest(path="/"))
- print("Greeter client received: " + response.message)
+ responses = stub.ReadFile(filesystem_pb2.ReadFileRequest(path="/usr/bin/envd"))
+ for response in responses:
+ print("Received message", response)
if __name__ == "__main__":
diff --git a/packages/python-sdk/e2b/sandbox/main.py b/packages/python-sdk/e2b/sandbox/main.py
index fea2bfd9d..d3bda05f6 100644
--- a/packages/python-sdk/e2b/sandbox/main.py
+++ b/packages/python-sdk/e2b/sandbox/main.py
@@ -319,14 +319,14 @@ class Sandbox(SandboxConnection):
"""
logger.info(f"Opening sandbox {self._template}")
super()._open(metadata=metadata, timeout=timeout)
- self._code_snippet._subscribe()
+ # self._code_snippet._subscribe()
logger.info(f"Sandbox {self._template} opened")
- if self.cwd:
- self.filesystem.make_dir(self.cwd)
+ # if self.cwd:
+ # self.filesystem.make_dir(self.cwd)
- if self._on_stderr or self._on_stdout:
- self._handle_start_cmd_logs()
+ # if self._on_stderr or self._on_stdout:
+ # self._handle_start_cmd_logs()
def file_url(self) -> str:
"""
diff --git a/packages/python-sdk/e2b/sandbox/sandbox_connection.py b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
index c070ea5cb..e019322b8 100644
--- a/packages/python-sdk/e2b/sandbox/sandbox_connection.py
+++ b/packages/python-sdk/e2b/sandbox/sandbox_connection.py
@@ -8,6 +8,7 @@ from concurrent.futures import ThreadPoolExecutor, CancelledError
from time import sleep
from typing import Any, Callable, List, Literal, Optional, Union, Dict
from datetime import datetime
+from e2b.grpc.main import call_grpc
from pydantic import BaseModel
from urllib3.exceptions import ReadTimeoutError, MaxRetryError, ConnectTimeoutError
@@ -272,7 +273,11 @@ class SandboxConnection:
self._start_refreshing()
try:
- self._connect_rpc(timeout)
+ url = self.get_hostname(self._debug_port or ENVD_PORT)
+ print(f"url: {url}")
+ call_grpc(url)
+
+ # self._connect_rpc(timeout)
except Exception as e:
logger.error(e)
self._close()
@@ -423,9 +428,7 @@ class SandboxConnection:
api = client.SandboxesApi(self._api_client)
while True:
if not self._is_open:
- logger.debug(
- f"Cannot refresh sandbox - it was closed. {self.id}"
- )
+ logger.debug(f"Cannot refresh sandbox - it was closed. {self.id}")
return
sleep(SANDBOX_REFRESH_PERIOD)
try:
@@ -459,7 +462,9 @@ class SandboxConnection:
self._close()
@staticmethod
- def list(api_key: Optional[str] = None, domain: str = DOMAIN) -> List[RunningSandbox]:
+ def list(
+ api_key: Optional[str] = None, domain: str = DOMAIN
+ ) -> List[RunningSandbox]:
"""
List all running sandboxes.
@@ -479,7 +484,9 @@ class SandboxConnection:
]
@staticmethod
- def kill(sandbox_id: str, api_key: Optional[str] = None, domain: str = DOMAIN) -> None:
+ def kill(
+ sandbox_id: str, api_key: Optional[str] = None, domain: str = DOMAIN
+ ) -> None:
"""
Kill the running sandbox specified by the sandbox ID.
diff --git a/packages/python-sdk/example.py b/packages/python-sdk/example.py
index a9593bd68..71875416e 100644
--- a/packages/python-sdk/example.py
+++ b/packages/python-sdk/example.py
@@ -2,10 +2,22 @@ import logging
from dotenv import load_dotenv
from e2b import Sandbox
+import time
load_dotenv()
logging.basicConfig(level=logging.ERROR)
-with Sandbox() as sandbox:
+start = time.time()
+
+with Sandbox(
+ template="i32b48xtmbk9w5vfad1l",
+ # _debug_hostname="localhost",
+ # _debug_port=49982,
+ # _debug_dev_env="local",
+) as sandbox:
print(sandbox.id)
+
+ end = time.time()
+
+ print(f"Time taken: {end - start}")