Skip to content

armgit / E2B

Public Imported from GitHub
0

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

Add recursive watch envd version check python SDK, js SDK check

Jakub Dobrýec9288a48bb5
diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
index 404faf21d..7210b99bc 100644
--- a/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/filesystem.py
@@ -1,9 +1,10 @@
+import httpcore
+import httpx
from io import TextIOBase
+from packaging.version import Version
from typing import IO, AsyncIterator, List, Literal, Optional, Union, overload
import e2b_connect as connect
-import httpcore
-import httpx
from e2b.connection_config import (
ConnectionConfig,
Username,
@@ -13,7 +14,7 @@ from e2b.connection_config import (
from e2b.envd.api import ENVD_API_FILES_ROUTE, ahandle_envd_api_exception
from e2b.envd.filesystem import filesystem_connect, filesystem_pb2
from e2b.envd.rpc import authentication_header, handle_rpc_exception
-from e2b.exceptions import SandboxException
+from e2b.exceptions import SandboxException, TemplateException
from e2b.sandbox.filesystem.filesystem import EntryInfo, map_file_type
from e2b.sandbox.filesystem.watch_handle import FilesystemEvent
from e2b.sandbox_async.filesystem.watch_handle import AsyncWatchHandle
@@ -28,11 +29,13 @@ class Filesystem:
def __init__(
self,
envd_api_url: str,
+ envd_version: Optional[str],
connection_config: ConnectionConfig,
pool: httpcore.AsyncConnectionPool,
envd_api: httpx.AsyncClient,
) -> None:
self._envd_api_url = envd_api_url
+ self._envd_version = envd_version
self._connection_config = connection_config
self._pool = pool
self._envd_api = envd_api
@@ -358,6 +361,12 @@ class Filesystem:
:return: `AsyncWatchHandle` object for stopping watching directory
"""
+ if recursive and self._envd_version is not None and Version(self._envd_version) < Version("0.1.3"):
+ raise TemplateException(
+ "You need to update the template to use recursive watching. "
+ "You can do this by running `e2b template build` in the directory with the template."
+ )
+
events = self._rpc.awatch_dir(
filesystem_pb2.WatchDirRequest(path=path, recursive=recursive),
request_timeout=self._connection_config.get_request_timeout(
diff --git a/packages/python-sdk/e2b/sandbox_async/main.py b/packages/python-sdk/e2b/sandbox_async/main.py
index ae6a5c597..cb2a39328 100644
--- a/packages/python-sdk/e2b/sandbox_async/main.py
+++ b/packages/python-sdk/e2b/sandbox_async/main.py
@@ -114,6 +114,7 @@ class AsyncSandbox(SandboxSetup, SandboxApi):
self._filesystem = Filesystem(
self.envd_api_url,
+ self._envd_version,
self.connection_config,
self._transport._pool,
self._envd_api,
diff --git a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
index f3f30f31d..e353a5477 100644
--- a/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_async/sandbox_api.py
@@ -1,4 +1,4 @@
-from typing import Optional, Dict, List
+from typing import Optional, Dict, List, Tuple
from packaging.version import Version
from e2b.sandbox.sandbox_api import SandboxInfo, SandboxApiBase
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index 68a8d606e..5945226ae 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -4,6 +4,9 @@ from typing import IO, Iterator, List, Literal, Optional, Union, overload
import e2b_connect
import httpcore
import httpx
+from packaging.version import Version
+
+from e2b.exceptions import TemplateException
from e2b.connection_config import (
ConnectionConfig,
Username,
@@ -25,11 +28,13 @@ class Filesystem:
def __init__(
self,
envd_api_url: str,
+ envd_version: Optional[str],
connection_config: ConnectionConfig,
pool: httpcore.ConnectionPool,
envd_api: httpx.Client,
) -> None:
self._envd_api_url = envd_api_url
+ self._envd_version = envd_version
self._connection_config = connection_config
self._pool = pool
self._envd_api = envd_api
@@ -348,6 +353,12 @@ class Filesystem:
:return: `WatchHandle` object for stopping watching directory
"""
+ if recursive and self._envd_version is not None and Version(self._envd_version) < Version("0.1.3"):
+ raise TemplateException(
+ "You need to update the template to use recursive watching. "
+ "You can do this by running `e2b template build` in the directory with the template."
+ )
+
try:
r = self._rpc.create_watcher(
filesystem_pb2.CreateWatcherRequest(path=path, recursive=recursive),
diff --git a/packages/python-sdk/e2b/sandbox_sync/main.py b/packages/python-sdk/e2b/sandbox_sync/main.py
index 363568c96..8922b2dc4 100644
--- a/packages/python-sdk/e2b/sandbox_sync/main.py
+++ b/packages/python-sdk/e2b/sandbox_sync/main.py
@@ -159,6 +159,7 @@ class Sandbox(SandboxSetup, SandboxApi):
self._filesystem = Filesystem(
self.envd_api_url,
+ self._envd_version,
self.connection_config,
self._transport._pool,
self._envd_api,
diff --git a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
index f7557b694..ea1efe1ac 100644
--- a/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
+++ b/packages/python-sdk/e2b/sandbox_sync/sandbox_api.py
@@ -1,5 +1,5 @@
from httpx import HTTPTransport
-from typing import Optional, Dict, List
+from typing import Optional, Dict, List, Tuple
from packaging.version import Version
from e2b.sandbox.sandbox_api import SandboxInfo, SandboxApiBase