Skip to content

Commit d42dc85

Browse files
committed
update doc
1 parent 444264a commit d42dc85

File tree

3 files changed

+248
-86
lines changed

3 files changed

+248
-86
lines changed

README.md

Lines changed: 64 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,21 @@
1515
<a href="https://github.com/modelscope/ms-enclave/pulls"><img src="https://img.shields.io/badge/PR-welcome-55EB99.svg"></a>
1616
<p>
1717

18-
## Overview
18+
## Introduction
1919

20-
ms-enclave is a modular and stable agent sandbox runtime environment that provides a secure isolated execution environment for applications. It achieves strong isolation through Docker containers, with accompanying local/HTTP managers and an extensible tool system, enabling you to safely and efficiently execute code in a controlled environment.
20+
ms-enclave is a modular and stable sandbox runtime environment that provides a secure isolated execution environment for applications. It implements strong isolation through Docker containers, equipped with local/HTTP managers and an extensible tool system, helping you execute code safely and efficiently in a controlled environment.
2121

22-
- 🔒 Secure Isolation: Full isolation and resource limitation based on Docker
23-
- 🧩 Modular: Extensible sandbox and tools (registration factory)
24-
- ⚡ Stable Performance: Simple implementation, fast startup, lifecycle management
22+
- 🔒 Secure Isolation: Complete isolation and resource limits based on Docker
23+
- 🧩 Modular: Both sandboxes and tools are extensible (registered factory)
24+
- ⚡ Stable Performance: Clean implementation, fast startup, with lifecycle management
2525
- 🌐 Remote Management: Built-in FastAPI service, supports HTTP management
2626
- 🔧 Tool System: Standardized tools enabled by sandbox type (OpenAI-style schema)
2727

2828
## System Requirements
2929

3030
- Python >= 3.10
3131
- Operating System: Linux, macOS, or Windows with Docker support
32-
- Docker daemon running locally (Notebook sandbox requires port 8888 open)
32+
- Docker daemon available on local machine (Notebook sandbox requires port 8888 open)
3333

3434
## Installation
3535

@@ -51,9 +51,9 @@ pip install -e .
5151
pip install -e '.[docker]'
5252
```
5353

54-
## Quick Start: Minimal Example (SandboxFactory)
54+
## Quick Start: Minimal Viable Example (SandboxFactory)
5555

56-
> Tools need to be explicitly enabled in the tools_config setting, otherwise they won't be registered.
56+
> Tools need to be explicitly enabled in the configured tools_config, otherwise they won't be registered.
5757
5858
```python
5959
import asyncio
@@ -72,7 +72,7 @@ async def main():
7272
)
7373

7474
async with SandboxFactory.create_sandbox(SandboxType.DOCKER, config) as sandbox:
75-
# 1) Write a file
75+
# 1) Write file
7676
await sandbox.execute_tool('file_operation', {
7777
'operation': 'write', 'file_path': '/sandbox/hello.txt', 'content': 'hi from enclave'
7878
})
@@ -87,20 +87,20 @@ asyncio.run(main())
8787

8888
---
8989

90-
## Typical Usage Scenarios and Examples
90+
## Typical Usage Patterns & Examples
9191

92-
- Directly using SandboxFactory: Create/destroy sandboxes in a single processlightweight; suitable for scripts or one-off tasks
93-
- Using LocalSandboxManager: Manage the lifecycle/cleanup of multiple sandboxes locally; suitable for service-oriented or multi-task parallel scenarios
94-
- Using HttpSandboxManager: Unified sandbox management through remote HTTP services; suitable for cross-machine/distributed or more isolated deployments
92+
- Direct use of SandboxFactory: Create/destroy sandboxes within a single process, most lightweight; suitable for scripts or one-time tasks
93+
- Using LocalSandboxManager: Uniformly orchestrate lifecycle/cleanup of multiple sandboxes on local machine; suitable for service-oriented, multi-task parallel scenarios
94+
- Using HttpSandboxManager: Manage sandboxes uniformly through remote HTTP service; suitable for cross-machine/distributed or stronger isolation deployments
9595

