ms-enclave 0.0.0__py3-none-any.whl → 0.0.1__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.
Potentially problematic release.
This version of ms-enclave might be problematic. Click here for more details.
- ms_enclave/__init__.py +2 -2
- ms_enclave/cli/__init__.py +1 -0
- ms_enclave/cli/base.py +20 -0
- ms_enclave/cli/cli.py +27 -0
- ms_enclave/cli/start_server.py +84 -0
- ms_enclave/sandbox/__init__.py +27 -0
- ms_enclave/sandbox/boxes/__init__.py +16 -0
- ms_enclave/sandbox/boxes/base.py +267 -0
- ms_enclave/sandbox/boxes/docker_notebook.py +216 -0
- ms_enclave/sandbox/boxes/docker_sandbox.py +252 -0
- ms_enclave/sandbox/manager/__init__.py +11 -0
- ms_enclave/sandbox/manager/base.py +155 -0
- ms_enclave/sandbox/manager/http_manager.py +405 -0
- ms_enclave/sandbox/manager/local_manager.py +295 -0
- ms_enclave/sandbox/model/__init__.py +21 -0
- ms_enclave/sandbox/model/base.py +36 -0
- ms_enclave/sandbox/model/config.py +97 -0
- ms_enclave/sandbox/model/requests.py +57 -0
- ms_enclave/sandbox/model/responses.py +57 -0
- ms_enclave/sandbox/server/__init__.py +0 -0
- ms_enclave/sandbox/server/server.py +195 -0
- ms_enclave/sandbox/tools/__init__.py +4 -0
- ms_enclave/sandbox/tools/base.py +95 -0
- ms_enclave/sandbox/tools/sandbox_tool.py +46 -0
- ms_enclave/sandbox/tools/sandbox_tools/__init__.py +4 -0
- ms_enclave/sandbox/tools/sandbox_tools/file_operation.py +215 -0
- ms_enclave/sandbox/tools/sandbox_tools/notebook_executor.py +167 -0
- ms_enclave/sandbox/tools/sandbox_tools/python_executor.py +87 -0
- ms_enclave/sandbox/tools/sandbox_tools/shell_executor.py +63 -0
- ms_enclave/sandbox/tools/tool_info.py +141 -0
- ms_enclave/utils/__init__.py +1 -0
- ms_enclave/utils/json_schema.py +208 -0
- ms_enclave/utils/logger.py +106 -0
- ms_enclave/version.py +2 -2
- ms_enclave-0.0.1.dist-info/METADATA +314 -0
- ms_enclave-0.0.1.dist-info/RECORD +40 -0
- {ms_enclave-0.0.0.dist-info → ms_enclave-0.0.1.dist-info}/WHEEL +1 -1
- ms_enclave-0.0.1.dist-info/entry_points.txt +2 -0
- ms_enclave/run_server.py +0 -21
- ms_enclave-0.0.0.dist-info/METADATA +0 -329
- ms_enclave-0.0.0.dist-info/RECORD +0 -8
- {ms_enclave-0.0.0.dist-info → ms_enclave-0.0.1.dist-info}/licenses/LICENSE +0 -0
- {ms_enclave-0.0.0.dist-info → ms_enclave-0.0.1.dist-info}/top_level.txt +0 -0
ms_enclave/run_server.py
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"""Server startup script."""
|
|
2
|
-
|
|
3
|
-
from ms_enclave.sandbox import create_server
|
|
4
|
-
from ms_enclave.utils import get_logger
|
|
5
|
-
|
|
6
|
-
logger = get_logger()
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def main():
|
|
10
|
-
"""Run the sandbox server."""
|
|
11
|
-
server = create_server(cleanup_interval=300) # 5 minutes
|
|
12
|
-
|
|
13
|
-
logger.info('Starting Sandbox Server...')
|
|
14
|
-
logger.info('API docs: http://localhost:8000/docs')
|
|
15
|
-
logger.info('Health check: http://localhost:8000/health')
|
|
16
|
-
|
|
17
|
-
server.run(host='0.0.0.0', port=8000, log_level='info')
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if __name__ == '__main__':
|
|
21
|
-
main()
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: ms-enclave
|
|
3
|
-
Version: 0.0.0
|
|
4
|
-
Summary: Modularized and Stable Sandbox runtime environment.
|
|
5
|
-
Author-email: ModelScope team <contact@modelscope.cn>
|
|
6
|
-
License-Expression: Apache-2.0
|
|
7
|
-
Project-URL: Homepage, https://github.com/modelscope/ms-enclave
|
|
8
|
-
Requires-Python: >=3.10
|
|
9
|
-
Description-Content-Type: text/markdown
|
|
10
|
-
License-File: LICENSE
|
|
11
|
-
Requires-Dist: fastapi>=0.104.0
|
|
12
|
-
Requires-Dist: uvicorn[standard]>=0.24.0
|
|
13
|
-
Requires-Dist: openai
|
|
14
|
-
Requires-Dist: pydantic>=2.11.7
|
|
15
|
-
Requires-Dist: requests>=2.32.4
|
|
16
|
-
Requires-Dist: shortuuid>=1.0.13
|
|
17
|
-
Requires-Dist: aiohttp>=3.8.1
|
|
18
|
-
Requires-Dist: docstring-parser
|
|
19
|
-
Provides-Extra: dev
|
|
20
|
-
Requires-Dist: pytest>=8.3.5; extra == "dev"
|
|
21
|
-
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
22
|
-
Requires-Dist: pre-commit>=4.2.0; extra == "dev"
|
|
23
|
-
Requires-Dist: jupyter-book>=1.0.4.post1; extra == "dev"
|
|
24
|
-
Requires-Dist: pytest-cov>=6.2.1; extra == "dev"
|
|
25
|
-
Provides-Extra: docker
|
|
26
|
-
Requires-Dist: docker>=7.1.0; extra == "docker"
|
|
27
|
-
Dynamic: license-file
|
|
28
|
-
|
|
29
|
-
# ms-enclave
|
|
30
|
-
|
|
31
|
-
Modularized and Stable Sandbox runtime environment
|
|
32
|
-
|
|
33
|
-
## Overview
|
|
34
|
-
|
|
35
|
-
ms-enclave is a modularized and stable sandbox runtime environment that provides secure isolated execution environments for applications. It supports multiple programming languages and frameworks, ensuring code runs safely in controlled environments with Docker-based containerization.
|
|
36
|
-
|
|
37
|
-
## Features
|
|
38
|
-
|
|
39
|
-
- 🔒 **Secure Isolation**: Complete isolation using Docker containers
|
|
40
|
-
- 🧩 **Modular Design**: Plugin-based architecture with extensible tools
|
|
41
|
-
- ⚡ **High Performance**: Optimized runtime performance with resource monitoring
|
|
42
|
-
- 🐍 **Python Support**: First-class Python code execution with persistent state
|
|
43
|
-
- 📊 **Resource Monitoring**: Real-time CPU, memory, and resource usage tracking
|
|
44
|
-
- 🛡️ **Security Policies**: Configurable security policies and permission control
|
|
45
|
-
- 🌐 **HTTP API**: RESTful API for remote sandbox management
|
|
46
|
-
- 🔧 **Tool System**: Extensible tool system for different execution environments
|
|
47
|
-
|
|
48
|
-
## Requirements
|
|
49
|
-
|
|
50
|
-
- Python >= 3.8
|
|
51
|
-
- Docker >= 20.0.0
|
|
52
|
-
- Operating System: Linux, macOS, or Windows with Docker support
|
|
53
|
-
|
|
54
|
-
## Installation
|
|
55
|
-
|
|
56
|
-
### Install from PyPI
|
|
57
|
-
|
|
58
|
-
```bash
|
|
59
|
-
pip install ms-enclave
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
### Install from Source
|
|
63
|
-
|
|
64
|
-
```bash
|
|
65
|
-
git clone https://github.com/your-username/ms-enclave.git
|
|
66
|
-
cd ms-enclave
|
|
67
|
-
pip install -e .
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
## Quick Start
|
|
71
|
-
|
|
72
|
-
### Basic Usage
|
|
73
|
-
|
|
74
|
-
```python
|
|
75
|
-
import asyncio
|
|
76
|
-
from ms_enclave.sandbox.boxes import SandboxFactory
|
|
77
|
-
from ms_enclave.sandbox.model import DockerSandboxConfig, SandboxType
|
|
78
|
-
|
|
79
|
-
async def main():
|
|
80
|
-
# Create Docker sandbox configuration
|
|
81
|
-
config = DockerSandboxConfig(
|
|
82
|
-
image='python:3.11-slim',
|
|
83
|
-
timeout=30,
|
|
84
|
-
memory_limit='512m',
|
|
85
|
-
tools_config={'python_executor': {}}
|
|
86
|
-
)
|
|
87
|
-
|
|
88
|
-
# Create and use sandbox with context manager
|
|
89
|
-
async with SandboxFactory.create_sandbox(SandboxType.DOCKER, config) as sandbox:
|
|
90
|
-
# Execute Python code
|
|
91
|
-
result = await sandbox.execute_tool('python_executor', {
|
|
92
|
-
'code': "print('Hello from sandbox!')\nresult = 2 + 2\nprint(f'2 + 2 = {result}')"
|
|
93
|
-
})
|
|
94
|
-
print(f'Result: {result.output}')
|
|
95
|
-
|
|
96
|
-
asyncio.run(main())
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
### HTTP Server Usage
|
|
100
|
-
|
|
101
|
-
```python
|
|
102
|
-
from ms_enclave.sandbox import create_server
|
|
103
|
-
|
|
104
|
-
# Start the sandbox server
|
|
105
|
-
server = create_server(cleanup_interval=300)
|
|
106
|
-
server.run(host='127.0.0.1', port=8000)
|
|
107
|
-
```
|
|
108
|
-
or
|
|
109
|
-
```shell
|
|
110
|
-
python -m ms_enclave.run_server
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### HTTP Manager Client
|
|
114
|
-
|
|
115
|
-
```python
|
|
116
|
-
import asyncio
|
|
117
|
-
from ms_enclave.sandbox.manager import HttpSandboxManager
|
|
118
|
-
from ms_enclave.sandbox.model import DockerSandboxConfig, SandboxType
|
|
119
|
-
|
|
120
|
-
async def main():
|
|
121
|
-
|
|
122
|
-
async with HttpSandboxManager(base_url='http://127.0.0.1:8000') as manager:
|
|
123
|
-
# Create sandbox
|
|
124
|
-
config = DockerSandboxConfig(image='python:3.11-slim', tools_config={'python_executor': {}})
|
|
125
|
-
sandbox_id = await manager.create_sandbox(SandboxType.DOCKER, config)
|
|
126
|
-
|
|
127
|
-
# Execute code
|
|
128
|
-
result = await manager.execute_tool(
|
|
129
|
-
sandbox_id, 'python_executor',
|
|
130
|
-
{'code': 'print("Hello from remote sandbox!")'}
|
|
131
|
-
)
|
|
132
|
-
print(result.model_dump())
|
|
133
|
-
|
|
134
|
-
asyncio.run(main())
|
|
135
|
-
```
|
|
136
|
-
|
|
137
|
-
## API Reference
|
|
138
|
-
|
|
139
|
-
### SandboxFactory
|
|
140
|
-
|
|
141
|
-
#### create_sandbox(sandbox_type, config)
|
|
142
|
-
|
|
143
|
-
Create a new sandbox instance.
|
|
144
|
-
|
|
145
|
-
```python
|
|
146
|
-
sandbox = SandboxFactory.create_sandbox(SandboxType.DOCKER, config)
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
### Sandbox Methods
|
|
150
|
-
|
|
151
|
-
#### execute_tool(tool_name, parameters)
|
|
152
|
-
|
|
153
|
-
Execute a tool within the sandbox.
|
|
154
|
-
|
|
155
|
-
```python
|
|
156
|
-
result = await sandbox.execute_tool('python_executor', {
|
|
157
|
-
'code': 'print("Hello World")',
|
|
158
|
-
'timeout': 30
|
|
159
|
-
})
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
#### get_available_tools()
|
|
163
|
-
|
|
164
|
-
Get list of available tools.
|
|
165
|
-
|
|
166
|
-
```python
|
|
167
|
-
tools = sandbox.get_available_tools()
|
|
168
|
-
```
|
|
169
|
-
|
|
170
|
-
#### start() / stop() / cleanup()
|
|
171
|
-
|
|
172
|
-
Manage sandbox lifecycle.
|
|
173
|
-
|
|
174
|
-
```python
|
|
175
|
-
await sandbox.start()
|
|
176
|
-
await sandbox.stop()
|
|
177
|
-
await sandbox.cleanup()
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### HttpSandboxManager
|
|
181
|
-
|
|
182
|
-
Remote sandbox management via HTTP API.
|
|
183
|
-
|
|
184
|
-
#### create_sandbox(sandbox_type, config)
|
|
185
|
-
|
|
186
|
-
```python
|
|
187
|
-
sandbox_id = await manager.create_sandbox(SandboxType.DOCKER, config)
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
#### execute_tool(sandbox_id, tool_name, parameters)
|
|
191
|
-
|
|
192
|
-
```python
|
|
193
|
-
result = await manager.execute_tool(sandbox_id, 'python_executor', params)
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
#### list_sandboxes(status_filter=None)
|
|
197
|
-
|
|
198
|
-
```python
|
|
199
|
-
sandboxes = await manager.list_sandboxes()
|
|
200
|
-
```
|
|
201
|
-
|
|
202
|
-
## Examples
|
|
203
|
-
|
|
204
|
-
### Advanced Python Execution
|
|
205
|
-
|
|
206
|
-
```python
|
|
207
|
-
async def advanced_example():
|
|
208
|
-
config = DockerSandboxConfig(
|
|
209
|
-
image='python:3.11-slim',
|
|
210
|
-
tools_config={'python_executor': {}},
|
|
211
|
-
memory_limit='1g'
|
|
212
|
-
)
|
|
213
|
-
|
|
214
|
-
async with SandboxFactory.create_sandbox(SandboxType.DOCKER, config) as sandbox:
|
|
215
|
-
# Data processing example
|
|
216
|
-
code = '''
|
|
217
|
-
import json
|
|
218
|
-
import statistics
|
|
219
|
-
|
|
220
|
-
data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
|
|
221
|
-
result = {
|
|
222
|
-
"mean": statistics.mean(data),
|
|
223
|
-
"median": statistics.median(data),
|
|
224
|
-
"stdev": statistics.stdev(data)
|
|
225
|
-
}
|
|
226
|
-
print(json.dumps(result, indent=2))
|
|
227
|
-
'''
|
|
228
|
-
|
|
229
|
-
result = await sandbox.execute_tool('python_executor', {'code': code})
|
|
230
|
-
print(result.output)
|
|
231
|
-
```
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
### Error Handling
|
|
235
|
-
|
|
236
|
-
```python
|
|
237
|
-
async def error_handling_example():
|
|
238
|
-
config = DockerSandboxConfig(
|
|
239
|
-
image='python:3.11-slim',
|
|
240
|
-
tools_config={'python_executor': {}},
|
|
241
|
-
timeout=5
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
async with SandboxFactory.create_sandbox(SandboxType.DOCKER, config) as sandbox:
|
|
245
|
-
# Handle syntax errors
|
|
246
|
-
result = await sandbox.execute_tool('python_executor', {
|
|
247
|
-
'code': 'print("Missing quote'
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
if result.error:
|
|
251
|
-
print(f"Error: {result.error}")
|
|
252
|
-
else:
|
|
253
|
-
print(f"Output: {result.output}")
|
|
254
|
-
```
|
|
255
|
-
|
|
256
|
-
## Development
|
|
257
|
-
|
|
258
|
-
### Local Development Setup
|
|
259
|
-
|
|
260
|
-
```bash
|
|
261
|
-
# Clone the repository
|
|
262
|
-
git clone https://github.com/your-username/ms-enclave.git
|
|
263
|
-
cd ms-enclave
|
|
264
|
-
|
|
265
|
-
# Create virtual environment
|
|
266
|
-
python -m venv venv
|
|
267
|
-
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
268
|
-
|
|
269
|
-
# Install dependencies
|
|
270
|
-
pip install -e ".[dev]"
|
|
271
|
-
|
|
272
|
-
# Run tests
|
|
273
|
-
pytest
|
|
274
|
-
|
|
275
|
-
# Run examples
|
|
276
|
-
python examples/usage_examples.py
|
|
277
|
-
python examples/server_example.py
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
### Running Tests
|
|
282
|
-
|
|
283
|
-
```bash
|
|
284
|
-
# Run all tests
|
|
285
|
-
pytest
|
|
286
|
-
|
|
287
|
-
# Run with coverage
|
|
288
|
-
pytest --cov=ms_enclave
|
|
289
|
-
|
|
290
|
-
# Run specific test file
|
|
291
|
-
pytest tests/test_sandbox.py
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
## Tools
|
|
295
|
-
|
|
296
|
-
### Python Executor
|
|
297
|
-
|
|
298
|
-
Execute Python code with persistent state across multiple calls.
|
|
299
|
-
|
|
300
|
-
```python
|
|
301
|
-
result = await sandbox.execute_tool('python_executor', {
|
|
302
|
-
'code': 'x = 42\nprint(f"Value: {x}")',
|
|
303
|
-
'timeout': 30
|
|
304
|
-
})
|
|
305
|
-
```
|
|
306
|
-
|
|
307
|
-
### Available Tools
|
|
308
|
-
|
|
309
|
-
- `python_executor`: Execute Python code
|
|
310
|
-
- `bash`: Execute bash commands
|
|
311
|
-
- Custom tools can be added via the tool factory system
|
|
312
|
-
|
|
313
|
-
## Contributing
|
|
314
|
-
|
|
315
|
-
We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.
|
|
316
|
-
|
|
317
|
-
### Contributing Steps
|
|
318
|
-
|
|
319
|
-
1. Fork the repository
|
|
320
|
-
2. Create a feature branch: `git checkout -b feature/amazing-feature`
|
|
321
|
-
3. Make your changes and add tests
|
|
322
|
-
4. Run tests: `pytest`
|
|
323
|
-
5. Commit changes: `git commit -m 'Add amazing feature'`
|
|
324
|
-
6. Push to branch: `git push origin feature/amazing-feature`
|
|
325
|
-
7. Submit a Pull Request
|
|
326
|
-
|
|
327
|
-
## License
|
|
328
|
-
|
|
329
|
-
This project is licensed under the MIT License. See [LICENSE](LICENSE) file for details.
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
ms_enclave/__init__.py,sha256=r39l09GDYXaFM_s8YC-n-0W3YsK0YhFWBVCFRARFL_8,60
|
|
2
|
-
ms_enclave/run_server.py,sha256=gWYluCQ-xGHS0R4TDz4De0v_mMJpuJxQ8cj-z5L-AXU,514
|
|
3
|
-
ms_enclave/version.py,sha256=2aSJkcDtd3ZTHF6jCbx-_Xc_MjPIDebYAr9LLXBXFx8,62
|
|
4
|
-
ms_enclave-0.0.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
ms_enclave-0.0.0.dist-info/METADATA,sha256=xt-MSW14e3vcBj45bT7eSA2y51iFcl9f9w2LE7lq8qA,7974
|
|
6
|
-
ms_enclave-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
7
|
-
ms_enclave-0.0.0.dist-info/top_level.txt,sha256=V_Q9rBOF-RGwACDP9ppukoyjaOtpjdht7dhe7StS86A,11
|
|
8
|
-
ms_enclave-0.0.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|