scalebox-sdk 0.1.4__py3-none-any.whl → 0.1.25__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 (68) hide show
  1. scalebox/__init__.py +1 -1
  2. scalebox/api/__init__.py +128 -128
  3. scalebox/api/client/__init__.py +8 -8
  4. scalebox/api/client/api/sandboxes/get_sandboxes.py +5 -3
  5. scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +2 -2
  6. scalebox/api/client/api/sandboxes/post_sandboxes.py +2 -2
  7. scalebox/api/client/client.py +288 -288
  8. scalebox/api/client/models/listed_sandbox.py +11 -9
  9. scalebox/api/client/models/new_sandbox.py +1 -1
  10. scalebox/api/client/models/sandbox.py +125 -125
  11. scalebox/api/client/models/sandbox_state.py +1 -0
  12. scalebox/api/client/types.py +46 -46
  13. scalebox/code_interpreter/code_interpreter_async.py +370 -369
  14. scalebox/code_interpreter/code_interpreter_sync.py +318 -317
  15. scalebox/connection_config.py +92 -92
  16. scalebox/csx_desktop/main.py +12 -12
  17. scalebox/generated/api_pb2_connect.py +17 -66
  18. scalebox/sandbox_async/commands/command.py +307 -307
  19. scalebox/sandbox_async/commands/command_handle.py +187 -187
  20. scalebox/sandbox_async/commands/pty.py +187 -187
  21. scalebox/sandbox_async/filesystem/filesystem.py +557 -557
  22. scalebox/sandbox_async/filesystem/watch_handle.py +61 -61
  23. scalebox/sandbox_async/main.py +647 -646
  24. scalebox/sandbox_async/sandbox_api.py +365 -365
  25. scalebox/sandbox_async/utils.py +7 -7
  26. scalebox/sandbox_sync/__init__.py +2 -2
  27. scalebox/sandbox_sync/commands/command.py +300 -300
  28. scalebox/sandbox_sync/commands/command_handle.py +150 -150
  29. scalebox/sandbox_sync/commands/pty.py +181 -181
  30. scalebox/sandbox_sync/filesystem/filesystem.py +543 -543
  31. scalebox/sandbox_sync/filesystem/watch_handle.py +66 -66
  32. scalebox/sandbox_sync/main.py +789 -790
  33. scalebox/sandbox_sync/sandbox_api.py +356 -356
  34. scalebox/test/CODE_INTERPRETER_TESTS_READY.md +256 -256
  35. scalebox/test/README.md +164 -164
  36. scalebox/test/aclient.py +72 -72
  37. scalebox/test/code_interpreter_centext.py +21 -21
  38. scalebox/test/code_interpreter_centext_sync.py +21 -21
  39. scalebox/test/code_interpreter_test.py +1 -1
  40. scalebox/test/code_interpreter_test_sync.py +1 -1
  41. scalebox/test/run_all_validation_tests.py +334 -334
  42. scalebox/test/test_basic.py +78 -78
  43. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
  44. scalebox/test/{test_code_interpreter_e2bsync_comprehensive.py → test_code_interpreter_execcode.py} +328 -392
  45. scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
  46. scalebox/test/test_csx_desktop_examples.py +130 -0
  47. scalebox/test/test_sandbox_async_comprehensive.py +736 -738
  48. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
  49. scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
  50. scalebox/test/test_sandbox_usage_examples.py +987 -987
  51. scalebox/test/testacreate.py +24 -24
  52. scalebox/test/testagetinfo.py +18 -18
  53. scalebox/test/testcodeinterpreter_async.py +508 -508
  54. scalebox/test/testcodeinterpreter_sync.py +239 -239
  55. scalebox/test/testcomputeuse.py +2 -2
  56. scalebox/test/testnovnc.py +12 -12
  57. scalebox/test/testsandbox_api.py +15 -0
  58. scalebox/test/testsandbox_async.py +202 -118
  59. scalebox/test/testsandbox_sync.py +71 -38
  60. scalebox/version.py +2 -2
  61. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/METADATA +104 -103
  62. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/RECORD +66 -66
  63. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +0 -2655
  64. scalebox/test/test_e2b_first.py +0 -11
  65. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/WHEEL +0 -0
  66. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/entry_points.txt +0 -0
  67. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/licenses/LICENSE +0 -0
  68. {scalebox_sdk-0.1.4.dist-info → scalebox_sdk-0.1.25.dist-info}/top_level.txt +0 -0