9696
### 1) Direct Sandbox Creation: SandboxFactory (Lightweight, Temporary)
9797

98-
Usage Scenarios:
98+
Use Cases:
9999

100-
- Temporarily execute code in scripts or microservices
101-
- Fine-grained control over sandbox lifecycle (cleanup upon context exit)
100+
- Temporarily run a piece of code in scripts or microservices
101+
- Fine-grained control over sandbox lifecycle (cleanup on context exit)
102102

103-
Example (Docker Sandbox + Python Execution):
103+
Example (Docker sandbox + Python execution):
104104

105105
```python
106106
import asyncio
@@ -120,12 +120,12 @@ async def main():
120120
asyncio.run(main())
121121
```
122122

123-
### 2) Local Unified Management: LocalSandboxManager (Multi-Sandbox, Lifecycle Management)
123+
### 2) Local Unified Orchestration: LocalSandboxManager (Multiple Sandboxes, Lifecycle Management)
124124

125-
Usage Scenarios:
125+
Use Cases:
126126

127-
- Create/manage multiple sandboxes within the same process (creation, query, stop, periodic cleanup)
128-
- Unified view for monitoring stats and health
127+
- Need to create/manage multiple sandboxes within the same process (create, query, stop, periodic cleanup)
128+
- Want unified status view, statistics, and health checks
129129

130130
Example:
131131

@@ -154,24 +154,24 @@ async def main():
154154
asyncio.run(main())
155155
```
156156

157-
### 3) Remote Unified Management: HttpSandboxManager (Cross-Machine/Isolated Deployment)
157+
### 3) Remote Unified Management: HttpSandboxManager (Cross-machine/Isolated Deployment)
158158

159-
Usage Scenarios:
159+
Use Cases:
160160

161-
- Run sandbox services on dedicated hosts/containers, invoke remotely via HTTP
162-
- Share a secure controlled sandbox cluster among multiple applications
161+
- Run sandbox service on a separate host/container, invoke remotely via HTTP
162+
- Multiple applications share a secure controlled sandbox cluster
163163

164-
Start the service (choose one):
164+
Start the service first (choose one):
165165

166166
```bash
167-
# Option A: Command line
167+
# Method A: Command line
168168
ms-enclave server --host 0.0.0.0 --port 8000
169169

170-
# Option B: Python script
170+
# Method B: Python startup
171171
python -c "from ms_enclave.sandbox import create_server; create_server().run(host='0.0.0.0', port=8000)"
172172
```
173173

174-
Client Example:
174+
Client example:
175175

176176
```python
177177
import asyncio
@@ -191,27 +191,28 @@ asyncio.run(main())
191191

192192
---
193193

194-
## Sandbox Types and Tool Support
194+
## Sandbox Types & Tool Support
195195

196-
Currently Supported Sandbox Types:
196+
Current built-in sandbox types:
197197

198-
- DOCKER (General-purpose container execution)
198+
- DOCKER (General container execution)
199199
- Supported tools:
200-
- python_executor (execute Python code)
201-
- shell_executor (execute Shell commands)
202-
- file_operation (read/write/delete/list files)
203-
- Features: Configurable memory/CPU limits, volume mounts, network toggling, privileged mode, port mapping
200+
- python_executor (Execute Python code)
201+
- shell_executor (Execute Shell commands)
202+
- file_operation (Read/write/delete/list files)
203+
- multi_code_executor (Multi-language code execution, supports python, cpp, csharp, go, java, nodejs, ts, rust, php, bash, pytest, jest, go_test, lua, r, perl, d_ut, ruby, scala, julia, kotlin_script, verilog, lean, swift, racket) Requires specifying image `volcengine/sandbox-fusion:server-20250609`
204+
- Features: Configurable memory/CPU limits, volume mounts, network toggle, privileged mode, port mapping
204205

205206
- DOCKER_NOTEBOOK (Jupyter Kernel Gateway environment)
206207
- Supported tools:
207-
- notebook_executor (execute code via Jupyter Kernel, supports context saving)
208-
- Note: This type only loads notebook_executor; other DOCKER-specific tools won't be enabled in this sandbox.
209-
- Dependencies: Requires port 8888 exposed and network enabled
208+
- notebook_executor (Execute code through Jupyter kernel, supports saving code context)
209+
- Note: This type only loads notebook_executor; other DOCKER-specific tools won't be enabled in this sandbox
210+
- Dependencies: Requires port 8888 exposed, network enabled
210211

211-
Tool Loading Rules:
212+
Tool loading rules:
212213

213-
- Tools are initialized and made available only when explicitly declared in `tools_config`.
214-
- Tools validate `required_sandbox_type`; unmatched types will be ignored automatically.
214+
- Tools are only initialized and available when explicitly declared in `tools_config`
215+
- Tools validate `required_sandbox_type`, automatically ignored if mismatched
215216

216217
Example:
217218

@@ -225,15 +226,14 @@ DockerNotebookConfig(tools_config={'notebook_executor': {}})
225226
## Common Configuration Options
226227

227228
- `image`: Docker image name (e.g., `python:3.11-slim` or `jupyter-kernel-gateway`)
228-
- `memory_limit`: Memory limit (e.g., `512m` / `1g`)
229-
- `cpu_limit`: CPU limit (float > 0)
230-
- `volumes`: Volume mounts, e.g., `{host_path: {"bind": "/container/path", "mode": "rw"}}`
231-
- `ports`: Port mappings, e.g., `{ "8888/tcp": ("127.0.0.1", 8888) }`
232-
- `network_enabled`: Enable network (Notebook sandbox requires True)
233-
- `remove_on_exit`: Automatically remove container on exit (default True)
229+
- `memory_limit`: Memory limit (e.g., `512m`/`1g`)
230+
- `cpu_limit`: CPU limit (float, >0)
231+
- `volumes`: Volume mounts, formatted as `{host_path: {"bind": "/container/path", "mode": "rw"}}`
232+
- `ports`: Port mapping, formatted as `{ "8888/tcp": ("127.0.0.1", 8888) }`
233+
- `network_enabled`: Whether to enable network (Notebook sandbox requires True)
234+
- `remove_on_exit`: Whether to delete container on exit (default True)
234235

235236
**Example of Installing Additional Dependencies in Sandbox**
236-
237237
```python
238238
async with SandboxFactory.create_sandbox(SandboxType.DOCKER, config) as sandbox:
239239
# 1) Write a file
@@ -252,8 +252,7 @@ async with SandboxFactory.create_sandbox(SandboxType.DOCKER, config) as sandbox:
252252
print(result_cli.stdout, flush=True)
253253
```
254254

255-
**Example of Reading and Writing Host Files in Sandbox**
256-
255+
**Example of Reading/Writing Host Files in Sandbox**
257256
```python
258257
async with LocalSandboxManager() as manager:
259258
# Create sandbox
@@ -271,68 +270,59 @@ async with LocalSandboxManager() as manager:
271270
)
272271
print(result.model_dump())
273272
```
273+
274274
---
275275

276-
## Error Handling and Debugging
276+
## Error Handling & Debugging
277277

278278
```python
279279
result = await sandbox.execute_tool('python_executor', {'code': 'print(1/0)'})
280280
if result.error:
281-
print('Error:', result.error)
281+
print('Error message:', result.error)
282282
else:
283283
print('Output:', result.output)
284284
```
285285

286286
---
287287

288-
## Development and Testing
288+
## Development & Testing
289289

