Open-source, secure environment with real-world tools for enterprise-grade agents.
Python agentaiai-agentai-agentscode-interpretercopilotdevelopmentdevtoolsgptgpt-4javascriptllmnextjsopenaipythonreactsoftwaretypescript
Add async tests; Fix watch test; [WIP] Fix create task
Tomas Valentac660ff4576b1
diff --git a/packages/js-sdk/tests/sandbox/files/list.test.ts b/packages/js-sdk/tests/sandbox/files/list.test.tsindex e69de29bb..7422c1355 100644--- a/packages/js-sdk/tests/sandbox/files/list.test.ts+++ b/packages/js-sdk/tests/sandbox/files/list.test.ts@@ -0,0 +1,22 @@+import { assert } from 'vitest'++import { sandboxTest } from '../../setup.js'++sandboxTest('list directory', async ({ sandbox }) => {+ const dirName = 'test_directory'++ await sandbox.files.makeDir(dirName)++ const files = await sandbox.files.list(dirName)+ assert.equal(files.length, 0)++ await sandbox.files.write('test_directory/test_file', 'test')++ const files1 = await sandbox.files.list(dirName)+ assert.equal(files1.length, 1)+ assert.equal(files1[0].name, 'test_file')+ assert.equal(files1[0].type, 'file')++ const exists = await sandbox.files.exists(dirName)+ assert.isTrue(exists)+})diff --git a/packages/js-sdk/tests/sandbox/files/watch.test.ts b/packages/js-sdk/tests/sandbox/files/watch.test.tsindex 0f14a76f6..36ec01016 100644--- a/packages/js-sdk/tests/sandbox/files/watch.test.ts+++ b/packages/js-sdk/tests/sandbox/files/watch.test.ts@@ -1,4 +1,4 @@-import { assert, expect } from 'vitest'+import { expect } from 'vitest'import { sandboxTest } from '../../setup.js'import { FilesystemEventType, NotFoundError } from '../../../src'@@ -12,17 +12,23 @@ sandboxTest('watch directory changes', async ({ sandbox }) => {await sandbox.files.makeDir(dirname)await sandbox.files.write(`${dirname}/${filename}`, content)- let eventTriggered = false+ let trigger: () => void++ const eventPromise = new Promise<void>(resolve => {+ trigger = resolve+ })++const handle = await sandbox.files.watch(dirname, async (event) => {if (event.type === FilesystemEventType.WRITE && event.name === filename) {- eventTriggered = true+ trigger()}})await sandbox.files.write(`${dirname}/${filename}`, newContent)await new Promise(resolve => setTimeout(resolve, 1000)) // wait for the event to be triggered- assert.isTrue(eventTriggered)+ await eventPromiseawait handle.close()})diff --git a/packages/python-sdk/e2b/sandbox_async/filesystem/watch_handle.py b/packages/python-sdk/e2b/sandbox_async/filesystem/watch_handle.pyindex cfb2b01a5..c9b131c19 100644--- a/packages/python-sdk/e2b/sandbox_async/filesystem/watch_handle.py+++ b/packages/python-sdk/e2b/sandbox_async/filesystem/watch_handle.py@@ -1,4 +1,4 @@-import asyncio+import anyioimport inspectfrom typing import Any, AsyncGenerator, Optional@@ -19,10 +19,12 @@ class AsyncWatchHandle:self._events = eventsself._on_event = on_eventself._on_exit = on_exit- self._task = asyncio.create_task(self._handle_events())++ self._tg = anyio.create_task_group()+ self._tg.start_soon(self._handle_events)async def close(self):- self._task.cancel()+ self._tg.cancel_scope.cancel()await self._events.aclose()async def _iterate_events(self):diff --git a/packages/python-sdk/e2b/sandbox_async/process/process_handle.py b/packages/python-sdk/e2b/sandbox_async/process/process_handle.pyindex 6f592b5a8..05d8f574a 100644--- a/packages/python-sdk/e2b/sandbox_async/process/process_handle.py+++ b/packages/python-sdk/e2b/sandbox_async/process/process_handle.py@@ -1,4 +1,4 @@-import asyncio+import anyioimport inspectfrom typing import (Optional,@@ -69,7 +69,14 @@ class AsyncProcessHandle:self._result: Optional[ProcessResult] = Noneself._iteration_exception: Optional[Exception] = None- self._wait = asyncio.create_task(self._handle_events())+ self._tg = anyio.create_task_group()+ self._wait = anyio.Event()++ async def wait():+ await self._handle_events()+ self._wait.set()++ self._tg.start_soon(wait)async def _iterate_events(self,@@ -99,6 +106,7 @@ class AsyncProcessHandle:await self.disconnect()async def disconnect(self) -> None:+ self._tg.cancel_scope.cancel()await self._events.aclose()async def _handle_events(self):@@ -134,7 +142,7 @@ class AsyncProcessHandle:return self._resultasync def wait(self) -> ProcessResult:- await self._wait+ await self._wait.wait()if self._iteration_exception:raise self._iteration_exception@@ -153,4 +161,5 @@ class AsyncProcessHandle:return self._resultasync def kill(self):+ self._tg.cancel_scope.cancel()await self._handle_kill()diff --git a/packages/python-sdk/poetry.lock b/packages/python-sdk/poetry.lockindex 5ded889f9..0190addd6 100644--- a/packages/python-sdk/poetry.lock+++ b/packages/python-sdk/poetry.lock@@ -445,4 +445,4 @@ files = [[metadata]lock-version = "2.0"python-versions = "^3.8"-content-hash = "e0bad63042465728305d56fa013c5e7c9c207e6d1f31630d1c137c4456ae20a6"+content-hash = "fb057b723b0e97a0757c61b2ddf1967d7e601755005076fd9dadf04be9f1c5f1"diff --git a/packages/python-sdk/pyproject.toml b/packages/python-sdk/pyproject.tomlindex ce0cc537b..b94696377 100644--- a/packages/python-sdk/pyproject.toml+++ b/packages/python-sdk/pyproject.toml@@ -17,6 +17,7 @@ protobuf = "^5.26.1"httpcore = "^1.0.5"httpx = "^0.27.0"attrs = "^23.2.0"+anyio = "^4.4.0"[tool.poetry.group.dev.dependencies]black = "^23.7.0"diff --git a/packages/python-sdk/tests/async/api_async/test_sbx_kill.py b/packages/python-sdk/tests/async/api_async/test_sbx_kill.pynew file mode 100644index 000000000..991880d86--- /dev/null+++ b/packages/python-sdk/tests/async/api_async/test_sbx_kill.py@@ -0,0 +1,18 @@+import pytest++from e2b import AsyncSandbox++[email protected]_debug()+async def test_kill_existing_sandbox(async_sandbox: AsyncSandbox):+ assert await AsyncSandbox.kill(async_sandbox.sandbox_id) == True++ list = await AsyncSandbox.list()+ assert async_sandbox.sandbox_id not in [s.sandbox_id for s in list]++[email protected]_debug()+async def test_kill_non_existing_sandbox():+ assert await AsyncSandbox.kill("non-existing-sandbox") == Falsediff --git a/packages/python-sdk/tests/async/api_async/test_sbx_list.py b/packages/python-sdk/tests/async/api_async/test_sbx_list.pynew file mode 100644index 000000000..2d466df9b--- /dev/null+++ b/packages/python-sdk/tests/async/api_async/test_sbx_list.py@@ -0,0 +1,11 @@+import pytest++from e2b import AsyncSandbox++[email protected]_debug()+async def test_list_sandboxes(async_sandbox: AsyncSandbox):+ sandboxes = await AsyncSandbox.list()+ assert len(sandboxes) > 0+ assert async_sandbox.sandbox_id in [sbx.sandbox_id for sbx in sandboxes]diff --git a/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_connect.py b/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_connect.pynew file mode 100644index 000000000..c80a35b6d--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_connect.py@@ -0,0 +1,20 @@+import pytest++from e2b import NotFoundException, AsyncSandbox+++async def test_connect_to_process(async_sandbox: AsyncSandbox):+ cmd = await async_sandbox.commands.run("sleep 10", background=True)+ pid = cmd.pid++ process_info = await async_sandbox.commands.connect(pid)+ assert process_info.pid == pid+++async def test_connect_to_non_existing_process(async_sandbox: AsyncSandbox):+ non_existing_pid = 999999++ with pytest.raises(NotFoundException):+ await async_sandbox.commands.connect(non_existing_pid)diff --git a/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_kill.py b/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_kill.pynew file mode 100644index 000000000..d54b5ade7--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_kill.py@@ -0,0 +1,21 @@+import pytest++from e2b import AsyncSandbox, ProcessExitException+++async def test_kill_process(async_sandbox: AsyncSandbox):+ cmd = await async_sandbox.commands.run("sleep 10", background=True)+ pid = cmd.pid++ await async_sandbox.commands.kill(pid)++ with pytest.raises(ProcessExitException):+ await async_sandbox.commands.run(f"kill -0 {pid}")+++async def test_kill_non_existing_process(async_sandbox: AsyncSandbox):+ non_existing_pid = 999999++ assert await async_sandbox.commands.kill(non_existing_pid) == Falsediff --git a/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_list.py b/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_list.pynew file mode 100644index 000000000..154f44097--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/commands/test_cmd_list.py@@ -0,0 +1,16 @@+import pytest++from e2b import AsyncSandbox+++async def test_kill_process(async_sandbox: AsyncSandbox):+ c1 = await async_sandbox.commands.run("sleep 10", background=True)+ c2 = await async_sandbox.commands.run("sleep 10", background=True)++ processes = await async_sandbox.commands.list()++ assert len(processes) >= 2+ pids = [p.pid for p in processes]+ assert c1.pid in pids+ assert c2.pid in pidsdiff --git a/packages/python-sdk/tests/async/sandbox_async/commands/test_run.py b/packages/python-sdk/tests/async/sandbox_async/commands/test_run.pynew file mode 100644index 000000000..cebd82648--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/commands/test_run.py@@ -0,0 +1,46 @@+import pytest++from e2b import AsyncSandbox+++async def test_run(async_sandbox: AsyncSandbox):+ text = "Hello, World!"++ cmd = await async_sandbox.commands.run(f'echo "{text}"')++ assert cmd.exit_code == 0+ assert cmd.stdout == f"{text}\n"+++async def test_run_with_special_characters(async_sandbox: AsyncSandbox):+ text = "!@#$%^&*()_+"++ cmd = await async_sandbox.commands.run(f'echo "{text}"')++ assert cmd.exit_code == 0+ assert cmd.stdout == f"{text}\n"+++async def test_run_with_multiline_string(async_sandbox: AsyncSandbox):+ text = "Hello,\nWorld!"++ cmd = await async_sandbox.commands.run(f'echo "{text}"')++ assert cmd.exit_code == 0+ assert cmd.stdout == f"{text}\n"+++async def test_run_with_timeout(async_sandbox: AsyncSandbox):+ cmd = await async_sandbox.commands.run('echo "Hello, World!"', timeout=1000)++ assert cmd.exit_code == 0+++async def test_run_with_too_short_timeout(async_sandbox: AsyncSandbox):+ with pytest.raises(Exception):+ await async_sandbox.commands.run("sleep 10", timeout=1000)diff --git a/packages/python-sdk/tests/async/sandbox_async/commands/test_send_stdin.py b/packages/python-sdk/tests/async/sandbox_async/commands/test_send_stdin.pynew file mode 100644index 000000000..56939005c--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/commands/test_send_stdin.py@@ -0,0 +1,34 @@+import pytest+import anyio++from e2b import AsyncSandbox+++async def test_send_stdin_to_process(async_sandbox: AsyncSandbox):+ cmd = await async_sandbox.commands.run("cat", background=True)+ await async_sandbox.commands.send_stdin(cmd.pid, "Hello, World!")++ await anyio.sleep(2)++ assert cmd.stdout == "Hello, World!"+++async def test_send_special_characters_to_process(async_sandbox: AsyncSandbox):+ cmd = await async_sandbox.commands.run("cat", background=True)+ await async_sandbox.commands.send_stdin(cmd.pid, "!@#$%^&*()_+")++ await anyio.sleep(2)++ assert cmd.stdout == "!@#$%^&*()_+"+++async def test_send_multiline_string_to_process(async_sandbox: AsyncSandbox):+ cmd = await async_sandbox.commands.run("cat", background=True)+ await async_sandbox.commands.send_stdin(cmd.pid, "Hello,\nWorld!")++ await anyio.sleep(2)++ assert cmd.stdout == "Hello,\nWorld!"diff --git a/packages/python-sdk/tests/sandbox_async/files/test_exists.py b/packages/python-sdk/tests/async/sandbox_async/files/test_exists.pysimilarity index 91%rename from packages/python-sdk/tests/sandbox_async/files/test_exists.pyrename to packages/python-sdk/tests/async/sandbox_async/files/test_exists.pyindex dc7057d6b..21cd19240 100644--- a/packages/python-sdk/tests/sandbox_async/files/test_exists.py+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_exists.py@@ -3,7 +3,7 @@ import pytestfrom e2b import AsyncSandboxasync def test_exists(async_sandbox: AsyncSandbox):filename = "test_exists.txt"diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.py b/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.pynew file mode 100644index 000000000..01050c9d7--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_files_list.py@@ -0,0 +1,18 @@+import pytest++from e2b import AsyncSandbox, FileType+++async def test_list_directory(async_sandbox: AsyncSandbox):+ dir_name = "test_directory"++ await async_sandbox.files.make_dir(dir_name)+ files = await async_sandbox.files.list(dir_name)+ assert len(files) == 0++ await async_sandbox.files.write(f"{dir_name}/test_file", "test")+ files1 = await async_sandbox.files.list(dir_name)+ assert len(files1) == 1+ assert files1[0].name == "test_file"+ assert files1[0].type == FileType.FILEdiff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.py b/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.pynew file mode 100644index 000000000..3dfb580f9--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_make_dir.py@@ -0,0 +1,21 @@+import pytest++from e2b import AsyncSandbox+++async def test_make_directory(async_sandbox: AsyncSandbox):+ dir_name = "test_directory"++ await async_sandbox.files.make_dir(dir_name)+ exists = await async_sandbox.files.exists(dir_name)+ assert exists+++async def test_make_nested_directory(async_sandbox: AsyncSandbox):+ nested_dir_name = "test_directory/nested_directory"++ await async_sandbox.files.make_dir(nested_dir_name)+ exists = await async_sandbox.files.exists(nested_dir_name)+ assert existsdiff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_read.py b/packages/python-sdk/tests/async/sandbox_async/files/test_read.pynew file mode 100644index 000000000..25fbdc8bc--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_read.py@@ -0,0 +1,21 @@+import pytest++from e2b import NotFoundException, AsyncSandbox+++async def test_read_file(async_sandbox: AsyncSandbox):+ filename = "test_read.txt"+ content = "Hello, world!"++ await async_sandbox.files.write(filename, content)+ read_content = await async_sandbox.files.read(filename)+ assert read_content == content+++async def test_read_non_existing_file(async_sandbox: AsyncSandbox):+ filename = "non_existing_file.txt"++ with pytest.raises(NotFoundException):+ await async_sandbox.files.read(filename)diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_remove.py b/packages/python-sdk/tests/async/sandbox_async/files/test_remove.pynew file mode 100644index 000000000..403ae280d--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_remove.py@@ -0,0 +1,20 @@+import pytest++from e2b import AsyncSandbox+++async def test_remove_file(async_sandbox: AsyncSandbox):+ filename = "test_remove.txt"+ content = "This file will be removed."++ await async_sandbox.files.write(filename, content)+ await async_sandbox.files.remove(filename)+ exists = await async_sandbox.files.exists(filename)+ assert not exists+++async def test_remove_non_existing_file(async_sandbox: AsyncSandbox):+ filename = "non_existing_file.txt"+ await async_sandbox.files.remove(filename)diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_rename.py b/packages/python-sdk/tests/async/sandbox_async/files/test_rename.pynew file mode 100644index 000000000..7ecc7320a--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_rename.py@@ -0,0 +1,28 @@+import pytest++from e2b import NotFoundException, AsyncSandbox+++async def test_rename_file(async_sandbox: AsyncSandbox):+ old_filename = "test_rename_old.txt"+ new_filename = "test_rename_new.txt"+ content = "This file will be renamed."++ await async_sandbox.files.write(old_filename, content)+ await async_sandbox.files.rename(old_filename, new_filename)+ exists_old = await async_sandbox.files.exists(old_filename)+ exists_new = await async_sandbox.files.exists(new_filename)+ assert not exists_old+ assert exists_new+ read_content = await async_sandbox.files.read(new_filename)+ assert read_content == content+++async def test_rename_non_existing_file(async_sandbox: AsyncSandbox):+ old_filename = "non_existing_file.txt"+ new_filename = "new_non_existing_file.txt"++ with pytest.raises(NotFoundException):+ await async_sandbox.files.rename(old_filename, new_filename)diff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py b/packages/python-sdk/tests/async/sandbox_async/files/test_watch.pynew file mode 100644index 000000000..7f09825f3--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_watch.py@@ -0,0 +1,41 @@+import pytest++from asyncio import Event++from e2b import NotFoundException, AsyncSandbox, FilesystemEvent, FilesystemEventType+++async def test_watch_directory_changes(async_sandbox: AsyncSandbox):+ dirname = "test_watch_dir"+ filename = "test_watch.txt"+ content = "This file will be watched."+ new_content = "This file has been modified."++ await async_sandbox.files.make_dir(dirname)+ await async_sandbox.files.write(f"{dirname}/{filename}", content)++ event_triggered = Event()++ def handle_event(e: FilesystemEvent):+ if e.type == FilesystemEventType.WRITE and e.name == filename:+ event_triggered.set()++ handle = await async_sandbox.files.watch(dirname, on_event=handle_event)++ await async_sandbox.files.write(f"{dirname}/{filename}", new_content)++ await event_triggered.wait()++ await handle.close()+++async def test_watch_non_existing_directory(async_sandbox: AsyncSandbox):+ dirname = "non_existing_watch_dir"++ with pytest.raises(NotFoundException):+ await async_sandbox.files.watch(dirname, on_event=lambda e: None)+++# TODO: Add test for nonexistent filediff --git a/packages/python-sdk/tests/async/sandbox_async/files/test_write.py b/packages/python-sdk/tests/async/sandbox_async/files/test_write.pynew file mode 100644index 000000000..bcd43e46d--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/files/test_write.py@@ -0,0 +1,41 @@+import pytest++from e2b import AsyncSandbox+++async def test_write_file(async_sandbox: AsyncSandbox):+ filename = "test_write.txt"+ content = "This is a test file."++ await async_sandbox.files.write(filename, content)+ exists = await async_sandbox.files.exists(filename)+ assert exists++ read_content = await async_sandbox.files.read(filename)+ assert read_content == content+++async def test_overwrite_file(async_sandbox: AsyncSandbox):+ filename = "test_overwrite.txt"+ initial_content = "Initial content."+ new_content = "New content."++ await async_sandbox.files.write(filename, initial_content)+ await async_sandbox.files.write(filename, new_content)+ read_content = await async_sandbox.files.read(filename)+ assert read_content == new_content+++async def test_write_to_non_existing_directory(async_sandbox: AsyncSandbox):+ filename = "non_existing_dir/test_write.txt"+ content = "This should succeed too."++ await async_sandbox.files.write(filename, content)+ exists = await async_sandbox.files.exists(filename)+ assert exists++ read_content = await async_sandbox.files.read(filename)+ assert read_content == contentdiff --git a/packages/python-sdk/tests/sandbox_async/pty/test_pty_create.py b/packages/python-sdk/tests/async/sandbox_async/pty/test_pty_create.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/pty/test_pty_create.pyrename to packages/python-sdk/tests/async/sandbox_async/pty/test_pty_create.pydiff --git a/packages/python-sdk/tests/sandbox_async/pty/test_resize.py b/packages/python-sdk/tests/async/sandbox_async/pty/test_resize.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/pty/test_resize.pyrename to packages/python-sdk/tests/async/sandbox_async/pty/test_resize.pydiff --git a/packages/python-sdk/tests/sandbox_async/pty/test_stream_input.py b/packages/python-sdk/tests/async/sandbox_async/pty/test_stream_input.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/pty/test_stream_input.pyrename to packages/python-sdk/tests/async/sandbox_async/pty/test_stream_input.pydiff --git a/packages/python-sdk/tests/sandbox_async/test_connect.py b/packages/python-sdk/tests/async/sandbox_async/test_connect.pysimilarity index 93%rename from packages/python-sdk/tests/sandbox_async/test_connect.pyrename to packages/python-sdk/tests/async/sandbox_async/test_connect.pyindex 651ca23d5..7655098d5 100644--- a/packages/python-sdk/tests/sandbox_async/test_connect.py+++ b/packages/python-sdk/tests/async/sandbox_async/test_connect.py@@ -3,7 +3,7 @@ import pytestfrom e2b import AsyncSandboxasync def test_connect(template):sbx = await AsyncSandbox.create(template, timeout=10)assert await sbx.is_running()diff --git a/packages/python-sdk/tests/sandbox_async/test_create.py b/packages/python-sdk/tests/async/sandbox_async/test_create.pysimilarity index 94%rename from packages/python-sdk/tests/sandbox_async/test_create.pyrename to packages/python-sdk/tests/async/sandbox_async/test_create.pyindex cee667c62..6cb1ed671 100644--- a/packages/python-sdk/tests/sandbox_async/test_create.py+++ b/packages/python-sdk/tests/async/sandbox_async/test_create.py@@ -4,14 +4,14 @@ from e2b import AsyncSandbox@pytest.mark.skip_debug()async def test_start(template):sbx = await AsyncSandbox.create(template, timeout=5)assert await sbx.is_running()@pytest.mark.skip_debug()async def test_metadata(template):sbx = await AsyncSandbox.create(template, timeout=5, metadata={"test-key": "test-value"}diff --git a/packages/python-sdk/tests/async/sandbox_async/test_host.py b/packages/python-sdk/tests/async/sandbox_async/test_host.pynew file mode 100644index 000000000..c4fad88f9--- /dev/null+++ b/packages/python-sdk/tests/async/sandbox_async/test_host.py@@ -0,0 +1,25 @@+import httpx+import pytest++from time import sleep++from e2b import AsyncSandbox+++async def test_ping_server(async_sandbox: AsyncSandbox, debug):+ cmd = await async_sandbox.commands.run(+ "python -m http.server 8000",+ background=True,+ )++ try:+ sleep(1)+ host = async_sandbox.get_host(8000)++ async with httpx.AsyncClient() as client:+ res = await client.get(f"{'http' if debug else 'https'}://{host}")+ assert res.status_code == 200++ finally:+ await cmd.kill()diff --git a/packages/python-sdk/tests/sandbox_async/test_kill.py b/packages/python-sdk/tests/async/sandbox_async/test_kill.pysimilarity index 92%rename from packages/python-sdk/tests/sandbox_async/test_kill.pyrename to packages/python-sdk/tests/async/sandbox_async/test_kill.pyindex 19c1cf040..d59430dc9 100644--- a/packages/python-sdk/tests/sandbox_async/test_kill.py+++ b/packages/python-sdk/tests/async/sandbox_async/test_kill.py@@ -4,7 +4,7 @@ from e2b import AsyncSandbox@pytest.mark.skip_debug()async def test_kill(async_sandbox: AsyncSandbox):await async_sandbox.kill()diff --git a/packages/python-sdk/tests/sandbox_async/test_timeout.py b/packages/python-sdk/tests/async/sandbox_async/test_timeout.pysimilarity index 93%rename from packages/python-sdk/tests/sandbox_async/test_timeout.pyrename to packages/python-sdk/tests/async/sandbox_async/test_timeout.pyindex 452f2a40c..15205a77e 100644--- a/packages/python-sdk/tests/sandbox_async/test_timeout.py+++ b/packages/python-sdk/tests/async/sandbox_async/test_timeout.py@@ -7,7 +7,7 @@ from e2b import AsyncSandbox@pytest.mark.skip_debug()async def test_shorten_timeout(async_sandbox: AsyncSandbox):await async_sandbox.set_timeout(5)sleep(6)@@ -16,7 +16,7 @@ async def test_shorten_timeout(async_sandbox: AsyncSandbox):@pytest.mark.skip_debug()async def test_shorten_then_lengthen_timeout(async_sandbox: AsyncSandbox):await async_sandbox.set_timeout(5)sleep(1)diff --git a/packages/python-sdk/tests/sandbox_async/test_upload_url.py b/packages/python-sdk/tests/async/sandbox_async/test_upload_url.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/test_upload_url.pyrename to packages/python-sdk/tests/async/sandbox_async/test_upload_url.pydiff --git a/packages/python-sdk/tests/conftest.py b/packages/python-sdk/tests/conftest.pyindex f4f5a0682..1aef2082a 100644--- a/packages/python-sdk/tests/conftest.py+++ b/packages/python-sdk/tests/conftest.py@@ -53,3 +53,8 @@ def skip_by_debug(request, debug):if request.node.get_closest_marker("skip_debug"):if debug:pytest.skip("skipped because E2B_DEBUG is set")+++def anyio_backend():+ return "asyncio"diff --git a/packages/python-sdk/tests/sandbox_async/files/test_files_list.py b/packages/python-sdk/tests/sandbox_async/files/test_files_list.pydeleted file mode 100644index e69de29bb..000000000diff --git a/packages/python-sdk/tests/sandbox_async/test_host.py b/packages/python-sdk/tests/sandbox_async/test_host.pydeleted file mode 100644index 749fbf656..000000000--- a/packages/python-sdk/tests/sandbox_async/test_host.py+++ /dev/null@@ -1,20 +0,0 @@-import httpx-import pytest--from time import sleep--from e2b import AsyncSandbox---async def test_ping_server(async_sandbox: AsyncSandbox, debug):- cmd = async_sandbox.commands.run("python -m http.server 8000", background=True)-- try:- sleep(1)- host = async_sandbox.get_host(8000)- res = httpx.get(f"{'http' if debug else 'https'}://{host}")- assert res.status_code == 200-- finally:- cmd.kill()diff --git a/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_connect.py b/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_connect.pydeleted file mode 100644index eb705698d..000000000--- a/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_connect.py+++ /dev/null@@ -1,18 +0,0 @@-import pytest--from e2b import NotFoundException---def test_connect_to_process(sandbox):- cmd = sandbox.commands.run("sleep 10", background=True)- pid = cmd.pid-- process_info = sandbox.commands.connect(pid)- assert process_info.pid == pid---def test_connect_to_non_existing_process(sandbox):- non_existing_pid = 999999-- with pytest.raises(NotFoundException):- sandbox.commands.connect(non_existing_pid)diff --git a/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_kill.py b/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_kill.pydeleted file mode 100644index ed9e21bd3..000000000--- a/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_kill.py+++ /dev/null@@ -1,19 +0,0 @@-import pytest--from e2b import Sandbox, ProcessExitException---def test_kill_process(sandbox: Sandbox):- cmd = sandbox.commands.run("sleep 10", background=True)- pid = cmd.pid-- sandbox.commands.kill(pid)-- with pytest.raises(ProcessExitException):- sandbox.commands.run(f"kill -0 {pid}")---def test_kill_non_existing_process(sandbox):- non_existing_pid = 999999-- assert sandbox.commands.kill(non_existing_pid) == Falsediff --git a/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_list.py b/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_list.pydeleted file mode 100644index 30bedb510..000000000--- a/packages/python-sdk/tests/sandbox_sync/commands/test_cmd_list.py+++ /dev/null@@ -1,13 +0,0 @@-from e2b import Sandbox---def test_kill_process(sandbox: Sandbox):- c1 = sandbox.commands.run("sleep 10", background=True)- c2 = sandbox.commands.run("sleep 10", background=True)-- processes = sandbox.commands.list()-- assert len(processes) >= 2- pids = [p.pid for p in processes]- assert c1.pid in pids- assert c2.pid in pidsdiff --git a/packages/python-sdk/tests/sandbox_sync/commands/test_run.py b/packages/python-sdk/tests/sandbox_sync/commands/test_run.pydeleted file mode 100644index 337844e26..000000000--- a/packages/python-sdk/tests/sandbox_sync/commands/test_run.py+++ /dev/null@@ -1,41 +0,0 @@-import pytest--from e2b import Sandbox---def test_run(sandbox: Sandbox):- text = "Hello, World!"-- cmd = sandbox.commands.run(f'echo "{text}"')-- assert cmd.exit_code == 0- assert cmd.stdout == f"{text}\n"---def test_run_with_special_characters(sandbox: Sandbox):- text = "!@#$%^&*()_+"-- cmd = sandbox.commands.run(f'echo "{text}"')-- assert cmd.exit_code == 0- assert cmd.stdout == f"{text}\n"---def test_run_with_multiline_string(sandbox):- text = "Hello,\nWorld!"-- cmd = sandbox.commands.run(f'echo "{text}"')-- assert cmd.exit_code == 0- assert cmd.stdout == f"{text}\n"---def test_run_with_timeout(sandbox):- cmd = sandbox.commands.run('echo "Hello, World!"', timeout=1000)-- assert cmd.exit_code == 0---def test_run_with_too_short_timeout(sandbox):- with pytest.raises(Exception):- sandbox.commands.run("sleep 10", timeout_ms=1000)diff --git a/packages/python-sdk/tests/sandbox_sync/commands/test_send_stdin.py b/packages/python-sdk/tests/sandbox_sync/commands/test_send_stdin.pydeleted file mode 100644index 640cdf340..000000000--- a/packages/python-sdk/tests/sandbox_sync/commands/test_send_stdin.py+++ /dev/null@@ -1,28 +0,0 @@-from e2b import Sandbox---def test_send_stdin_to_process(sandbox: Sandbox):- cmd = sandbox.commands.run("cat", background=True)- sandbox.commands.send_stdin(cmd.pid, "Hello, World!")-- for stdout, _ in cmd:- assert stdout == "Hello, World!"- break---def test_send_special_characters_to_process(sandbox: Sandbox):- cmd = sandbox.commands.run("cat", background=True)- sandbox.commands.send_stdin(cmd.pid, "!@#$%^&*()_+")-- for stdout, _ in cmd:- assert stdout == "!@#$%^&*()_+"- break---def test_send_multiline_string_to_process(sandbox: Sandbox):- cmd = sandbox.commands.run("cat", background=True)- sandbox.commands.send_stdin(cmd.pid, "Hello,\nWorld!")-- for stdout, _ in cmd:- assert stdout == "Hello,\nWorld!"- breakdiff --git a/packages/python-sdk/tests/sandbox_sync/files/test_files_list.py b/packages/python-sdk/tests/sandbox_sync/files/test_files_list.pydeleted file mode 100644index e69de29bb..000000000diff --git a/packages/python-sdk/tests/sandbox_sync/files/test_make_dir.py b/packages/python-sdk/tests/sandbox_sync/files/test_make_dir.pydeleted file mode 100644index ce37cbed4..000000000--- a/packages/python-sdk/tests/sandbox_sync/files/test_make_dir.py+++ /dev/null@@ -1,14 +0,0 @@-def test_make_directory(sandbox):- dir_name = "test_directory"-- sandbox.files.make_dir(dir_name)- exists = sandbox.files.exists(dir_name)- assert exists---def test_make_nested_directory(sandbox):- nested_dir_name = "test_directory/nested_directory"-- sandbox.files.make_dir(nested_dir_name)- exists = sandbox.files.exists(nested_dir_name)- assert existsdiff --git a/packages/python-sdk/tests/sandbox_sync/files/test_read.py b/packages/python-sdk/tests/sandbox_sync/files/test_read.pydeleted file mode 100644index e010ecbf0..000000000--- a/packages/python-sdk/tests/sandbox_sync/files/test_read.py+++ /dev/null@@ -1,18 +0,0 @@-import pytest-from e2b import NotFoundException---def test_read_file(sandbox):- filename = "test_read.txt"- content = "Hello, world!"-- sandbox.files.write(filename, content)- read_content = sandbox.files.read(filename)- assert read_content == content---def test_read_non_existing_file(sandbox):- filename = "non_existing_file.txt"-- with pytest.raises(NotFoundException):- sandbox.files.read(filename)diff --git a/packages/python-sdk/tests/sandbox_sync/files/test_remove.py b/packages/python-sdk/tests/sandbox_sync/files/test_remove.pydeleted file mode 100644index 6e65a6d16..000000000--- a/packages/python-sdk/tests/sandbox_sync/files/test_remove.py+++ /dev/null@@ -1,13 +0,0 @@-def test_remove_file(sandbox):- filename = "test_remove.txt"- content = "This file will be removed."-- sandbox.files.write(filename, content)- sandbox.files.remove(filename)- exists = sandbox.files.exists(filename)- assert not exists---def test_remove_non_existing_file(sandbox):- filename = "non_existing_file.txt"- sandbox.files.remove(filename)diff --git a/packages/python-sdk/tests/sandbox_sync/files/test_rename.py b/packages/python-sdk/tests/sandbox_sync/files/test_rename.pydeleted file mode 100644index 1267a6842..000000000--- a/packages/python-sdk/tests/sandbox_sync/files/test_rename.py+++ /dev/null@@ -1,25 +0,0 @@-import pytest-from e2b import NotFoundException---def test_rename_file(sandbox):- old_filename = "test_rename_old.txt"- new_filename = "test_rename_new.txt"- content = "This file will be renamed."-- sandbox.files.write(old_filename, content)- sandbox.files.rename(old_filename, new_filename)- exists_old = sandbox.files.exists(old_filename)- exists_new = sandbox.files.exists(new_filename)- assert not exists_old- assert exists_new- read_content = sandbox.files.read(new_filename)- assert read_content == content---def test_rename_non_existing_file(sandbox):- old_filename = "non_existing_file.txt"- new_filename = "new_non_existing_file.txt"-- with pytest.raises(NotFoundException):- sandbox.files.rename(old_filename, new_filename)diff --git a/packages/python-sdk/tests/sandbox_sync/files/test_watch.py b/packages/python-sdk/tests/sandbox_sync/files/test_watch.pydeleted file mode 100644index b459fb42d..000000000--- a/packages/python-sdk/tests/sandbox_sync/files/test_watch.py+++ /dev/null@@ -1,40 +0,0 @@-from time import sleep--import pytest--from e2b import NotFoundException-from e2b.sandbox.filesystem.watch_handle import FilesystemEventType---def test_watch_directory_changes(sandbox):- dirname = "test_watch_dir"- filename = "test_watch.txt"- content = "This file will be watched."- new_content = "This file has been modified."-- sandbox.files.make_dir(dirname)- sandbox.files.write(f"{dirname}/{filename}", content)-- event_triggered = False- handle = sandbox.files.watch(dirname)-- sandbox.files.write(f"{dirname}/{filename}", new_content)-- sleep(1) # wait for the event to be triggered-- for event in handle:- if event.type == FilesystemEventType.WRITE and event.name == filename:- event_triggered = True-- assert event_triggered-- handle.close()---def test_watch_non_existing_directory(sandbox):- dirname = "non_existing_watch_dir"-- with pytest.raises(NotFoundException):- sandbox.files.watch(dirname)--# TODO: Add test for nonexistent filediff --git a/packages/python-sdk/tests/sandbox_sync/files/test_write.py b/packages/python-sdk/tests/sandbox_sync/files/test_write.pydeleted file mode 100644index 0aebddcc1..000000000--- a/packages/python-sdk/tests/sandbox_sync/files/test_write.py+++ /dev/null@@ -1,33 +0,0 @@-def test_write_file(sandbox):- filename = "test_write.txt"- content = "This is a test file."-- sandbox.files.write(filename, content)- exists = sandbox.files.exists(filename)- assert exists-- read_content = sandbox.files.read(filename)- assert read_content == content---def test_overwrite_file(sandbox):- filename = "test_overwrite.txt"- initial_content = "Initial content."- new_content = "New content."-- sandbox.files.write(filename, initial_content)- sandbox.files.write(filename, new_content)- read_content = sandbox.files.read(filename)- assert read_content == new_content---def test_write_to_non_existing_directory(sandbox):- filename = "non_existing_dir/test_write.txt"- content = "This should succeed too."-- sandbox.files.write(filename, content)- exists = sandbox.files.exists(filename)- assert exists-- read_content = sandbox.files.read(filename)- assert read_content == contentdiff --git a/packages/python-sdk/tests/api/test_sbx_kill.py b/packages/python-sdk/tests/sync/api_sync/test_sbx_kill.pysimilarity index 100%rename from packages/python-sdk/tests/api/test_sbx_kill.pyrename to packages/python-sdk/tests/sync/api_sync/test_sbx_kill.pydiff --git a/packages/python-sdk/tests/api/test_sbx_list.py b/packages/python-sdk/tests/sync/api_sync/test_sbx_list.pysimilarity index 100%rename from packages/python-sdk/tests/api/test_sbx_list.pyrename to packages/python-sdk/tests/sync/api_sync/test_sbx_list.pydiff --git a/packages/python-sdk/tests/sandbox_async/commands/test_cmd_connect.py b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_cmd_connect.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/commands/test_cmd_connect.pyrename to packages/python-sdk/tests/sync/sandbox_sync/commands/test_cmd_connect.pydiff --git a/packages/python-sdk/tests/sandbox_async/commands/test_cmd_kill.py b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_cmd_kill.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/commands/test_cmd_kill.pyrename to packages/python-sdk/tests/sync/sandbox_sync/commands/test_cmd_kill.pydiff --git a/packages/python-sdk/tests/sandbox_async/commands/test_cmd_list.py b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_cmd_list.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/commands/test_cmd_list.pyrename to packages/python-sdk/tests/sync/sandbox_sync/commands/test_cmd_list.pydiff --git a/packages/python-sdk/tests/sandbox_async/commands/test_run.py b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_run.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/commands/test_run.pyrename to packages/python-sdk/tests/sync/sandbox_sync/commands/test_run.pydiff --git a/packages/python-sdk/tests/sandbox_async/commands/test_send_stdin.py b/packages/python-sdk/tests/sync/sandbox_sync/commands/test_send_stdin.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/commands/test_send_stdin.pyrename to packages/python-sdk/tests/sync/sandbox_sync/commands/test_send_stdin.pydiff --git a/packages/python-sdk/tests/sandbox_sync/files/test_exists.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_exists.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/files/test_exists.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_exists.pydiff --git a/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.pynew file mode 100644index 000000000..5c701b6b8--- /dev/null+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_list_dir.py@@ -0,0 +1,15 @@+from e2b import Sandbox, FileType+++def test_list_directory(sandbox: Sandbox):+ dir_name = "test_directory"++ sandbox.files.make_dir(dir_name)+ files = sandbox.files.list(dir_name)+ assert len(files) == 0++ sandbox.files.write(f"{dir_name}/test_file", "test")+ files1 = sandbox.files.list(dir_name)+ assert len(files1) == 1+ assert files1[0].name == "test_file"+ assert files1[0].type == FileType.FILEdiff --git a/packages/python-sdk/tests/sandbox_async/files/test_make_dir.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_make_dir.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/files/test_make_dir.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_make_dir.pydiff --git a/packages/python-sdk/tests/sandbox_async/files/test_read.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_read.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/files/test_read.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_read.pydiff --git a/packages/python-sdk/tests/sandbox_async/files/test_remove.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_remove.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/files/test_remove.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_remove.pydiff --git a/packages/python-sdk/tests/sandbox_async/files/test_rename.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_rename.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/files/test_rename.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_rename.pydiff --git a/packages/python-sdk/tests/sandbox_async/files/test_watch.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.pysimilarity index 69%rename from packages/python-sdk/tests/sandbox_async/files/test_watch.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.pyindex b459fb42d..2219ee3d7 100644--- a/packages/python-sdk/tests/sandbox_async/files/test_watch.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/files/test_watch.py@@ -1,12 +1,9 @@-from time import sleep-import pytest-from e2b import NotFoundException-from e2b.sandbox.filesystem.watch_handle import FilesystemEventType+from e2b import NotFoundException, FilesystemEventType, Sandbox-def test_watch_directory_changes(sandbox):+def test_watch_directory_changes(sandbox: Sandbox):dirname = "test_watch_dir"filename = "test_watch.txt"content = "This file will be watched."@@ -15,18 +12,13 @@ def test_watch_directory_changes(sandbox):sandbox.files.make_dir(dirname)sandbox.files.write(f"{dirname}/{filename}", content)- event_triggered = Falsehandle = sandbox.files.watch(dirname)sandbox.files.write(f"{dirname}/{filename}", new_content)- sleep(1) # wait for the event to be triggered-for event in handle:if event.type == FilesystemEventType.WRITE and event.name == filename:- event_triggered = True-- assert event_triggered+ breakhandle.close()@@ -37,4 +29,5 @@ def test_watch_non_existing_directory(sandbox):with pytest.raises(NotFoundException):sandbox.files.watch(dirname)+# TODO: Add test for nonexistent filediff --git a/packages/python-sdk/tests/sandbox_async/files/test_write.py b/packages/python-sdk/tests/sync/sandbox_sync/files/test_write.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_async/files/test_write.pyrename to packages/python-sdk/tests/sync/sandbox_sync/files/test_write.pydiff --git a/packages/python-sdk/tests/sandbox_sync/pty/test_pty_create.py b/packages/python-sdk/tests/sync/sandbox_sync/pty/test_pty_create.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/pty/test_pty_create.pyrename to packages/python-sdk/tests/sync/sandbox_sync/pty/test_pty_create.pydiff --git a/packages/python-sdk/tests/sandbox_sync/pty/test_resize.py b/packages/python-sdk/tests/sync/sandbox_sync/pty/test_resize.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/pty/test_resize.pyrename to packages/python-sdk/tests/sync/sandbox_sync/pty/test_resize.pydiff --git a/packages/python-sdk/tests/sandbox_sync/pty/test_stream_input.py b/packages/python-sdk/tests/sync/sandbox_sync/pty/test_stream_input.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/pty/test_stream_input.pyrename to packages/python-sdk/tests/sync/sandbox_sync/pty/test_stream_input.pydiff --git a/packages/python-sdk/tests/sandbox_sync/test_connect.py b/packages/python-sdk/tests/sync/sandbox_sync/test_connect.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/test_connect.pyrename to packages/python-sdk/tests/sync/sandbox_sync/test_connect.pydiff --git a/packages/python-sdk/tests/sandbox_sync/test_create.py b/packages/python-sdk/tests/sync/sandbox_sync/test_create.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/test_create.pyrename to packages/python-sdk/tests/sync/sandbox_sync/test_create.pydiff --git a/packages/python-sdk/tests/sandbox_sync/test_host.py b/packages/python-sdk/tests/sync/sandbox_sync/test_host.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/test_host.pyrename to packages/python-sdk/tests/sync/sandbox_sync/test_host.pydiff --git a/packages/python-sdk/tests/sandbox_sync/test_kill.py b/packages/python-sdk/tests/sync/sandbox_sync/test_kill.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/test_kill.pyrename to packages/python-sdk/tests/sync/sandbox_sync/test_kill.pydiff --git a/packages/python-sdk/tests/sandbox_sync/test_timeout.py b/packages/python-sdk/tests/sync/sandbox_sync/test_timeout.pysimilarity index 92%rename from packages/python-sdk/tests/sandbox_sync/test_timeout.pyrename to packages/python-sdk/tests/sync/sandbox_sync/test_timeout.pyindex 2ca5e55c9..306f11334 100644--- a/packages/python-sdk/tests/sandbox_sync/test_timeout.py+++ b/packages/python-sdk/tests/sync/sandbox_sync/test_timeout.py@@ -3,8 +3,6 @@ from e2b.exceptions import TimeoutExceptionimport pytest-from e2b import NotFoundException-@pytest.mark.skip_debug()def test_shorten_timeout(sandbox):diff --git a/packages/python-sdk/tests/sandbox_sync/test_upload_url.py b/packages/python-sdk/tests/sync/sandbox_sync/test_upload_url.pysimilarity index 100%rename from packages/python-sdk/tests/sandbox_sync/test_upload_url.pyrename to packages/python-sdk/tests/sync/sandbox_sync/test_upload_url.py