@@ -1,118 +1,202 @@
1
- import asyncio
2
-
3
- from sandbox_async.main import AsyncSandbox
4
-
5
- from scalebox.sandbox.commands.command_handle import PtySize
6
-
7
- # from scalebox.sandbox_async.main import AsyncSandbox
8
-
9
-
10
- async def pty_output_handler(output):
11
- """处理 PTY 输出的回调函数"""
12
- print(f"PTY 输出: {output}")
13
-
14
-
15
- async def main():
16
- sandbox = AsyncSandbox()
17
- proc = await sandbox.commands.run("echo hello from async")
18
- print("exit_code =", proc.exit_code)
19
- print("stdout =", proc.stdout)
20
- # 4. 创建 PTY
21
- pty_size = PtySize(rows=24, cols=80)
22
- pty_handle = await sandbox.pty.create(
23
- size=pty_size,
24
- on_data=pty_output_handler,
25
- cwd="/root",
26
- envs={"CUSTOM_ENV": "value"},
27
- timeout=120,
28
- request_timeout=30,
29
- )
30
- print(f"PTY 已创建,PID: {pty_handle.pid}")
31
-
32
- # 5. 向 PTY 发送输入
33
- await sandbox.pty.send_stdin(
34
- pid=pty_handle.pid, data=b"echo 'Hello from PTY'\n", request_timeout=10
35
- )
36
- await asyncio.sleep(2)
37
-
38
- # 6. 调整 PTY 大小
39
- new_size = PtySize(rows=30, cols=100)
40
- await sandbox.pty.resize(pid=pty_handle.pid, size=new_size, request_timeout=10)
41
- print("PTY 大小已调整")
42
- killed = await sandbox.pty.kill(pty_handle.pid)
43
- print(f"PTY 是否被杀死: {killed}")
44
-
45
-
46
- # 静态方法使用示例
47
- async def static_methods_example():
48
- # 1. 创建沙箱
49
- sandbox = await AsyncSandbox.create()
50
- sandbox_id = sandbox.sandbox_id
51
-
52
- try:
53
- # 2. 使用静态方法获取沙箱信息
54
- info = await AsyncSandbox.get_info(sandbox_id)
55
- print(f"静态方法获取的沙箱信息: {info}")
56
-
57
- # 3. 使用静态方法设置超时
58
- await AsyncSandbox.set_timeout(sandbox_id, 1800) # 30分钟
59
-
60
- # 4. 使用静态方法获取指标
61
- try:
62
- metrics = await AsyncSandbox.get_metrics(sandbox_id)
63
- print(f"静态方法获取的指标: {metrics}")
64
- except Exception as e:
65
- print(f"静态方法获取指标失败: {e}")
66
-
67
- finally:
68
- # 5. 使用静态方法关闭沙箱
69
- killed = await AsyncSandbox.kill(sandbox_id)
70
- print(f"静态方法关闭沙箱结果: {killed}")
71
-
72
-
73
- # 连接现有沙箱示例
74
- async def connect_example():
75
- # 1. 创建沙箱并获取ID
76
- sandbox = await AsyncSandbox.create()
77
- sandbox_id = sandbox.sandbox_id
78
- await sandbox.kill() # 先关闭
79
-
80
- # 2. 连接到现有沙箱
81
- try:
82
- connected_sandbox = await AsyncSandbox.connect(sandbox_id)
83
- print(f"成功连接到沙箱: {connected_sandbox.sandbox_id}")
84
-
85
- # 使用连接的沙箱
86
- is_running = await connected_sandbox.is_running()
87
- print(f"连接后沙箱状态: {is_running}")
88
-
89
- await connected_sandbox.kill()
90
- except Exception as e:
91
- print(f"连接沙箱失败: {e}")
92
-
93
-
94
- # 上下文管理器使用示例
95
- async def context_manager_example():
96
- sandbox = AsyncSandbox()
97
- # async with AsyncSandbox() as sandbox:
98
- # # 在上下文中使用沙箱
99
- # is_running = await sandbox.is_running()
100
- # print(f"上下文管理器中的沙箱状态: {is_running}")
101
-
102
- # 创建和使用 PTY
103
- pty_handle = await sandbox.pty.create(
104
- size=PtySize(rows=24, cols=80), on_data=pty_output_handler
105
- )
106
-
107
- # 发送命令
108
- await sandbox.pty.send_stdin(pty_handle.pid, b"ls -la\n")
109
-
110
- # 等待一段时间
111
- await asyncio.sleep(10)
112
-
113
-
114
- if __name__ == "__main__":
115
- # asyncio.run(main())0
116
- # asyncio.run(static_methods_example())
117
- # asyncio.run(connect_example())
118
- asyncio.run(context_manager_example())
1
+ import asyncio
2
+
3
+ from sandbox_async.main import AsyncSandbox
4
+
5
+ from scalebox.sandbox.commands.command_handle import PtySize
6
+
7
+ # from scalebox.sandbox_async.main import AsyncSandbox
8
+
9
+
10
+ async def pty_output_handler(output):
11
+ """处理 PTY 输出的回调函数"""
12
+ print(f"PTY 输出: {output}")
13
+
14
+
15
+ async def main():
16
+ sandbox = await (AsyncSandbox.create(timeout=3600))
17
+ proc = await sandbox.commands.run("echo hello from async")
18
+ print("exit_code =", proc.exit_code)
19
+ print("stdout =", proc.stdout)
20
+ # 4. 创建 PTY
21
+ pty_size = PtySize(rows=24, cols=80)
22
+ pty_handle = await sandbox.pty.create(
23
+ size=pty_size,
24
+ on_data=pty_output_handler,
25
+ cwd="/root",
26
+ envs={"CUSTOM_ENV": "value"},
27
+ request_timeout=40
28
+ )
29
+ print(f"PTY 已创建,PID: {pty_handle.pid}")
30
+
31
+ # 5. 向 PTY 发送输入
32
+ await sandbox.pty.send_stdin(
33
+ pid=pty_handle.pid,
34
+ data=b"echo 'Hello from PTY 0s'\n",
35
+ request_timeout=10
36
+ )
37
+ await asyncio.sleep(30)
38
+ await sandbox.pty.send_stdin(
39
+ pid=pty_handle.pid,
40
+ data=b"echo 'Hello from PTY 30s'\n",
41
+ request_timeout=10
42
+ )
43
+ await asyncio.sleep(30)
44
+ await sandbox.pty.send_stdin(
45
+ pid=pty_handle.pid,
46
+ data=b"echo 'Hello from PTY 60s'\n",
47
+ request_timeout=10
48
+ )
49
+ await asyncio.sleep(30)
50
+ await sandbox.pty.send_stdin(
51
+ pid=pty_handle.pid,
52
+ data=b"echo 'Hello from PTY 90s'\n",
53
+ request_timeout=10
54
+ )
55
+ await asyncio.sleep(30)
56
+ await sandbox.pty.send_stdin(
57
+ pid=pty_handle.pid,
58
+ data=b"echo 'Hello from PTY 120s'\n",
59
+ request_timeout=10
60
+ )
61
+ await asyncio.sleep(30)
62
+ await sandbox.pty.send_stdin(
63
+ pid=pty_handle.pid,
64
+ data=b"echo 'Hello from PTY 150s'\n",
65
+ request_timeout=10
66
+ )
67
+ await asyncio.sleep(30)
68
+ await sandbox.pty.send_stdin(
69
+ pid=pty_handle.pid,
70
+ data=b"echo 'Hello from PTY 180s'\n",
71
+ request_timeout=10
72
+ )
73
+ await asyncio.sleep(30)
74
+ await sandbox.pty.send_stdin(
75
+ pid=pty_handle.pid,
76
+ data=b"echo 'Hello from PTY 210s'\n",
77
+ request_timeout=10
78
+ )
79
+ await asyncio.sleep(30)
80
+ await sandbox.pty.send_stdin(
81
+ pid=pty_handle.pid,
82
+ data=b"echo 'Hello from PTY 240s'\n",
83
+ request_timeout=10
84
+ )
85
+ await asyncio.sleep(30)
86
+ await sandbox.pty.send_stdin(
87
+ pid=pty_handle.pid,
88
+ data=b"echo 'Hello from PTY 270s'\n",
89
+ request_timeout=10
90
+ )
91
+ await asyncio.sleep(30)
92
+ await sandbox.pty.send_stdin(
93
+ pid=pty_handle.pid,
94
+ data=b"echo 'Hello from PTY 300s'\n",
95
+ request_timeout=10
96
+ )
97
+ await asyncio.sleep(30)
98
+ await sandbox.pty.send_stdin(
99
+ pid=pty_handle.pid,
100
+ data=b"echo 'Hello from PTY 330s'\n",
101
+ request_timeout=10
102
+ )
103
+ await asyncio.sleep(30)
104
+ await sandbox.pty.send_stdin(
105
+ pid=pty_handle.pid,
106
+ data=b"echo 'Hello from PTY 360s'\n",
107
+ request_timeout=10
108
+ )
109
+ await asyncio.sleep(30)
110
+ await sandbox.pty.send_stdin(
111
+ pid=pty_handle.pid,
112
+ data=b"echo 'Hello from PTY 390s'\n",
113
+ request_timeout=10
114
+ )
115
+ await asyncio.sleep(30)
116
+ await sandbox.pty.send_stdin(
117
+ pid=pty_handle.pid,
118
+ data=b"echo 'Hello from PTY 420s'\n",
119
+ request_timeout=10
120
+ )
121
+
122
+ # 6. 调整 PTY 大小
123
+ new_size = PtySize(rows=30, cols=100)
124
+ await sandbox.pty.resize(pid=pty_handle.pid, size=new_size, request_timeout=10)
125
+ print("PTY 大小已调整")
126
+ killed = await sandbox.pty.kill(pty_handle.pid)
127
+ print(f"PTY 是否被杀死: {killed}")
128
+
129
+
130
+ # 静态方法使用示例
131
+ async def static_methods_example():
132
+ # 1. 创建沙箱
133
+ sandbox = await AsyncSandbox.create()
134
+ sandbox_id = sandbox.sandbox_id
135
+
136
+ try:
137
+ # 2. 使用静态方法获取沙箱信息
138
+ info = await AsyncSandbox.get_info(sandbox_id)
139
+ print(f"静态方法获取的沙箱信息: {info}")
140
+
141
+ # 3. 使用静态方法设置超时
142
+ await AsyncSandbox.set_timeout(sandbox_id, 1800) # 30分钟
143
+
144
+ # 4. 使用静态方法获取指标
145
+ try:
146
+ metrics = await AsyncSandbox.get_metrics(sandbox_id)
147
+ print(f"静态方法获取的指标: {metrics}")
148
+ except Exception as e:
149
+ print(f"静态方法获取指标失败: {e}")
150
+
151
+ finally:
152
+ # 5. 使用静态方法关闭沙箱
153
+ killed = await AsyncSandbox.kill(sandbox_id)
154
+ print(f"静态方法关闭沙箱结果: {killed}")
155
+
156
+
157
+ # 连接现有沙箱示例
158
+ async def connect_example():
159
+ # 1. 创建沙箱并获取ID
160
+ sandbox = await AsyncSandbox.create()
161
+ sandbox_id = sandbox.sandbox_id
162
+ await sandbox.kill() # 先关闭
163
+
164
+ # 2. 连接到现有沙箱
165
+ try:
166
+ connected_sandbox = await AsyncSandbox.connect(sandbox_id)
167
+ print(f"成功连接到沙箱: {connected_sandbox.sandbox_id}")
168
+
169
+ # 使用连接的沙箱
170
+ is_running = await connected_sandbox.is_running()
171
+ print(f"连接后沙箱状态: {is_running}")
172
+
173
+ await connected_sandbox.kill()
174
+ except Exception as e:
175
+ print(f"连接沙箱失败: {e}")
176
+
177
+
178
+ # 上下文管理器使用示例
179
+ async def context_manager_example():
180
+ sandbox = AsyncSandbox()
181
+ # async with AsyncSandbox() as sandbox:
182
+ # # 在上下文中使用沙箱
183
+ # is_running = await sandbox.is_running()
184
+ # print(f"上下文管理器中的沙箱状态: {is_running}")
185
+
186
+ # 创建和使用 PTY
187
+ pty_handle = await sandbox.pty.create(
188
+ size=PtySize(rows=24, cols=80), on_data=pty_output_handler
189
+ )
190
+
191
+ # 发送命令
192
+ await sandbox.pty.send_stdin(pty_handle.pid, b"ls -la\n")
193
+
194
+ # 等待一段时间
195
+ await asyncio.sleep(10)
196
+
197
+
198
+ if __name__ == "__main__":
199
+ asyncio.run(main())
200
+ # asyncio.run(static_methods_example())
201
+ # asyncio.run(connect_example())
202
+ # asyncio.run(context_manager_example())
@@ -1,38 +1,71 @@
1
- from scalebox.sandbox.commands.command_handle import PtySize
2
- from scalebox.sandbox_sync.main import Sandbox
3
-
4
-
5
- def output_handler(output):
6
- """处理 输出的回调函数"""
7
- print(f"PTY 输出: {output}")
8
-
9
-
10
- sandbox = Sandbox(api_key=f"sk-Wk4IgtUYOqnttxGaxZmELEV4p2FXh15Evt0FIcSa")
11
- # print(sandbox.files.list("/root",2))
12
- # proc = sandbox.commands._start(
13
- # cmd="python3 -c \"import math; print('π =', math.pi); exit(42)\"",
14
- # ).wait(on_pty=None,
15
- # on_stdout=lambda data: print("[STDOUT]", data, end=""),
16
- # on_stderr=lambda data: print("[STDERR]", data, end=""),)
17
-
18
- # proc = sandbox.commands._start(
19
- # cmd="ls /",
20
- # ).wait(on_pty=None,
21
- # on_stdout=lambda data: print("[STDOUT]", data, end=""),
22
- # on_stderr=lambda data: print("[STDERR]", data, end=""),)
23
- #
24
- # print("exit_code =", proc.exit_code) # 42
25
- # print("full_output =", proc.stdout) # π = 3.141592653589793
26
- # pty=sandbox.pty.create(size=PtySize(1024, 768),user="root",cwd="/root/",)
27
- # sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"hello\"")
28
- # sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\"")
29
- # result=pty.wait(
30
- # on_pty=lambda data: print("[STDOUT]", data, end=""),
31
- # )
32
- # print("exit_code =", result.exit_code)
33
- # print("full_output =", result.stdout)
34
- result = sandbox.commands.run(
35
- cmd="ls /", on_stdout=output_handler, on_stderr=output_handler
36
- )
37
- print(result.exit_code)
38
- print(result.error)
1
+ import time
2
+
3
+ from scalebox.sandbox.commands.command_handle import PtySize
4
+ from scalebox.sandbox_sync.main import Sandbox
5
+
6
+
7
+ def output_handler(output):
8
+ """处理 输出的回调函数"""
9
+ print(f"PTY 输出: {output}")
10
+ sandbox = Sandbox.create(api_key=f"sk-Wk4IgtUYOqnttxGaxZmELEV4p2FXh15Evt0FIcSa")
11
+ # print(sandbox.files.list("/root",2))
12
+ # proc = sandbox.commands._start(
13
+ # cmd="python3 -c \"import math; print('π =', math.pi); exit(42)\"",
14
+ # ).wait(on_pty=None,
15
+ # on_stdout=lambda data: print("[STDOUT]", data, end=""),
16
+ # on_stderr=lambda data: print("[STDERR]", data, end=""),)
17
+
18
+ # proc = sandbox.commands._start(
19
+ # cmd="ls /",
20
+ # ).wait(on_pty=None,
21
+ # on_stdout=lambda data: print("[STDOUT]", data, end=""),
22
+ # on_stderr=lambda data: print("[STDERR]", data, end=""),)
23
+ #
24
+ # print("exit_code =", proc.exit_code) # 42
25
+ # print("full_output =", proc.stdout) # π = 3.141592653589793
26
+ # pty=sandbox.pty.create(size=PtySize(1024, 768),user="root",cwd="/root/",)
27
+ # sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"hello\"")
28
+ # sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\"")
29
+ # result=pty.wait(
30
+ # on_pty=lambda data: print("[STDOUT]", data, end=""),
31
+ # )
32
+ # print("exit_code =", result.exit_code)
33
+ # print("full_output =", result.stdout)
34
+ result = sandbox.commands.run(
35
+ cmd="ls /", on_stdout=output_handler, on_stderr=output_handler
36
+ )
37
+ print(result.exit_code)
38
+ print(result.error)
39
+ pty=sandbox.pty.create(size=PtySize(1024, 768),user="root",cwd="/root/",request_timeout=3600)
40
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"hello\"")
41
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\"")
42
+ time.sleep(30)
43
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 30s")
44
+ time.sleep(30)
45
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 60s")
46
+ time.sleep(30)
47
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 90s")
48
+ time.sleep(30)
49
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 120s")
50
+ time.sleep(30)
51
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 150s")
52
+ time.sleep(30)
53
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 180s")
54
+ time.sleep(30)
55
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 210s")
56
+ time.sleep(30)
57
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 240s")
58
+ time.sleep(30)
59
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 270s")
60
+ time.sleep(30)
61
+ sandbox.pty.send_stdin(pid=pty.pid,data=b"echo \"world!\" 300s")
62
+ result=pty.wait(
63
+ on_pty=lambda data: print("[STDOUT]", data, end=""),
64
+ )
65
+ print("exit_code =", result.exit_code)
66
+ print("full_output =", result.stdout)
67
+ # result=sandbox.commands.run(cmd="ls /",
68
+ # on_stdout=output_handler,
69
+ # on_stderr=output_handler)
70
+ # print(result.exit_code)
71
+ # print(result.error)
scalebox/version.py CHANGED
@@ -2,8 +2,8 @@
2
2
  Version information for ScaleBox Python SDK
3
3
  """
4
4
 
5
- __version__ = "0.1.4"
6
- __version_info__ = (0, 1, 4)
5
+ __version__ = "0.1.25"
6
+ __version_info__ = (0, 1, 25)
7
7
 
8
8
 
9
9
  def get_version() -> str: