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
@@ -1,243 +1,245 @@
1
- import time
2
-
3
- from scalebox.csx_desktop.main import Sandbox
4
-
5
-
6
- def desktop_automation_demo():
7
- """桌面自动化功能演示"""
8
-
9
- # 1. 创建桌面沙箱实例
10
- print("正在启动桌面沙箱...")
11
- desktop = Sandbox(timeout=3600, template="browser-use")
12
- # print(f"沙箱已启动,ID: {desktop.sandbox_id}")
13
-
14
- # 2. 启动VNC流以便远程查看桌面
15
- print("启动VNC远程桌面...")
16
- time.sleep(5)
17
- desktop.stream.start()
18
- vnc_url = desktop.stream.get_url(auto_connect=True)
19
- print(f"VNC访问URL: {vnc_url}")
20
- # print(f"VNC认证密钥: {desktop.stream.get_auth_key()}")
21
-
22
- # 等待系统完全启动
23
- time.sleep(3)
24
-
25
- # 3. 基本鼠标操作示例
26
- print("执行鼠标操作...")
27
-
28
- # 获取屏幕尺寸
29
- screen_width, screen_height = desktop.get_screen_size()
30
- print(f"屏幕尺寸: {screen_width}x{screen_height}")
31
-
32
- # 移动鼠标到屏幕中心
33
- center_x, center_y = screen_width // 2, screen_height // 2
34
- desktop.move_mouse(center_x, center_y)
35
-
36
- # 获取当前光标位置
37
- cursor_x, cursor_y = desktop.get_cursor_position()
38
- print(f"光标位置: ({cursor_x}, {cursor_y})")
39
-
40
- # 左键点击
41
- desktop.left_click(center_x, center_y)
42
-
43
- # 右键点击
44
- desktop.right_click(center_x + 100, center_y)
45
-
46
- # 双击
47
- desktop.double_click(center_x, center_y + 100)
48
-
49
- # 鼠标拖动示例
50
- desktop.drag((center_x, center_y), (center_x + 200, center_y))
51
-
52
- # 鼠标滚动
53
- desktop.scroll("down", 2) # 向下滚动2次
54
- desktop.scroll("up", 1) # 向上滚动1次
55
-
56
- # 4. 键盘输入示例
57
- print("执行键盘操作...")
58
-
59
- # 打开终端
60
- desktop.launch("xfce4-terminal") # 或 xfce4-terminal
61
- time.sleep(2)
62
-
63
- # 获取当前窗口ID
64
- current_window = desktop.get_current_window_id()
65
- print(f"当前窗口ID: {current_window}")
66
-
67
- # 输入命令
68
- desktop.write("echo 'Hello from SBX Sandbox!'")
69
- desktop.press("enter")
70
-
71
- # 特殊按键
72
- desktop.press("ctrl+shift+t") # 新建标签页
73
- time.sleep(1)
74
-
75
- desktop.write("ls -la")
76
- desktop.press("enter")
77
-
78
- # 5. 窗口管理示例
79
- print("执行窗口管理操作...")
80
-
81
- # 获取所有可见窗口
82
- terminal_windows = desktop.get_application_windows("xfce4-terminal")
83
- print(f"终端窗口: {terminal_windows}")
84
-
85
- if terminal_windows:
86
- # 获取窗口标题
87
- window_title = desktop.get_window_title(terminal_windows[0])
88
- print(f"窗口标题: {window_title}")
89
-
90
- # 6. 启动应用程序示例
91
- print("启动其他应用程序...")
92
-
93
- # 使用gtk-launch启动应用程序
94
- try:
95
- desktop.launch("firefox-esr") # 启动Firefox浏览器
96
- time.sleep(3)
97
-
98
- # 在Firefox中输入URL
99
- desktop.press("ctrl+l") # 聚焦地址栏
100
- desktop.write("https://www.google.com")
101
- desktop.press("enter")
102
-
103
- except Exception as e:
104
- print(f"启动Firefox失败: {e}")
105
-
106
- # 7. 文件操作示例 - 创建并打开文件
107
- print("执行文件操作...")
108
-
109
- # 创建测试文件
110
- test_content = """Hello World!
111
- This is a test file created from SBX Sandbox SDK.
112
- Current time: {time}
113
- """.format(
114
- time=time.ctime()
115
- )
116
-
117
- desktop.files.write("/tmp/test_file.txt", test_content)
118
- print("已创建测试文件")
119
-
120
- # 使用默认程序打开文件
121
- # desktop.open("/tmp/test_file.txt")
122
- # time.sleep(2)
123
-
124
- # 8. 截图功能示例
125
- print("执行截图操作...")
126
-
127
- # 截取屏幕并保存为bytes
128
- screenshot_bytes = desktop.screenshot(format="bytes")
129
- print(f"截图大小: {len(screenshot_bytes)} 字节")
130
-
131
- # 也可以获取截图流
132
- # screenshot_stream = desktop.screenshot(format="stream")
133
- # for chunk in screenshot_stream:
134
- # # 处理截图数据
135
- # pass
136
-
137
- # 9. 复杂自动化脚本示例
138
- print("执行复杂自动化任务...")
139
-
140
- # 返回终端窗口
141
- terminal_windows = desktop.get_application_windows("xfce4-terminal")
142
- if terminal_windows:
143
- # 激活终端窗口
144
- desktop.commands.run(
145
- f"DISPLAY={desktop._display} xdotool windowactivate {terminal_windows[0]}"
146
- )
147
-
148
- # 创建Python脚本并执行
149
- python_script = """#!/usr/bin/env python3
150
- import time
151
- print("starting...")
152
- for i in range(5):
153
- print(f"count: {i}")
154
- time.sleep(0.5)
155
- print("success!")
156
- """
157
-
158
- script_path = "/tmp/automation_script.py"
159
- desktop.files.write(script_path, python_script)
160
-
161
- desktop.write(f"python3 /uploads{script_path}")
162
- desktop.press("enter")
163
-
164
- # 10. 等待和定时操作
165
- print("等待操作完成...")
166
- desktop.wait(2000) # 等待2秒
167
-
168
- # 展示所有功能已完成
169
- desktop.write("echo 'All successfully!'")
170
- desktop.press("enter")
171
-
172
- print("演示完成! 沙箱将在10分钟后自动关闭或按Ctrl+C提前结束")
173
-
174
- # 保持沙箱运行以便观察
175
- try:
176
- time.sleep(600) # 保持10分钟
177
- except KeyboardInterrupt:
178
- print("提前结束沙箱会话")
179
-
180
- # 11. 清理工作会在with语句退出时自动执行
181
-
182
-
183
- # def specific_use_cases():
184
- # """特定用例示例"""
185
- #
186
- # # 用例1: 网页自动化测试
187
- # def web_automation():
188
- # with Sandbox() as desktop:
189
- # desktop.open("firefox")
190
- # time.sleep(3)
191
- # desktop.press("ctrl+l")
192
- # desktop.write("https://www.google.com")
193
- # desktop.press("enter")
194
- # time.sleep(2)
195
- # desktop.write("E2B Sandbox Automation")
196
- # desktop.press("enter")
197
- # # 更多网页自动化操作...
198
- #
199
- # # 用例2: GUI应用测试
200
- # def gui_app_testing():
201
- # with Sandbox() as desktop:
202
- # # 启动待测试的GUI应用
203
- # desktop.launch("some-gui-application")
204
- # time.sleep(2)
205
- #
206
- # # 执行一系列测试操作
207
- # desktop.move_mouse(100, 100)
208
- # desktop.left_click()
209
- # desktop.write("测试输入")
210
- # desktop.press("enter")
211
- #
212
- # # 验证结果
213
- # screenshot = desktop.screenshot(format="bytes")
214
- # # 这里可以添加截图分析逻辑
215
- #
216
- # # 用例3: 教育演示
217
- # def educational_demo():
218
- # with Sandbox() as desktop:
219
- # # 打开编程环境
220
- # desktop.open("vscode") # 或其他IDE
221
- #
222
- # # 逐步演示代码编写和执行过程
223
- # time.sleep(2)
224
- # desktop.write("# Python编程演示")
225
- # desktop.press("enter")
226
- # desktop.write("print('Hello, Students!')")
227
- # desktop.press("enter")
228
- #
229
- # # 保存并运行
230
- # desktop.press("ctrl+s")
231
- # desktop.press("ctrl+alt+t") # 打开终端
232
- # desktop.write("python3 demo.py")
233
- # desktop.press("enter")
234
-
235
-
236
- if __name__ == "__main__":
237
- try:
238
- desktop_automation_demo()
239
- except Exception as e:
240
- print(f"演示过程中发生错误: {e}")
241
- import traceback
242
-
243
- traceback.print_exc()
1
+ import time
2
+
3
+ from scalebox.csx_desktop.main import Sandbox
4
+
5
+
6
+ def desktop_automation_demo():
7
+ """桌面自动化功能演示"""
8
+
9
+ # 1. 创建桌面沙箱实例
10
+ print("正在启动桌面沙箱...")
11
+ desktop = Sandbox.create(timeout=3600)
12
+ print(f"沙箱已启动,ID: {desktop.sandbox_id}")
13
+
14
+ # 2. 启动VNC流以便远程查看桌面
15
+ print("启动VNC远程桌面...")
16
+ time.sleep(5)
17
+ desktop.stream.start()
18
+ vnc_url = desktop.stream.get_url(auto_connect=True)
19
+ print(f"VNC访问URL: {vnc_url}")
20
+ # print(f"VNC认证密钥: {desktop.stream.get_auth_key()}")
21
+
22
+ # 等待系统完全启动
23
+ time.sleep(3)
24
+
25
+ # 3. 基本鼠标操作示例
26
+
27
+
28
+ print("执行鼠标操作...")
29
+
30
+ # 获取屏幕尺寸
31
+ screen_width, screen_height = desktop.get_screen_size()
32
+ print(f"屏幕尺寸: {screen_width}x{screen_height}")
33
+
34
+ # 移动鼠标到屏幕中心
35
+ center_x, center_y = screen_width // 2, screen_height // 2
36
+ desktop.move_mouse(center_x, center_y)
37
+
38
+ # 获取当前光标位置
39
+ cursor_x, cursor_y = desktop.get_cursor_position()
40
+ print(f"光标位置: ({cursor_x}, {cursor_y})")
41
+
42
+ # 左键点击
43
+ desktop.left_click(center_x, center_y)
44
+
45
+ # 右键点击
46
+ desktop.right_click(center_x + 100, center_y)
47
+
48
+ # 双击
49
+ desktop.double_click(center_x, center_y + 100)
50
+
51
+ # 鼠标拖动示例
52
+ desktop.drag((center_x, center_y), (center_x + 200, center_y))
53
+
54
+ # 鼠标滚动
55
+ desktop.scroll("down", 2) # 向下滚动2次
56
+ desktop.scroll("up", 1) # 向上滚动1次
57
+
58
+ # 4. 键盘输入示例
59
+ print("执行键盘操作...")
60
+
61
+ # 打开终端
62
+ desktop.launch("xfce4-terminal") # 或 xfce4-terminal
63
+ time.sleep(2)
64
+
65
+ # 获取当前窗口ID
66
+ current_window = desktop.get_current_window_id()
67
+ print(f"当前窗口ID: {current_window}")
68
+
69
+ # 输入命令
70
+ desktop.write("echo 'Hello from SBX Sandbox!'")
71
+ desktop.press("enter")
72
+
73
+ # 特殊按键
74
+ desktop.press("ctrl+shift+t") # 新建标签页
75
+ time.sleep(1)
76
+
77
+ desktop.write("ls -la")
78
+ desktop.press("enter")
79
+
80
+ # 5. 窗口管理示例
81
+ print("执行窗口管理操作...")
82
+
83
+ # 获取所有可见窗口
84
+ terminal_windows = desktop.get_application_windows("xfce4-terminal")
85
+ print(f"终端窗口: {terminal_windows}")
86
+
87
+ if terminal_windows:
88
+ # 获取窗口标题
89
+ window_title = desktop.get_window_title(terminal_windows[0])
90
+ print(f"窗口标题: {window_title}")
91
+
92
+ # 6. 启动应用程序示例
93
+ print("启动其他应用程序...")
94
+
95
+ # 使用gtk-launch启动应用程序
96
+ try:
97
+ desktop.launch("firefox-esr") # 启动Firefox浏览器
98
+ time.sleep(3)
99
+
100
+ # 在Firefox中输入URL
101
+ desktop.press("ctrl+l") # 聚焦地址栏
102
+ desktop.write("https://www.google.com")
103
+ desktop.press("enter")
104
+
105
+ except Exception as e:
106
+ print(f"启动Firefox失败: {e}")
107
+
108
+ # 7. 文件操作示例 - 创建并打开文件
109
+ print("执行文件操作...")
110
+
111
+ # 创建测试文件
112
+ test_content = """Hello World!
113
+ This is a test file created from SBX Sandbox SDK.
114
+ Current time: {time}
115
+ """.format(
116
+ time=time.ctime()
117
+ )
118
+
119
+ desktop.files.write("/tmp/test_file.txt", test_content)
120
+ print("已创建测试文件")
121
+
122
+ # 使用默认程序打开文件
123
+ # desktop.open("/tmp/test_file.txt")
124
+ # time.sleep(2)
125
+
126
+ # 8. 截图功能示例
127
+ print("执行截图操作...")
128
+
129
+ # 截取屏幕并保存为bytes
130
+ screenshot_bytes = desktop.screenshot(format="bytes")
131
+ print(f"截图大小: {len(screenshot_bytes)} 字节")
132
+
133
+ # 也可以获取截图流
134
+ # screenshot_stream = desktop.screenshot(format="stream")
135
+ # for chunk in screenshot_stream:
136
+ # # 处理截图数据
137
+ # pass
138
+
139
+ # 9. 复杂自动化脚本示例
140
+ print("执行复杂自动化任务...")
141
+
142
+ # 返回终端窗口
143
+ terminal_windows = desktop.get_application_windows("xfce4-terminal")
144
+ if terminal_windows:
145
+ # 激活终端窗口
146
+ desktop.commands.run(
147
+ f"DISPLAY={desktop._display} xdotool windowactivate {terminal_windows[0]}"
148
+ )
149
+
150
+ # 创建Python脚本并执行
151
+ python_script = """#!/usr/bin/env python3
152
+ import time
153
+ print("starting...")
154
+ for i in range(5):
155
+ print(f"count: {i}")
156
+ time.sleep(0.5)
157
+ print("success!")
158
+ """
159
+
160
+ script_path = "/tmp/automation_script.py"
161
+ desktop.files.write(script_path, python_script)
162
+
163
+ desktop.write(f"python3 /uploads{script_path}")
164
+ desktop.press("enter")
165
+
166
+ # 10. 等待和定时操作
167
+ print("等待操作完成...")
168
+ desktop.wait(2000) # 等待2秒
169
+
170
+ # 展示所有功能已完成
171
+ desktop.write("echo 'All successfully!'")
172
+ desktop.press("enter")
173
+
174
+ print("演示完成! 沙箱将在10分钟后自动关闭或按Ctrl+C提前结束")
175
+
176
+ # 保持沙箱运行以便观察
177
+ try:
178
+ time.sleep(600) # 保持10分钟
179
+ except KeyboardInterrupt:
180
+ print("提前结束沙箱会话")
181
+
182
+ # 11. 清理工作会在with语句退出时自动执行
183
+
184
+
185
+ # def specific_use_cases():
186
+ # """特定用例示例"""
187
+ #
188
+ # # 用例1: 网页自动化测试
189
+ # def web_automation():
190
+ # with Sandbox() as desktop:
191
+ # desktop.open("firefox")
192
+ # time.sleep(3)
193
+ # desktop.press("ctrl+l")
194
+ # desktop.write("https://www.google.com")
195
+ # desktop.press("enter")
196
+ # time.sleep(2)
197
+ # desktop.write("E2B Sandbox Automation")
198
+ # desktop.press("enter")
199
+ # # 更多网页自动化操作...
200
+ #
201
+ # # 用例2: GUI应用测试
202
+ # def gui_app_testing():
203
+ # with Sandbox() as desktop:
204
+ # # 启动待测试的GUI应用
205
+ # desktop.launch("some-gui-application")
206
+ # time.sleep(2)
207
+ #
208
+ # # 执行一系列测试操作
209
+ # desktop.move_mouse(100, 100)
210
+ # desktop.left_click()
211
+ # desktop.write("测试输入")
212
+ # desktop.press("enter")
213
+ #
214
+ # # 验证结果
215
+ # screenshot = desktop.screenshot(format="bytes")
216
+ # # 这里可以添加截图分析逻辑
217
+ #
218
+ # # 用例3: 教育演示
219
+ # def educational_demo():
220
+ # with Sandbox() as desktop:
221
+ # # 打开编程环境
222
+ # desktop.open("vscode") # 或其他IDE
223
+ #
224
+ # # 逐步演示代码编写和执行过程
225
+ # time.sleep(2)
226
+ # desktop.write("# Python编程演示")
227
+ # desktop.press("enter")
228
+ # desktop.write("print('Hello, Students!')")
229
+ # desktop.press("enter")
230
+ #
231
+ # # 保存并运行
232
+ # desktop.press("ctrl+s")
233
+ # desktop.press("ctrl+alt+t") # 打开终端
234
+ # desktop.write("python3 demo.py")
235
+ # desktop.press("enter")
236
+
237
+
238
+ if __name__ == "__main__":
239
+ try:
240
+ desktop_automation_demo()
241
+ except Exception as e:
242
+ print(f"演示过程中发生错误: {e}")
243
+ import traceback
244
+
245
+ traceback.print_exc()
@@ -1,12 +1,12 @@
1
- from email.mime import application
2
-
3
- from csx_desktop.main import Sandbox
4
-
5
- sandbox = Sandbox()
6
- sandbox.stream.start()
7
-
8
- print(sandbox.get_screen_size())
9
- sandbox.launch("firefox-esr")
10
- windpws_id = sandbox.get_current_window_id()
11
- print(windpws_id)
12
- print(sandbox.get_window_title(window_id=windpws_id))
1
+ from email.mime import application
2
+
3
+ from csx_desktop.main import Sandbox
4
+
5
+ sandbox = Sandbox()
6
+ sandbox.stream.start()
7
+
8
+ print(sandbox.get_screen_size())
9
+ sandbox.launch("firefox-esr")
10
+ windpws_id = sandbox.get_current_window_id()
11
+ print(windpws_id)
12
+ print(sandbox.get_window_title(window_id=windpws_id))