scalebox-sdk 0.1.12__py3-none-any.whl → 0.1.13__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. scalebox/__init__.py +1 -1
  2. scalebox/test/aclient.py +72 -72
  3. scalebox/test/code_interpreter_centext.py +21 -21
  4. scalebox/test/code_interpreter_centext_sync.py +21 -21
  5. scalebox/test/code_interpreter_test.py +34 -34
  6. scalebox/test/code_interpreter_test_sync.py +34 -34
  7. scalebox/test/run_all_validation_tests.py +334 -334
  8. scalebox/test/test_basic.py +78 -78
  9. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
  10. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -2655
  11. scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -3416
  12. scalebox/test/test_code_interpreter_execcode.py +3352 -0
  13. scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
  14. scalebox/test/test_csx_desktop_examples.py +130 -0
  15. scalebox/test/test_e2b_first.py +11 -11
  16. scalebox/test/test_sandbox_async_comprehensive.py +736 -738
  17. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
  18. scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
  19. scalebox/test/test_sandbox_usage_examples.py +987 -987
  20. scalebox/test/testacreate.py +24 -24
  21. scalebox/test/testagetinfo.py +18 -18
  22. scalebox/test/testcodeinterpreter_async.py +508 -508
  23. scalebox/test/testcodeinterpreter_sync.py +239 -239
  24. scalebox/test/testcomputeuse.py +245 -243
  25. scalebox/test/testnovnc.py +12 -12
  26. scalebox/test/testsandbox_async.py +202 -118
  27. scalebox/test/testsandbox_sync.py +71 -38
  28. scalebox/version.py +2 -2
  29. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/METADATA +1 -1
  30. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/RECORD +34 -32
  31. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/WHEEL +0 -0
  32. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/entry_points.txt +0 -0
  33. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/licenses/LICENSE +0 -0
  34. {scalebox_sdk-0.1.12.dist-info → scalebox_sdk-0.1.13.dist-info}/top_level.txt +0 -0
scalebox/__init__.py CHANGED
@@ -9,7 +9,7 @@ A multi-language code execution sandbox with support for:
9
9
  - Real-time callbacks and monitoring
10
10
  """
11
11
 
12
- __version__ = "0.1.12"
12
+ __version__ = "0.1.13"
13
13
  __author__ = "ScaleBox Team"
14
14
  __email__ = "dev@scalebox.dev"
15
15
 
scalebox/test/aclient.py CHANGED
@@ -1,72 +1,72 @@
1
- # import sys, os
2
- # sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
3
- import asyncio
4
-
5
- import aiohttp
6
- from generated import api_pb2
7
- from generated.api_pb2_connect import AsyncFilesystemClient
8
- from tenacity import (
9
- retry,
10
- retry_if_exception_type,
11
- stop_after_attempt,
12
- wait_exponential,
13
- )
14
-
15
-
16
- @retry(
17
- stop=stop_after_attempt(5), # 最大重试5次
18
- wait=wait_exponential(multiplier=1, min=4, max=10), # 指数退避等待
19
- retry=retry_if_exception_type(
20
- (aiohttp.ClientError, asyncio.TimeoutError)
21
- ), # 针对这些异常重试
22
- )
23
- async def watch_directory_example():
24
- # 创建 aiohttp 客户端会话
25
- async with aiohttp.ClientSession(
26
- timeout=aiohttp.ClientTimeout(total=None)
27
- ) as session:
28
- # 创建文件系统客户端
29
- client = AsyncFilesystemClient(
30
- base_url="http://localhost:8080",
31
- http_client=session,
32
- # protocol=ConnectProtocol.CONNECT_PROTOBUF # 如果需要指定协议
33
- )
34
- # extra = {"authorization": "Bearer root"}
35
- # 创建监视请求
36
- request = api_pb2.WatchDirRequest(path="/root")
37
-
38
- # 可选:添加额外的请求头
39
- extra_headers = {
40
- "Authorization": "Bearer root",
41
- "X-Custom-Header": "custom-value",
42
- }
43
-
44
- try:
45
- # 使用 async for 循环处理流式响应
46
- async for response in client.watch_dir(
47
- request, extra_headers=extra_headers
48
- ):
49
- print(f"Received event: {response}")
50
- # 在这里处理每个事件
51
- # 例如,根据事件类型执行不同的操作
52
-
53
- # 如果收到特定事件,可以中断循环
54
- # if response.event_type == api_pb2.WatchDirResponse.EVENT_TYPE_STOP:
55
- # break
56
-
57
- except Exception as e:
58
- print(f"Error during directory watching: {e}")
59
-
60
- finally:
61
- # 关闭会话(在 with 语句中会自动关闭,但这里为了清晰展示)
62
- await session.close()
63
-
64
-
65
- async def main():
66
- # 运行监视示例
67
- await watch_directory_example()
68
-
69
-
70
- if __name__ == "__main__":
71
- # 运行异步主函数
72
- asyncio.run(main())
1
+ # import sys, os
2
+ # sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'generated'))
3
+ import asyncio
4
+
5
+ import aiohttp
6
+ from generated import api_pb2
7
+ from generated.api_pb2_connect import AsyncFilesystemClient
8
+ from tenacity import (
9
+ retry,
10
+ retry_if_exception_type,
11
+ stop_after_attempt,
12
+ wait_exponential,
13
+ )
14
+
15
+
16
+ @retry(
17
+ stop=stop_after_attempt(5), # 最大重试5次
18
+ wait=wait_exponential(multiplier=1, min=4, max=10), # 指数退避等待
19
+ retry=retry_if_exception_type(
20
+ (aiohttp.ClientError, asyncio.TimeoutError)
21
+ ), # 针对这些异常重试
22
+ )
23
+ async def watch_directory_example():
24
+ # 创建 aiohttp 客户端会话
25
+ async with aiohttp.ClientSession(
26
+ timeout=aiohttp.ClientTimeout(total=None)
27
+ ) as session:
28
+ # 创建文件系统客户端
29
+ client = AsyncFilesystemClient(
30
+ base_url="http://localhost:8080",
31
+ http_client=session,
32
+ # protocol=ConnectProtocol.CONNECT_PROTOBUF # 如果需要指定协议
33
+ )
34
+ # extra = {"authorization": "Bearer root"}
35
+ # 创建监视请求
36
+ request = api_pb2.WatchDirRequest(path="/root")
37
+
38
+ # 可选:添加额外的请求头
39
+ extra_headers = {
40
+ "Authorization": "Bearer root",
41
+ "X-Custom-Header": "custom-value",
42
+ }
43
+
44
+ try:
45
+ # 使用 async for 循环处理流式响应
46
+ async for response in client.watch_dir(
47
+ request, extra_headers=extra_headers
48
+ ):
49
+ print(f"Received event: {response}")
50
+ # 在这里处理每个事件
51
+ # 例如,根据事件类型执行不同的操作
52
+
53
+ # 如果收到特定事件,可以中断循环
54
+ # if response.event_type == api_pb2.WatchDirResponse.EVENT_TYPE_STOP:
55
+ # break
56
+
57
+ except Exception as e:
58
+ print(f"Error during directory watching: {e}")
59
+
60
+ finally:
61
+ # 关闭会话(在 with 语句中会自动关闭,但这里为了清晰展示)
62
+ await session.close()
63
+
64
+
65
+ async def main():
66
+ # 运行监视示例
67
+ await watch_directory_example()
68
+
69
+
70
+ if __name__ == "__main__":
71
+ # 运行异步主函数
72
+ asyncio.run(main())
@@ -1,21 +1,21 @@
1
- import asyncio
2
- import time
3
-
4
- from scalebox.code_interpreter import AsyncSandbox
5
-
6
- # from scalebox.sandbox_async.main import AsyncSandbox
7
-
8
-
9
- async def pty_output_handler(output):
10
- """处理 PTY 输出的回调函数"""
11
- print(f"输出: {output}")
12
-
13
-
14
- async def main():
15
- sandbox = AsyncSandbox()
16
- context = await sandbox.create_code_context(language="python3")
17
- print(context.__dict__)
18
-
19
-
20
- if __name__ == "__main__":
21
- asyncio.run(main())
1
+ import asyncio
2
+ import time
3
+
4
+ from scalebox.code_interpreter import AsyncSandbox
5
+
6
+ # from scalebox.sandbox_async.main import AsyncSandbox
7
+
8
+
9
+ async def pty_output_handler(output):
10
+ """处理 PTY 输出的回调函数"""
11
+ print(f"输出: {output}")
12
+
13
+
14
+ async def main():
15
+ sandbox = AsyncSandbox()
16
+ context = await sandbox.create_code_context(language="python3")
17
+ print(context.__dict__)
18
+
19
+
20
+ if __name__ == "__main__":
21
+ asyncio.run(main())
@@ -1,21 +1,21 @@
1
- import asyncio
2
- import time
3
-
4
- from scalebox.code_interpreter import Sandbox
5
-
6
- # from scalebox.sandbox_async.main import AsyncSandbox
7
-
8
-
9
- async def pty_output_handler(output):
10
- """处理 PTY 输出的回调函数"""
11
- print(f"输出: {output}")
12
-
13
-
14
- def main():
15
- sandbox = Sandbox()
16
- context = sandbox.create_code_context(language="python3")
17
- print(context.__dict__)
18
-
19
-
20
- if __name__ == "__main__":
21
- main()
1
+ import asyncio
2
+ import time
3
+
4
+ from scalebox.code_interpreter import Sandbox
5
+
6
+ # from scalebox.sandbox_async.main import AsyncSandbox
7
+
8
+
9
+ async def pty_output_handler(output):
10
+ """处理 PTY 输出的回调函数"""
11
+ print(f"输出: {output}")
12
+
13
+
14
+ def main():
15
+ sandbox = Sandbox()
16
+ context = sandbox.create_code_context(language="python3")
17
+ print(context.__dict__)
18
+
19
+
20
+ if __name__ == "__main__":
21
+ main()
@@ -1,34 +1,34 @@
1
- import asyncio
2
- import time
3
-
4
- from scalebox.code_interpreter import AsyncSandbox
5
-
6
- # from scalebox.sandbox_async.main import AsyncSandbox
7
-
8
-
9
- async def pty_output_handler(output):
10
- """处理 PTY 输出的回调函数"""
11
- print(f"输出: {output}")
12
-
13
-
14
- async def main():
15
- sandbox = AsyncSandbox.create()
16
- proc = await sandbox.run_code(
17
- """
18
- import time
19
- for i in range(3):
20
- print("Hello E2B", i)
21
- time.sleep(50)
22
- """,
23
- language="python3",
24
- request_timeout=3600,
25
- on_stdout=pty_output_handler,
26
- on_stderr=pty_output_handler,
27
- on_result=pty_output_handler,
28
- )
29
- print(proc)
30
- time.sleep(10)
31
-
32
-
33
- if __name__ == "__main__":
34
- asyncio.run(main())
1
+ import asyncio
2
+ import time
3
+
4
+ from scalebox.code_interpreter import AsyncSandbox
5
+
6
+ # from scalebox.sandbox_async.main import AsyncSandbox
7
+
8
+
9
+ async def pty_output_handler(output):
10
+ """处理 PTY 输出的回调函数"""
11
+ print(f"输出: {output}")
12
+
13
+
14
+ async def main():
15
+ sandbox = AsyncSandbox.create()
16
+ proc = await sandbox.run_code(
17
+ """
18
+ import time
19
+ for i in range(3):
20
+ print("Hello E2B", i)
21
+ time.sleep(50)
22
+ """,
23
+ language="python3",
24
+ request_timeout=3600,
25
+ on_stdout=pty_output_handler,
26
+ on_stderr=pty_output_handler,
27
+ on_result=pty_output_handler,
28
+ )
29
+ print(proc)
30
+ time.sleep(10)
31
+
32
+
33
+ if __name__ == "__main__":
34
+ asyncio.run(main())
@@ -1,34 +1,34 @@
1
- import asyncio
2
- import time
3
-
4
- from code_interpreter import Sandbox
5
-
6
- # from scalebox.sandbox_async.main import AsyncSandbox
7
-
8
-
9
- def pty_output_handler(output):
10
- """处理 PTY 输出的回调函数"""
11
- print(f"输出: {output}")
12
-
13
-
14
- def main():
15
- sandbox = Sandbox()
16
- proc = sandbox.run_code(
17
- """
18
- import time
19
- for i in range(3):
20
- print("Hello E2B", i)
21
- time.sleep(50)
22
- """,
23
- language="python3",
24
- request_timeout=3600,
25
- on_stdout=pty_output_handler,
26
- on_stderr=pty_output_handler,
27
- on_result=pty_output_handler,
28
- )
29
- print(proc)
30
- time.sleep(10)
31
-
32
-
33
- if __name__ == "__main__":
34
- main()
1
+ import asyncio
2
+ import time
3
+
4
+ from code_interpreter import Sandbox
5
+
6
+ # from scalebox.sandbox_async.main import AsyncSandbox
7
+
8
+
9
+ def pty_output_handler(output):
10
+ """处理 PTY 输出的回调函数"""
11
+ print(f"输出: {output}")
12
+
13
+
14
+ def main():
15
+ sandbox = Sandbox()
16
+ proc = sandbox.run_code(
17
+ """
18
+ import time
19
+ for i in range(3):
20
+ print("Hello E2B", i)
21
+ time.sleep(50)
22
+ """,
23
+ language="python3",
24
+ request_timeout=3600,
25
+ on_stdout=pty_output_handler,
26
+ on_stderr=pty_output_handler,
27
+ on_result=pty_output_handler,
28
+ )
29
+ print(proc)
30
+ time.sleep(10)
31
+
32
+
33
+ if __name__ == "__main__":
34
+ main()