Skip to content

armgit / E2B

Public Imported from GitHub
0

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

allow passing empty array of files in python-sdk

0divfbc4af4908ea
diff --git a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
index 7af797ba9..f0b55b529 100644
--- a/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
+++ b/packages/python-sdk/e2b/sandbox_sync/filesystem/filesystem.py
@@ -155,7 +155,7 @@ class Filesystem:
When writing to a file that's in a directory that doesn't exist, you'll get an error.
"""
- path, write_files, user, request_timeout, = None, [], "user", None
+ path, write_files, user, request_timeout = None, [], "user", None
if isinstance(path_or_files, str):
if isinstance(data_or_user, list):
raise Exception("Cannot specify path with array of files")
@@ -165,9 +165,6 @@ class Filesystem:
path, write_files, user, request_timeout = \
None, path_or_files, data_or_user, user_or_request_timeout
- if len(write_files) == 0:
- raise Exception("Need at least one file to write")
-
# Prepare the files for the multipart/form-data request
httpx_files = []
for file in write_files:
@@ -178,6 +175,9 @@ class Filesystem:
httpx_files.append(('file', (file_path, file_data.read())))
else:
raise ValueError(f"Unsupported data type for file {file_path}")
+
+ # Allow passing empty list of files
+ if len(httpx_files) == 0: return []
params = {"username": user}
if path is not None: params["path"] = path
diff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
index 3ccbd41e0..a9bbf419d 100644
--- a/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.py
@@ -15,10 +15,9 @@ def test_write_file(sandbox):
def test_write_multiple_files(sandbox):
# Attempt to write with empty files array
- try:
- sandbox.files.write([])
- except Exception as e:
- assert "Need at least one file to write" in str(e)
+ empty_info = sandbox.files.write([])
+ assert isinstance(empty_info, list)
+ assert len(empty_info) == 0
# Attempt to write with path and file array
try: