scalebox-sdk 0.1.0__tar.gz

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 (164) hide show
  1. scalebox_sdk-0.1.0/CHANGELOG.md +44 -0
  2. scalebox_sdk-0.1.0/LICENSE +21 -0
  3. scalebox_sdk-0.1.0/MANIFEST.in +23 -0
  4. scalebox_sdk-0.1.0/PKG-INFO +292 -0
  5. scalebox_sdk-0.1.0/README.md +233 -0
  6. scalebox_sdk-0.1.0/pyproject.toml +126 -0
  7. scalebox_sdk-0.1.0/scalebox/__init__.py +80 -0
  8. scalebox_sdk-0.1.0/scalebox/api/__init__.py +128 -0
  9. scalebox_sdk-0.1.0/scalebox/api/client/__init__.py +8 -0
  10. scalebox_sdk-0.1.0/scalebox/api/client/api/__init__.py +1 -0
  11. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/__init__.py +0 -0
  12. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/delete_sandboxes_sandbox_id.py +161 -0
  13. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/get_sandboxes.py +176 -0
  14. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/get_sandboxes_metrics.py +173 -0
  15. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id.py +163 -0
  16. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_logs.py +199 -0
  17. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/get_sandboxes_sandbox_id_metrics.py +214 -0
  18. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/get_v2_sandboxes.py +229 -0
  19. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/post_sandboxes.py +174 -0
  20. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_pause.py +165 -0
  21. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_refreshes.py +182 -0
  22. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_resume.py +190 -0
  23. scalebox_sdk-0.1.0/scalebox/api/client/api/sandboxes/post_sandboxes_sandbox_id_timeout.py +194 -0
  24. scalebox_sdk-0.1.0/scalebox/api/client/client.py +288 -0
  25. scalebox_sdk-0.1.0/scalebox/api/client/errors.py +16 -0
  26. scalebox_sdk-0.1.0/scalebox/api/client/models/__init__.py +81 -0
  27. scalebox_sdk-0.1.0/scalebox/api/client/models/build_log_entry.py +79 -0
  28. scalebox_sdk-0.1.0/scalebox/api/client/models/created_access_token.py +100 -0
  29. scalebox_sdk-0.1.0/scalebox/api/client/models/created_team_api_key.py +166 -0
  30. scalebox_sdk-0.1.0/scalebox/api/client/models/error.py +67 -0
  31. scalebox_sdk-0.1.0/scalebox/api/client/models/identifier_masking_details.py +83 -0
  32. scalebox_sdk-0.1.0/scalebox/api/client/models/listed_sandbox.py +138 -0
  33. scalebox_sdk-0.1.0/scalebox/api/client/models/log_level.py +11 -0
  34. scalebox_sdk-0.1.0/scalebox/api/client/models/new_access_token.py +59 -0
  35. scalebox_sdk-0.1.0/scalebox/api/client/models/new_sandbox.py +125 -0
  36. scalebox_sdk-0.1.0/scalebox/api/client/models/new_team_api_key.py +59 -0
  37. scalebox_sdk-0.1.0/scalebox/api/client/models/node.py +154 -0
  38. scalebox_sdk-0.1.0/scalebox/api/client/models/node_detail.py +152 -0
  39. scalebox_sdk-0.1.0/scalebox/api/client/models/node_status.py +11 -0
  40. scalebox_sdk-0.1.0/scalebox/api/client/models/node_status_change.py +61 -0
  41. scalebox_sdk-0.1.0/scalebox/api/client/models/post_sandboxes_sandbox_id_refreshes_body.py +59 -0
  42. scalebox_sdk-0.1.0/scalebox/api/client/models/post_sandboxes_sandbox_id_timeout_body.py +59 -0
  43. scalebox_sdk-0.1.0/scalebox/api/client/models/resumed_sandbox.py +68 -0
  44. scalebox_sdk-0.1.0/scalebox/api/client/models/sandbox.py +125 -0
  45. scalebox_sdk-0.1.0/scalebox/api/client/models/sandbox_detail.py +178 -0
  46. scalebox_sdk-0.1.0/scalebox/api/client/models/sandbox_log.py +70 -0
  47. scalebox_sdk-0.1.0/scalebox/api/client/models/sandbox_logs.py +73 -0
  48. scalebox_sdk-0.1.0/scalebox/api/client/models/sandbox_metric.py +110 -0
  49. scalebox_sdk-0.1.0/scalebox/api/client/models/sandbox_state.py +9 -0
  50. scalebox_sdk-0.1.0/scalebox/api/client/models/sandboxes_with_metrics.py +59 -0
  51. scalebox_sdk-0.1.0/scalebox/api/client/models/team.py +83 -0
  52. scalebox_sdk-0.1.0/scalebox/api/client/models/team_api_key.py +158 -0
  53. scalebox_sdk-0.1.0/scalebox/api/client/models/team_user.py +68 -0
  54. scalebox_sdk-0.1.0/scalebox/api/client/models/template.py +179 -0
  55. scalebox_sdk-0.1.0/scalebox/api/client/models/template_build.py +117 -0
  56. scalebox_sdk-0.1.0/scalebox/api/client/models/template_build_file_upload.py +70 -0
  57. scalebox_sdk-0.1.0/scalebox/api/client/models/template_build_request.py +115 -0
  58. scalebox_sdk-0.1.0/scalebox/api/client/models/template_build_request_v2.py +88 -0
  59. scalebox_sdk-0.1.0/scalebox/api/client/models/template_build_start_v2.py +114 -0
  60. scalebox_sdk-0.1.0/scalebox/api/client/models/template_build_status.py +11 -0
  61. scalebox_sdk-0.1.0/scalebox/api/client/models/template_step.py +91 -0
  62. scalebox_sdk-0.1.0/scalebox/api/client/models/template_update_request.py +59 -0
  63. scalebox_sdk-0.1.0/scalebox/api/client/models/update_team_api_key.py +59 -0
  64. scalebox_sdk-0.1.0/scalebox/api/client/py.typed +1 -0
  65. scalebox_sdk-0.1.0/scalebox/api/client/types.py +46 -0
  66. scalebox_sdk-0.1.0/scalebox/api/metadata.py +19 -0
  67. scalebox_sdk-0.1.0/scalebox/cli.py +125 -0
  68. scalebox_sdk-0.1.0/scalebox/client/__init__.py +0 -0
  69. scalebox_sdk-0.1.0/scalebox/client/aclient.py +57 -0
  70. scalebox_sdk-0.1.0/scalebox/client/api.proto +460 -0
  71. scalebox_sdk-0.1.0/scalebox/client/buf.gen.yaml +8 -0
  72. scalebox_sdk-0.1.0/scalebox/client/client.py +102 -0
  73. scalebox_sdk-0.1.0/scalebox/client/requirements.txt +5 -0
  74. scalebox_sdk-0.1.0/scalebox/code_interpreter/__init__.py +12 -0
  75. scalebox_sdk-0.1.0/scalebox/code_interpreter/charts.py +230 -0
  76. scalebox_sdk-0.1.0/scalebox/code_interpreter/code_interpreter_async.py +369 -0
  77. scalebox_sdk-0.1.0/scalebox/code_interpreter/code_interpreter_sync.py +317 -0
  78. scalebox_sdk-0.1.0/scalebox/code_interpreter/constants.py +3 -0
  79. scalebox_sdk-0.1.0/scalebox/code_interpreter/exceptions.py +13 -0
  80. scalebox_sdk-0.1.0/scalebox/code_interpreter/models.py +485 -0
  81. scalebox_sdk-0.1.0/scalebox/connection_config.py +92 -0
  82. scalebox_sdk-0.1.0/scalebox/csx_connect/__init__.py +1 -0
  83. scalebox_sdk-0.1.0/scalebox/csx_connect/client.py +485 -0
  84. scalebox_sdk-0.1.0/scalebox/csx_desktop/__init__.py +0 -0
  85. scalebox_sdk-0.1.0/scalebox/csx_desktop/main.py +651 -0
  86. scalebox_sdk-0.1.0/scalebox/exceptions.py +83 -0
  87. scalebox_sdk-0.1.0/scalebox/generated/__init__.py +0 -0
  88. scalebox_sdk-0.1.0/scalebox/generated/api.py +61 -0
  89. scalebox_sdk-0.1.0/scalebox/generated/api_pb2.py +203 -0
  90. scalebox_sdk-0.1.0/scalebox/generated/api_pb2.pyi +956 -0
  91. scalebox_sdk-0.1.0/scalebox/generated/api_pb2_connect.py +1456 -0
  92. scalebox_sdk-0.1.0/scalebox/generated/rpc.py +50 -0
  93. scalebox_sdk-0.1.0/scalebox/generated/versions.py +3 -0
  94. scalebox_sdk-0.1.0/scalebox/requirements.txt +36 -0
  95. scalebox_sdk-0.1.0/scalebox/sandbox/__init__.py +0 -0
  96. scalebox_sdk-0.1.0/scalebox/sandbox/commands/__init__.py +0 -0
  97. scalebox_sdk-0.1.0/scalebox/sandbox/commands/command_handle.py +69 -0
  98. scalebox_sdk-0.1.0/scalebox/sandbox/commands/main.py +39 -0
  99. scalebox_sdk-0.1.0/scalebox/sandbox/filesystem/__init__.py +0 -0
  100. scalebox_sdk-0.1.0/scalebox/sandbox/filesystem/filesystem.py +95 -0
  101. scalebox_sdk-0.1.0/scalebox/sandbox/filesystem/watch_handle.py +60 -0
  102. scalebox_sdk-0.1.0/scalebox/sandbox/main.py +139 -0
  103. scalebox_sdk-0.1.0/scalebox/sandbox/sandbox_api.py +91 -0
  104. scalebox_sdk-0.1.0/scalebox/sandbox/signature.py +40 -0
  105. scalebox_sdk-0.1.0/scalebox/sandbox/utils.py +34 -0
  106. scalebox_sdk-0.1.0/scalebox/sandbox_async/__init__.py +1 -0
  107. scalebox_sdk-0.1.0/scalebox/sandbox_async/commands/command.py +307 -0
  108. scalebox_sdk-0.1.0/scalebox/sandbox_async/commands/command_handle.py +187 -0
  109. scalebox_sdk-0.1.0/scalebox/sandbox_async/commands/pty.py +187 -0
  110. scalebox_sdk-0.1.0/scalebox/sandbox_async/filesystem/filesystem.py +557 -0
  111. scalebox_sdk-0.1.0/scalebox/sandbox_async/filesystem/watch_handle.py +61 -0
  112. scalebox_sdk-0.1.0/scalebox/sandbox_async/main.py +646 -0
  113. scalebox_sdk-0.1.0/scalebox/sandbox_async/sandbox_api.py +365 -0
  114. scalebox_sdk-0.1.0/scalebox/sandbox_async/utils.py +7 -0
  115. scalebox_sdk-0.1.0/scalebox/sandbox_sync/__init__.py +2 -0
  116. scalebox_sdk-0.1.0/scalebox/sandbox_sync/commands/__init__.py +0 -0
  117. scalebox_sdk-0.1.0/scalebox/sandbox_sync/commands/command.py +300 -0
  118. scalebox_sdk-0.1.0/scalebox/sandbox_sync/commands/command_handle.py +150 -0
  119. scalebox_sdk-0.1.0/scalebox/sandbox_sync/commands/pty.py +181 -0
  120. scalebox_sdk-0.1.0/scalebox/sandbox_sync/filesystem/__init__.py +0 -0
  121. scalebox_sdk-0.1.0/scalebox/sandbox_sync/filesystem/filesystem.py +543 -0
  122. scalebox_sdk-0.1.0/scalebox/sandbox_sync/filesystem/watch_handle.py +66 -0
  123. scalebox_sdk-0.1.0/scalebox/sandbox_sync/main.py +790 -0
  124. scalebox_sdk-0.1.0/scalebox/sandbox_sync/sandbox_api.py +356 -0
  125. scalebox_sdk-0.1.0/scalebox/test/CODE_INTERPRETER_TESTS_READY.md +323 -0
  126. scalebox_sdk-0.1.0/scalebox/test/README.md +329 -0
  127. scalebox_sdk-0.1.0/scalebox/test/__init__.py +0 -0
  128. scalebox_sdk-0.1.0/scalebox/test/aclient.py +72 -0
  129. scalebox_sdk-0.1.0/scalebox/test/code_interpreter_centext.py +21 -0
  130. scalebox_sdk-0.1.0/scalebox/test/code_interpreter_centext_sync.py +21 -0
  131. scalebox_sdk-0.1.0/scalebox/test/code_interpreter_test.py +34 -0
  132. scalebox_sdk-0.1.0/scalebox/test/code_interpreter_test_sync.py +34 -0
  133. scalebox_sdk-0.1.0/scalebox/test/run_all_validation_tests.py +334 -0
  134. scalebox_sdk-0.1.0/scalebox/test/run_code_interpreter_tests.sh +67 -0
  135. scalebox_sdk-0.1.0/scalebox/test/run_tests.sh +230 -0
  136. scalebox_sdk-0.1.0/scalebox/test/test_basic.py +78 -0
  137. scalebox_sdk-0.1.0/scalebox/test/test_code_interpreter_async_comprehensive.py +2653 -0
  138. scalebox_sdk-0.1.0/scalebox/test/test_code_interpreter_e2basync_comprehensive.py +2655 -0
  139. scalebox_sdk-0.1.0/scalebox/test/test_code_interpreter_e2bsync_comprehensive.py +3416 -0
  140. scalebox_sdk-0.1.0/scalebox/test/test_code_interpreter_sync_comprehensive.py +3412 -0
  141. scalebox_sdk-0.1.0/scalebox/test/test_e2b_first.py +11 -0
  142. scalebox_sdk-0.1.0/scalebox/test/test_sandbox_async_comprehensive.py +738 -0
  143. scalebox_sdk-0.1.0/scalebox/test/test_sandbox_stress_and_edge_cases.py +778 -0
  144. scalebox_sdk-0.1.0/scalebox/test/test_sandbox_sync_comprehensive.py +770 -0
  145. scalebox_sdk-0.1.0/scalebox/test/test_sandbox_usage_examples.py +987 -0
  146. scalebox_sdk-0.1.0/scalebox/test/testacreate.py +24 -0
  147. scalebox_sdk-0.1.0/scalebox/test/testagetinfo.py +18 -0
  148. scalebox_sdk-0.1.0/scalebox/test/testcodeinterpreter_async.py +508 -0
  149. scalebox_sdk-0.1.0/scalebox/test/testcodeinterpreter_sync.py +239 -0
  150. scalebox_sdk-0.1.0/scalebox/test/testcomputeuse.py +243 -0
  151. scalebox_sdk-0.1.0/scalebox/test/testnovnc.py +12 -0
  152. scalebox_sdk-0.1.0/scalebox/test/testsandbox_async.py +118 -0
  153. scalebox_sdk-0.1.0/scalebox/test/testsandbox_sync.py +38 -0
  154. scalebox_sdk-0.1.0/scalebox/utils/__init__.py +0 -0
  155. scalebox_sdk-0.1.0/scalebox/utils/httpcoreclient.py +297 -0
  156. scalebox_sdk-0.1.0/scalebox/utils/httpxclient.py +403 -0
  157. scalebox_sdk-0.1.0/scalebox/version.py +16 -0
  158. scalebox_sdk-0.1.0/scalebox_sdk.egg-info/PKG-INFO +292 -0
  159. scalebox_sdk-0.1.0/scalebox_sdk.egg-info/SOURCES.txt +162 -0
  160. scalebox_sdk-0.1.0/scalebox_sdk.egg-info/dependency_links.txt +1 -0
  161. scalebox_sdk-0.1.0/scalebox_sdk.egg-info/entry_points.txt +2 -0
  162. scalebox_sdk-0.1.0/scalebox_sdk.egg-info/requires.txt +34 -0
  163. scalebox_sdk-0.1.0/scalebox_sdk.egg-info/top_level.txt +1 -0
  164. scalebox_sdk-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,44 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