290290
```bash
291-
# Clone the repository
291+
# Clone repository
292292
git clone https://github.com/modelscope/ms-enclave.git
293293
cd ms-enclave
294294

295-
# Setup virtual environment
296-
python -m venv venv
297-
source venv/bin/activate # Windows: venv\Scripts\activate
295+
# Create virtual environment
296+
conda create -n ms-enclave python=3.10 -y
297+
conda activate ms-enclave
298298

299299
# Install dependencies
300300
pip install -e ".[dev]"
301301

302302
# Run tests
303303
pytest
304304

305-
# Run examples (provided in the repository)
305+
# Run examples (provided in repository)
306306
python examples/sandbox_usage_examples.py
307307
python examples/local_manager_example.py
308308
python examples/server_manager_example.py
309309
```
310310

311311
---
312312

313-
## Available Tools
314-
315-
- `python_executor`: Execute Python code (DOCKER)
316-
- `shell_executor`: Execute Shell commands (DOCKER)
317-
- `file_operation`: Read/Write/Delete/List files (DOCKER)
318-
- `notebook_executor`: Execute via Jupyter Kernel (DOCKER_NOTEBOOK)
319-
- You can also register custom tools via the Tool factory (`@register_tool`).
320-
321-
---
322-
323-
## Contribution
313+
## Contributing
324314

325315
We welcome contributions! Please check [CONTRIBUTING.md](CONTRIBUTING.md) for details.
326316

327-
### Steps to Contribute
317+
### Contribution Steps
328318

329319
1. Fork the repository
330320
2. Create a feature branch: `git checkout -b feature/amazing-feature`
331321
3. Develop and add tests
332-
4. Run local tests: `pytest`
322+
4. Run tests locally: `pytest`
333323
5. Commit changes: `git commit -m 'Add amazing feature'`
334-
6. Push the branch: `git push origin feature/amazing-feature`
335-
7. Submit a Pull Request
324+
6. Push branch: `git push origin feature/amazing-feature`
325+
7. Submit Pull Request
336326

337327
## License
338328

README_zh.md

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ asyncio.run(main())
202202
- python_executor(执行 Python 代码)
203203
- shell_executor(执行 Shell 命令)
204204
- file_operation(读/写/删/列 文件)
205+
- multi_code_executor(多语言代码执行,支持 python, cpp, csharp, go, java, nodejs, ts, rust, php, bash, pytest, jest, go_test, lua, r, perl, d_ut, ruby, scala, julia, kotlin_script, verilog, lean, swift, racket)需要指定镜像 `volcengine/sandbox-fusion:server-20250609`
205206
- 特性:可配置内存/CPU 限制、卷挂载、网络开关、特权模式、端口映射
206207

207208
- DOCKER_NOTEBOOK(Jupyter Kernel Gateway 环境)
@@ -294,8 +295,8 @@ git clone https://github.com/modelscope/ms-enclave.git
294295
cd ms-enclave
295296

296297
# 创建虚拟环境
297-
python -m venv venv
298-
source venv/bin/activate # Windows: venv\Scripts\activate
298+
conda create -n ms-enclave python=3.10 -y
299+
conda activate ms-enclave
299300

300301
# 安装依赖
301302
pip install -e ".[dev]"
@@ -311,16 +312,6 @@ python examples/server_manager_example.py
311312

312313
---
313314

314-
## 可用工具一览
315-
316-
- `python_executor`:执行 Python 代码(DOCKER)
317-
- `shell_executor`:执行 Shell 命令(DOCKER)
318-
- `file_operation`:读/写/删/列 文件(DOCKER)
319-
- `notebook_executor`:在 Jupyter Kernel 中执行(DOCKER_NOTEBOOK)
320-
- 你也可以通过 Tool 工厂(`@register_tool`)注册自定义工具
321-
322-
---
323-
324315
## 贡献
325316

326317
我们欢迎贡献!请查看 [CONTRIBUTING.md](CONTRIBUTING.md) 了解详情。

0 commit comments

Comments
 (0)