scalebox-sdk 0.1.11__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 (38) hide show
  1. scalebox/__init__.py +1 -1
  2. scalebox/code_interpreter/code_interpreter_async.py +12 -12
  3. scalebox/code_interpreter/code_interpreter_sync.py +11 -11
  4. scalebox/generated/api_pb2_connect.py +3 -3
  5. scalebox/sandbox_sync/main.py +1 -1
  6. scalebox/test/aclient.py +72 -72
  7. scalebox/test/code_interpreter_centext.py +21 -21
  8. scalebox/test/code_interpreter_centext_sync.py +21 -21
  9. scalebox/test/code_interpreter_test.py +34 -34
  10. scalebox/test/code_interpreter_test_sync.py +34 -34
  11. scalebox/test/run_all_validation_tests.py +334 -334
  12. scalebox/test/test_basic.py +78 -78
  13. scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -2653
  14. scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -2655
  15. scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -3416
  16. scalebox/test/test_code_interpreter_execcode.py +3352 -0
  17. scalebox/test/test_code_interpreter_sync_comprehensive.py +3416 -3412
  18. scalebox/test/test_csx_desktop_examples.py +130 -0
  19. scalebox/test/test_e2b_first.py +11 -11
  20. scalebox/test/test_sandbox_async_comprehensive.py +736 -738
  21. scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -778
  22. scalebox/test/test_sandbox_sync_comprehensive.py +779 -770
  23. scalebox/test/test_sandbox_usage_examples.py +987 -987
  24. scalebox/test/testacreate.py +24 -24
  25. scalebox/test/testagetinfo.py +18 -18
  26. scalebox/test/testcodeinterpreter_async.py +508 -508
  27. scalebox/test/testcodeinterpreter_sync.py +239 -239
  28. scalebox/test/testcomputeuse.py +245 -243
  29. scalebox/test/testnovnc.py +12 -12
  30. scalebox/test/testsandbox_async.py +202 -118
  31. scalebox/test/testsandbox_sync.py +71 -38
  32. scalebox/version.py +2 -2
  33. {scalebox_sdk-0.1.11.dist-info → scalebox_sdk-0.1.13.dist-info}/METADATA +1 -1
  34. {scalebox_sdk-0.1.11.dist-info → scalebox_sdk-0.1.13.dist-info}/RECORD +38 -36
  35. {scalebox_sdk-0.1.11.dist-info → scalebox_sdk-0.1.13.dist-info}/WHEEL +0 -0
  36. {scalebox_sdk-0.1.11.dist-info → scalebox_sdk-0.1.13.dist-info}/entry_points.txt +0 -0
  37. {scalebox_sdk-0.1.11.dist-info → scalebox_sdk-0.1.13.dist-info}/licenses/LICENSE +0 -0
  38. {scalebox_sdk-0.1.11.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.11"
12
+ __version__ = "0.1.13"
13
13
  __author__ = "ScaleBox Team"
14
14
  __email__ = "dev@scalebox.dev"
15
15
 
@@ -205,9 +205,9 @@ class AsyncSandbox(BaseAsyncSandbox):
205
205
  )
206
206
 
207
207
  # Set headers
208
- headers = {
209
- "Authorization": "Bearer root",
210
- }
208
+ # headers = {
209
+ # "Authorization": "Bearer root",
210
+ # }
211
211
 
212
212
  try:
213
213
  # Create client and execute request
@@ -227,7 +227,7 @@ class AsyncSandbox(BaseAsyncSandbox):
227
227
  # Execute request and get response stream
228
228
  responses = client.execute(
229
229
  req=request,
230
- extra_headers=headers,
230
+ extra_headers=self.connection_config.headers,
231
231
  timeout_seconds=request_timeout,
232
232
  )
233
233
 
@@ -298,9 +298,9 @@ class AsyncSandbox(BaseAsyncSandbox):
298
298
  http_client=self._session,
299
299
  base_url=self.envd_api_url,
300
300
  )
301
- headers = {
302
- "Authorization": "Bearer root",
303
- }
301
+ # headers = {
302
+ # "Authorization": "Bearer root",
303
+ # }
304
304
 
305
305
  # Build request
306
306
  request = api_pb2.CreateContextRequest(
@@ -311,7 +311,7 @@ class AsyncSandbox(BaseAsyncSandbox):
311
311
  # Execute request and get response stream
312
312
  response = await client.create_context(
313
313
  req=request,
314
- extra_headers=headers,
314
+ extra_headers=self.connection_config.headers,
315
315
  )
316
316
  return Context.from_json(
317
317
  {
@@ -361,9 +361,9 @@ class AsyncSandbox(BaseAsyncSandbox):
361
361
  base_url=self.envd_api_url,
362
362
  http_client=self._session,
363
363
  )
364
- headers = {
365
- "Authorization": "Bearer root",
366
- }
367
- await client.destroy_context(destroy_context_request, extra_headers=headers)
364
+ # headers = {
365
+ # "Authorization": "Bearer root",
366
+ # }
367
+ await client.destroy_context(destroy_context_request,extra_headers=self.connection_config.headers)
368
368
  except Exception as e:
369
369
  logger.warning(f"Failed to destroy context {context.id}: {e}")
@@ -199,13 +199,13 @@ class Sandbox(BaseSandbox):
199
199
 
200
200
  # Execute code via gRPC
201
201
  execution = Execution()
202
- headers = {
203
- "Authorization": "Bearer root",
204
- }
202
+ # headers = {
203
+ # "Authorization": "Bearer root",
204
+ # }
205
205
  response_stream = client.execute(
206
206
  execute_request,
207
207
  timeout_seconds=deadline - time.time(),
208
- extra_headers=headers,
208
+ extra_headers=self.connection_config.headers,
209
209
  )
210
210
 
211
211
  # Process stream responses
@@ -263,9 +263,9 @@ class Sandbox(BaseSandbox):
263
263
  base_url=self.envd_api_url,
264
264
  http_client=self._urllib3_pool,
265
265
  )
266
- headers = {
267
- "Authorization": "Bearer root",
268
- }
266
+ # headers = {
267
+ # "Authorization": "Bearer root",
268
+ # }
269
269
  # Create context via gRPC
270
270
  response = client.create_context(
271
271
  create_context_request,
@@ -308,10 +308,10 @@ class Sandbox(BaseSandbox):
308
308
  base_url=self.envd_api_url,
309
309
  http_client=self._urllib3_pool,
310
310
  )
311
- headers = {
312
- "Authorization": "Bearer root",
313
- }
314
- client.destroy_context(destroy_context_request, extra_headers=headers)
311
+ # headers = {
312
+ # "Authorization": "Bearer root",
313
+ # }
314
+ client.destroy_context(destroy_context_request,extra_headers=self.connection_config.headers)
315
315
 
316
316
  except Exception as e:
317
317
  logger.warning(f"Failed to destroy context {context.id}: {e}")
@@ -690,7 +690,7 @@ class ProcessClient:
690
690
  extra_headers: HeaderInput | None = None,
691
691
  timeout_seconds: float | None = None,
692
692
  ) -> Iterator[api_pb2.ConnectResponse]:
693
- stream_output = self.call_connect(req, extra_headers)
693
+ stream_output = self.call_connect(req, extra_headers,timeout_seconds)
694
694
  err = stream_output.error()
695
695
  if err is not None:
696
696
  raise err
@@ -725,7 +725,7 @@ class ProcessClient:
725
725
  extra_headers: HeaderInput | None = None,
726
726
  timeout_seconds: float | None = None,
727
727
  ) -> Iterator[api_pb2.StartResponse]:
728
- stream_output = self.call_start(req, extra_headers)
728
+ stream_output = self.call_start(req, extra_headers,timeout_seconds)
729
729
  err = stream_output.error()
730
730
  if err is not None:
731
731
  raise err
@@ -943,7 +943,7 @@ class AsyncProcessClient:
943
943
  extra_headers: HeaderInput | None = None,
944
944
  timeout_seconds: float | None = None,
945
945
  ) -> AsyncIterator[api_pb2.StartResponse]:
946
- stream_output = await self.call_start(req, extra_headers)
946
+ stream_output = await self.call_start(req, extra_headers,timeout_seconds)
947
947
  err = stream_output.error()
948
948
  if err is not None:
949
949
  raise err
@@ -335,7 +335,7 @@ class Sandbox(SandboxSetup, SandboxApi):
335
335
  :param timeout: Timeout for the sandbox in **seconds**, default to 300 seconds. Maximum time a sandbox can be kept alive is 24 hours (86_400 seconds) for Pro users and 1 hour (3_600 seconds) for Hobby users.
336
336
  :param metadata: Custom metadata for the sandbox
337
337
  :param envs: Custom environment variables for the sandbox
338
- :param api_key: E2B API Key to use for authentication, defaults to `E2B_API_KEY` environment variable
338
+ :param api_key: scalebox API Key to use for authentication, defaults to `CSX_API_KEY` environment variable
339
339
  :param request_timeout: Timeout for the request in **seconds**
340
340
  :param proxy: Proxy to use for the request and for the **requests made to the returned sandbox**
341
341
  :param secure: Envd is secured with access token and cannot be used without it
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()