11
+ - Initial release of ScaleBox Python SDK
12
+ - Multi-language code execution support (Python, R, Node.js, Deno/TypeScript, Java, Bash)
13
+ - Synchronous and asynchronous sandbox execution
14
+ - Persistent context management across executions
15
+ - Rich result formats (text, HTML, Markdown, SVG, images, LaTeX, JSON, JavaScript, charts)
16
+ - Real-time callbacks for stdout, stderr, results, and errors
17
+ - Comprehensive test suite with integration tests
18
+ - Full API client with authentication support
19
+ - File system operations and command execution
20
+ - PTY support for interactive sessions
21
+ - Context managers for resource cleanup
22
+ - Error handling with specific exception types
23
+ - Connection configuration with environment variable support
24
+
25
+ ### Features
26
+ - **Code Interpreter**: Execute code in multiple languages with rich output formats
27
+ - **Sandbox Management**: Create, manage, and destroy isolated execution environments
28
+ - **File Operations**: Upload, download, list, and manage files in sandboxes
29
+ - **Command Execution**: Run shell commands with real-time output
30
+ - **Context Persistence**: Maintain variable state across multiple executions
31
+ - **Async Support**: Full async/await support for concurrent operations
32
+ - **Error Handling**: Comprehensive exception handling with specific error types
33
+ - **Authentication**: API key and token-based authentication
34
+ - **Configuration**: Flexible configuration via environment variables or direct parameters
35
+
36
+ ## [0.1.0] - 2025-01-XX
37
+
38
+ ### Added
39
+ - Initial release
40
+ - Core SDK functionality
41
+ - Multi-language support
42
+ - Comprehensive documentation
43
+ - Test suite with 49+ test cases
44
+ - PyPI package configuration
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 scalebox-dev
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,23 @@
1
+ include README.md
2
+ include LICENSE
3
+ include CHANGELOG.md
4
+ include pyproject.toml
5
+ recursive-include scalebox *.py
6
+ recursive-include scalebox *.pyi
7
+ recursive-include scalebox *.proto
8
+ recursive-include scalebox *.yaml
9
+ recursive-include scalebox *.yml
10
+ recursive-include scalebox *.txt
11
+ recursive-include scalebox *.md
12
+ include scalebox/py.typed
13
+ recursive-include scalebox/test *.py
14
+ recursive-include scalebox/test *.md
15
+ recursive-include scalebox/test *.sh
16
+ global-exclude *.pyc
17
+ global-exclude *.pyo
18
+ global-exclude __pycache__
19
+ global-exclude .git*
20
+ global-exclude .DS_Store
21
+ global-exclude *.egg-info
22
+ global-exclude dist
23
+ global-exclude build
@@ -0,0 +1,292 @@
1
+ Metadata-Version: 2.4
2
+ Name: scalebox-sdk
3
+ Version: 0.1.0
4
+ Summary: ScaleBox Python SDK - A multi-language code execution sandbox with Python, R, Node.js, Deno/TypeScript, Java, and Bash support
5
+ Author-email: ScaleBox Team <dev@scalebox.dev>
6
+ Maintainer-email: ScaleBox Team <dev@scalebox.dev>
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/scalebox-dev/scalebox-sdk-python
9
+ Project-URL: Documentation, https://docs.scalebox.dev/python-sdk
10
+ Project-URL: Repository, https://github.com/scalebox-dev/scalebox-sdk-python
11
+ Project-URL: Issues, https://github.com/scalebox-dev/scalebox-sdk-python/issues
12
+ Project-URL: Changelog, https://github.com/scalebox-dev/scalebox-sdk-python/blob/main/CHANGELOG.md
13
+ Keywords: sandbox,code-execution,multi-language,python,r,nodejs,typescript,java,bash
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: Software Development :: Testing
25
+ Classifier: Topic :: System :: Distributed Computing
26
+ Requires-Python: >=3.9
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: httpx>=0.24
30
+ Requires-Dist: aiohttp>=3.8.0
31
+ Requires-Dist: urllib3>=1.26.0
32
+ Requires-Dist: httpcore>=0.15.0
33
+ Requires-Dist: grpcio>=1.70.0
34
+ Requires-Dist: grpcio-tools>=1.70.0
35
+ Requires-Dist: protobuf>=4.0.0
36
+ Requires-Dist: attrs>=21.4.0
37
+ Requires-Dist: dataclasses-json>=0.5.0
38
+ Requires-Dist: python-dateutil>=2.8.0
39
+ Requires-Dist: tenacity>=8.0.0
40
+ Requires-Dist: packaging>=21.0
41
+ Requires-Dist: typing-extensions>=4.0.0
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
44
+ Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
45
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
46
+ Requires-Dist: black>=22.0.0; extra == "dev"
47
+ Requires-Dist: isort>=5.0.0; extra == "dev"
48
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
49
+ Requires-Dist: mypy>=0.950; extra == "dev"
50
+ Requires-Dist: pre-commit>=2.17.0; extra == "dev"
51
+ Requires-Dist: python-dotenv>=0.19.0; extra == "dev"
52
+ Provides-Extra: connect
53
+ Requires-Dist: connectrpc>=0.0.1; python_version >= "3.13" and extra == "connect"
54
+ Provides-Extra: docs
55
+ Requires-Dist: sphinx>=4.0.0; extra == "docs"
56
+ Requires-Dist: sphinx-rtd-theme>=1.0.0; extra == "docs"
57
+ Requires-Dist: myst-parser>=0.18.0; extra == "docs"
58
+ Dynamic: license-file
59
+
60
+ # Scalebox Python SDK
61
+
62
+ 一个用于在可控沙箱中执行多语言代码的 Python SDK,支持同步与异步模式,以及多语言 Kernel(Python、R、Node.js、Deno/TypeScript、Java/IJAVA、Bash)。已提供全面的真实环境测试用例与脚本。
63
+
64
+ ## 功能特性
65
+ - 多语言内核:Python、R、Node.js、Deno/TypeScript、Java/IJAVA、Bash
66
+ - 同步 `Sandbox` 与异步 `AsyncSandbox` 执行
67
+ - 持久上下文:跨多次执行保留变量/状态
68
+ - 回调订阅:stdout、stderr、结果与错误
69
+ - 丰富结果格式:text、html、markdown、svg、png、jpeg、pdf、latex、json、javascript、chart、data 等
70
+ - 真实环境测试:覆盖同步/异步与多语言示例
71
+
72
+ ## 环境要求
73
+ - Python 3.12+
74
+ - 可访问的 Scalebox 环境或本地服务
75
+
76
+ ## 安装
77
+
78
+ ```bash
79
+ # 克隆项目
80
+ git clone https://github.com/scalebox-dev/scalebox-sdk-python.git
81
+ cd scalebox-sdk-python
82
+
83
+ # 建议使用虚拟环境
84
+ python3 -m venv venv
85
+ source venv/bin/activate
86
+
87
+ # 安装依赖
88
+ pip install -r scalebox/requirements.txt
89
+ ```
90
+
91
+ 如果你以源码方式直接使用包(非 pip 安装),请将 `scalebox` 目录加入 Python 路径或复制到 venv 的 site-packages:
92
+ ```bash
93
+ cp -r scalebox venv/lib/python3.12/site-packages/
94
+ ```
95
+
96
+ ## 配置
97
+ 支持从环境变量或 `.env` 文件读取凭据:
98
+
99
+ - `SBX_API_KEY` 或 `E2B_API_KEY`
100
+
101
+ 示例:
102
+ ```env
103
+ # .env
104
+ SBX_API_KEY=***
105
+ ```
106
+ 或:
107
+ ```bash
108
+ export SBX_API_KEY=***
109
+ ```
110
+
111
+ 可选:使用 `python-dotenv` 自动加载 `.env`:
112
+ ```bash
113
+ pip install python-dotenv
114
+ ```
115
+
116
+ ## 快速开始(同步)
117
+ ```python
118
+ from dotenv import load_dotenv; load_dotenv()
119
+ from scalebox.code_interpreter import Sandbox
120
+
121
+ sandbox = Sandbox.create() # 默认生存期 5 分钟
122
+ execution = sandbox.run_code("print('hello world')", language="python")
123
+ print(execution.logs.stdout)
124
+
125
+ files = sandbox.files.list("/")
126
+ print(files)
127
+ ```
128
+
129
+ ## 快速开始(异步)
130
+ ```python
131
+ import asyncio
132
+ from dotenv import load_dotenv; load_dotenv()
133
+ from scalebox.code_interpreter import AsyncSandbox
134
+
135
+ async def main():
136
+ sandbox = await AsyncSandbox.create()
137
+ exec_ = await sandbox.run_code("print('async hello')", language="python")
138
+ print(exec_.logs.stdout)
139
+
140
+ asyncio.run(main())
141
+ ```
142
+
143
+ ## 多语言示例
144
+ - Python:`language="python"`
145
+ - R:`language="r"`
146
+ - Node.js:`language="nodejs"`
147
+ - Deno/TypeScript:`language="typescript"`
148
+ - Java(IJAVA/纯Java):`language="ijava"` 或 `language="java"`
149
+ - Bash:`language="bash"`
150
+
151
+ 示例(Node.js):
152
+ ```python
153
+ from scalebox.code_interpreter import Sandbox
154
+ sbx = Sandbox.create()
155
+ code = """
156
+ console.log("Hello from Node.js!");
157
+ const x = 1 + 2; console.log(`x=${x}`);
158
+ """
159
+ result = sbx.run_code(code, language="nodejs")
160
+ print(result.logs.stdout)
161
+ ```
162
+
163
+ 示例(R):
164
+ ```python
165
+ from scalebox.code_interpreter import Sandbox
166
+ sbx = Sandbox.create()
167
+ code = """
168
+ print("Hello from R!")
169
+ x <- mean(c(1,2,3,4,5))
170
+ print(paste("mean:", x))
171
+ """
172
+ res = sbx.run_code(code, language="r")
173
+ print(res.logs.stdout)
174
+ ```
175
+
176
+ 示例(Deno/TypeScript):
177
+ ```python
178
+ from scalebox.code_interpreter import Sandbox
179
+ sbx = Sandbox.create()
180
+ ts = """
181
+ console.log("Hello from Deno/TypeScript!")
182
+ const nums: number[] = [1,2,3]
183
+ console.log(nums.reduce((a,b)=>a+b, 0))
184
+ """
185
+ res = sbx.run_code(ts, language="typescript")
186
+ print(res.logs.stdout)
187
+ ```
188
+
189
+ 示例(Java/IJAVA):
190
+ ```python
191
+ from scalebox.code_interpreter import Sandbox
192
+ sbx = Sandbox.create()
193
+ code = """
194
+ System.out.println("Hello from IJAVA!");
195
+ int a = 10, b = 20; System.out.println(a + b);
196
+ """
197
+ res = sbx.run_code(code, language="java")
198
+ print(res.logs.stdout)
199
+ ```
200
+
201
+ 示例(Bash):
202
+ ```python
203
+ from scalebox.code_interpreter import Sandbox
204
+ sbx = Sandbox.create()
205
+ res = sbx.run_code("echo 'Hello from Bash'", language="bash")
206
+ print(res.logs.stdout)
207
+ ```
208
+
209
+ ## 上下文管理(Context)
210
+ 上下文允许跨多次执行复用变量/状态:
211
+ ```python
212
+ from scalebox.code_interpreter import Sandbox
213
+ sbx = Sandbox.create()
214
+ ctx = sbx.create_code_context(language="python", cwd="/tmp")
215
+
216
+ sbx.run_code("counter = 0", context=ctx)
217
+ sbx.run_code("counter += 1; print(counter)", context=ctx)
218
+ # 使用完必须清理
219
+ sbx.destroy_context(ctx)
220
+ ```
221
+ 异步 API:
222
+ ```python
223
+ from scalebox.code_interpreter import AsyncSandbox
224
+
225
+ async def demo():
226
+ sbx = await AsyncSandbox.create()
227
+ ctx = await sbx.create_code_context(language="python", cwd="/tmp")
228
+ await sbx.run_code("counter = 0", context=ctx)
229
+ await sbx.run_code("counter += 1; print(counter)", context=ctx)
230
+ await sbx.destroy_context(ctx)
231
+ ```
232
+
233
+ ## 回调(可选)
234
+ ```python
235
+ from scalebox.code_interpreter import Sandbox
236
+ from scalebox.code_interpreter import OutputMessage, Result, ExecutionError
237
+
238
+ sbx = Sandbox.create()
239
+
240
+ def on_stdout(msg: OutputMessage):
241
+ print("STDOUT:", msg.content)
242
+
243
+ def on_stderr(msg: OutputMessage):
244
+ print("STDERR:", msg.content)
245
+
246
+ def on_result(res: Result):
247
+ print("RESULT formats:", list(res.formats()))
248
+
249
+ def on_error(err: ExecutionError):
250
+ print("ERROR:", err.name, err.value)
251
+
252
+ sbx.run_code(
253
+ "print('with callbacks')",
254
+ language="python",
255
+ on_stdout=on_stdout,
256
+ on_stderr=on_stderr,
257
+ on_result=on_result,
258
+ on_error=on_error,
259
+ )
260
+ ```
261
+
262
+ ## 结果格式(Result)
263
+ `Result` 可能包含如下数据字段:
264
+ - `text`, `html`, `markdown`, `svg`, `png`, `jpeg`, `pdf`, `latex`
265
+ - `json_data`, `javascript`, `data`, `chart`
266
+ - `execution_count`, `is_main_result`, `extra`
267
+
268
+ 可以通过 `list(result.formats())` 查看可用格式。
269
+
270
+ ## 运行测试
271
+ 项目 `test/` 目录包含全面的真实环境用例(非 unittest,直接脚本风格),覆盖:
272
+ - 同步与异步综合用例
273
+ - 多语言内核(Python、R、Node.js、Deno/TypeScript、Java/IJAVA、Bash)
274
+ - 上下文管理、回调与结果格式
275
+
276
+ 运行语法检查:
277
+ ```bash
278
+ cd test
279
+ python3 -m py_compile test_code_interpreter_sync_comprehensive.py
280
+ python3 -m py_compile test_code_interpreter_async_comprehensive.py
281
+ ```
282
+
283
+ 建议在虚拟环境中准备依赖并按需安装语言运行时(如 R、Node、Deno、JDK/IJAVA 等),确保各内核能够被后端执行。
284
+
285
+ ## 常见问题(Troubleshooting)
286
+ - Import/依赖错误:请确认已激活 venv 并正确安装 `scalebox/requirements.txt` 所需依赖
287
+ - `ModuleNotFoundError`:在测试脚本中添加项目根路径到 `sys.path`,或从项目根目录运行
288
+ - 外部内核不可用:确保环境已安装对应语言运行时(R/Node/Deno/JDK)与后端已启用该内核
289
+ - 超时/网络:检查网络与后端服务可达性,必要时增大 `timeout`/`request_timeout`
290
+
291
+ ## 许可证
292
+ 本项目遵循项目仓库所附许可证(LICENSE)条款。
@@ -0,0 +1,233 @@
1
+ # Scalebox Python SDK
2
+
3
+ 一个用于在可控沙箱中执行多语言代码的 Python SDK,支持同步与异步模式,以及多语言 Kernel(Python、R、Node.js、Deno/TypeScript、Java/IJAVA、Bash)。已提供全面的真实环境测试用例与脚本。
4
+
5
+ ## 功能特性
6
+ - 多语言内核:Python、R、Node.js、Deno/TypeScript、Java/IJAVA、Bash
7
+ - 同步 `Sandbox` 与异步 `AsyncSandbox` 执行
8
+ - 持久上下文:跨多次执行保留变量/状态
9
+ - 回调订阅:stdout、stderr、结果与错误
10
+ - 丰富结果格式:text、html、markdown、svg、png、jpeg、pdf、latex、json、javascript、chart、data 等
11
+ - 真实环境测试:覆盖同步/异步与多语言示例
12
+
13
+ ## 环境要求
14
+ - Python 3.12+
15
+ - 可访问的 Scalebox 环境或本地服务
16
+
17
+ ## 安装
18
+
19
+ ```bash
20
+ # 克隆项目
21
+ git clone https://github.com/scalebox-dev/scalebox-sdk-python.git
22
+ cd scalebox-sdk-python
23
+
24
+ # 建议使用虚拟环境
25
+ python3 -m venv venv
26
+ source venv/bin/activate
27
+
28
+ # 安装依赖
29
+ pip install -r scalebox/requirements.txt
30
+ ```
31
+
32
+ 如果你以源码方式直接使用包(非 pip 安装),请将 `scalebox` 目录加入 Python 路径或复制到 venv 的 site-packages:
33
+ ```bash
34
+ cp -r scalebox venv/lib/python3.12/site-packages/
35
+ ```
36
+
37
+ ## 配置
38
+ 支持从环境变量或 `.env` 文件读取凭据:
39
+
40
+ - `SBX_API_KEY` 或 `E2B_API_KEY`
41
+
42
+ 示例:
43
+ ```env
44
+ # .env
45
+ SBX_API_KEY=***
46
+ ```
47
+ 或:
48
+ ```bash
49
+ export SBX_API_KEY=***
50
+ ```
51
+
52
+ 可选:使用 `python-dotenv` 自动加载 `.env`:
53
+ ```bash
54
+ pip install python-dotenv
55
+ ```
56
+
57
+ ## 快速开始(同步)
58
+ ```python
59
+ from dotenv import load_dotenv; load_dotenv()
60
+ from scalebox.code_interpreter import Sandbox
61
+
62
+ sandbox = Sandbox.create() # 默认生存期 5 分钟
63
+ execution = sandbox.run_code("print('hello world')", language="python")
64
+ print(execution.logs.stdout)
65
+
66
+ files = sandbox.files.list("/")
67
+ print(files)
68
+ ```
69
+
70
+ ## 快速开始(异步)
71
+ ```python
72
+ import asyncio
73
+ from dotenv import load_dotenv; load_dotenv()
74
+ from scalebox.code_interpreter import AsyncSandbox
75
+
76
+ async def main():
77
+ sandbox = await AsyncSandbox.create()
78
+ exec_ = await sandbox.run_code("print('async hello')", language="python")
79
+ print(exec_.logs.stdout)
80
+
81
+ asyncio.run(main())
82
+ ```
83
+
84
+ ## 多语言示例
85
+ - Python:`language="python"`
86
+ - R:`language="r"`
87
+ - Node.js:`language="nodejs"`
88
+ - Deno/TypeScript:`language="typescript"`
89
+ - Java(IJAVA/纯Java):`language="ijava"` 或 `language="java"`
90
+ - Bash:`language="bash"`
91
+
92
+ 示例(Node.js):
93
+ ```python
94
+ from scalebox.code_interpreter import Sandbox
95
+ sbx = Sandbox.create()
96
+ code = """
97
+ console.log("Hello from Node.js!");
98
+ const x = 1 + 2; console.log(`x=${x}`);
99
+ """
100
+ result = sbx.run_code(code, language="nodejs")
101
+ print(result.logs.stdout)
102
+ ```
103
+
104
+ 示例(R):
105
+ ```python
106
+ from scalebox.code_interpreter import Sandbox
107
+ sbx = Sandbox.create()
108
+ code = """
109
+ print("Hello from R!")
110
+ x <- mean(c(1,2,3,4,5))
111
+ print(paste("mean:", x))
112
+ """
113
+ res = sbx.run_code(code, language="r")
114
+ print(res.logs.stdout)
115
+ ```
116
+
117
+ 示例(Deno/TypeScript):
118
+ ```python
119
+ from scalebox.code_interpreter import Sandbox
120
+ sbx = Sandbox.create()
121
+ ts = """
122
+ console.log("Hello from Deno/TypeScript!")
123
+ const nums: number[] = [1,2,3]
124
+ console.log(nums.reduce((a,b)=>a+b, 0))
125
+ """
126
+ res = sbx.run_code(ts, language="typescript")
127
+ print(res.logs.stdout)
128
+ ```
129
+
130
+ 示例(Java/IJAVA):
131
+ ```python
132
+ from scalebox.code_interpreter import Sandbox
133
+ sbx = Sandbox.create()
134
+ code = """
135
+ System.out.println("Hello from IJAVA!");
136
+ int a = 10, b = 20; System.out.println(a + b);
137
+ """
138
+ res = sbx.run_code(code, language="java")
139
+ print(res.logs.stdout)
140
+ ```
141
+
142
+ 示例(Bash):
143
+ ```python
144
+ from scalebox.code_interpreter import Sandbox
145
+ sbx = Sandbox.create()
146
+ res = sbx.run_code("echo 'Hello from Bash'", language="bash")
147
+ print(res.logs.stdout)
148
+ ```
149
+
150
+ ## 上下文管理(Context)
151
+ 上下文允许跨多次执行复用变量/状态:
152
+ ```python
153
+ from scalebox.code_interpreter import Sandbox
154
+ sbx = Sandbox.create()
155
+ ctx = sbx.create_code_context(language="python", cwd="/tmp")
156
+
157
+ sbx.run_code("counter = 0", context=ctx)
158
+ sbx.run_code("counter += 1; print(counter)", context=ctx)
159
+ # 使用完必须清理
160
+ sbx.destroy_context(ctx)
161
+ ```
162
+ 异步 API:
163
+ ```python
164
+ from scalebox.code_interpreter import AsyncSandbox
165
+
166
+ async def demo():
167
+ sbx = await AsyncSandbox.create()
168
+ ctx = await sbx.create_code_context(language="python", cwd="/tmp")
169
+ await sbx.run_code("counter = 0", context=ctx)
170
+ await sbx.run_code("counter += 1; print(counter)", context=ctx)
171
+ await sbx.destroy_context(ctx)
172
+ ```
173
+
174
+ ## 回调(可选)
175
+ ```python
176
+ from scalebox.code_interpreter import Sandbox
177
+ from scalebox.code_interpreter import OutputMessage, Result, ExecutionError
178
+
179
+ sbx = Sandbox.create()
180
+
181
+ def on_stdout(msg: OutputMessage):
182
+ print("STDOUT:", msg.content)
183
+
184
+ def on_stderr(msg: OutputMessage):
185
+ print("STDERR:", msg.content)
186
+
187
+ def on_result(res: Result):
188
+ print("RESULT formats:", list(res.formats()))
189
+
190
+ def on_error(err: ExecutionError):
191
+ print("ERROR:", err.name, err.value)
192
+
193
+ sbx.run_code(
194
+ "print('with callbacks')",
195
+ language="python",
196
+ on_stdout=on_stdout,
197
+ on_stderr=on_stderr,
198
+ on_result=on_result,
199
+ on_error=on_error,
200
+ )
201
+ ```
202
+
203
+ ## 结果格式(Result)
204
+ `Result` 可能包含如下数据字段:
205
+ - `text`, `html`, `markdown`, `svg`, `png`, `jpeg`, `pdf`, `latex`
206
+ - `json_data`, `javascript`, `data`, `chart`
207
+ - `execution_count`, `is_main_result`, `extra`
208
+
209
+ 可以通过 `list(result.formats())` 查看可用格式。
210
+
211
+ ## 运行测试
212
+ 项目 `test/` 目录包含全面的真实环境用例(非 unittest,直接脚本风格),覆盖:
213
+ - 同步与异步综合用例
214
+ - 多语言内核(Python、R、Node.js、Deno/TypeScript、Java/IJAVA、Bash)
215
+ - 上下文管理、回调与结果格式
216
+
217
+ 运行语法检查:
218
+ ```bash
219
+ cd test
220
+ python3 -m py_compile test_code_interpreter_sync_comprehensive.py
221
+ python3 -m py_compile test_code_interpreter_async_comprehensive.py
222
+ ```
223
+
224
+ 建议在虚拟环境中准备依赖并按需安装语言运行时(如 R、Node、Deno、JDK/IJAVA 等),确保各内核能够被后端执行。
225
+
226
+ ## 常见问题(Troubleshooting)
227
+ - Import/依赖错误:请确认已激活 venv 并正确安装 `scalebox/requirements.txt` 所需依赖
228
+ - `ModuleNotFoundError`:在测试脚本中添加项目根路径到 `sys.path`,或从项目根目录运行
229
+ - 外部内核不可用:确保环境已安装对应语言运行时(R/Node/Deno/JDK)与后端已启用该内核
230
+ - 超时/网络:检查网络与后端服务可达性,必要时增大 `timeout`/`request_timeout`
231
+
232
+ ## 许可证
233
+ 本项目遵循项目仓库所附许可证(LICENSE)条款。