Skip to content

Commit e68969e

Browse files
committed
Code Genesis supports shell script execution within a sandbox
1 parent 19a5e03 commit e68969e

6 files changed

Lines changed: 113 additions & 29 deletions

File tree

projects/code_genesis/README.md

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,15 @@ This project needs to be used together with ms-agent.
1919
cd ms-agent
2020
```
2121

22-
2. Prepare python environment (python>=3.10) with conda:
22+
2. Build the Docker sandbox image (requires Docker):
2323

2424
```shell
25-
conda create -n code_genesis python==3.11
26-
conda activate code_genesis
27-
pip install -r ./requirements.txt
25+
bash projects/code_genesis/tools/build_sandbox_image.sh
2826
```
2927

30-
3. Prepare npm environment, following https://nodejs.org/en/download. If you are using Mac, using Homebrew is recommended: https://formulae.brew.sh/formula/node
28+
This builds a `code-genesis-sandbox:version1` image containing Python 3.12, Node.js 20, npm, git and curl. All shell commands from the agents run inside this container for security isolation.
3129

32-
Make sure your installation is successful:
33-
34-
```shell
35-
npm --version
36-
```
37-
38-
Make sure the npm installation is successful, or the npm install/build/dev will fail and cause an infinite loop.
39-
40-
4. Run:
30+
3. Run:
4131

4232
```shell
4333
PYTHONPATH=. openai_api_key=your-api-key openai_base_url=your-api-url python ms_agent/cli/cli.py run --config projects/code_genesis --query 'make a demo website' --trust_remote_code true

projects/code_genesis/coding.yaml

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,10 @@ prompt:
103103
8. When fixing issues and updating files:
104104
Call the `edit_file` tool or `write_file` tool, after fixing issues there's no need to check by yourself, the lsp tool will check and report issues.
105105
106-
9. You can use the shell to debug problems:
106+
9. You can use the shell_executor to debug problems:
107107
108108
Example:
109-
# Find all fields of a class
110-
execute_single(command='python -c "from module import MyClass; print(vars(MyClass))"')
109+
shell_executor(command='python -c "from module import MyClass; print(vars(MyClass))"')
111110
112111
Your optimization goals:
113112
1. [Priority] Output the most accurate code implementation at once, without hallucinations or incorrect references.
@@ -128,8 +127,25 @@ tools:
128127
base_url: https://api.morphllm.com/v1
129128
plugins:
130129
- workflow/api_search
131-
shell:
130+
code_executor:
132131
mcp: false
132+
sandbox:
133+
mode: local
134+
type: docker_notebook
135+
image: code-genesis-sandbox:version1
136+
working_dir: /data
137+
timeout: 180
138+
memory_limit: "2g"
139+
cpu_limit: 2.0
140+
network_enabled: true
141+
tools_config:
142+
shell_executor: {}
143+
exclude:
144+
- notebook_executor
145+
- python_executor
146+
- file_operation
147+
- reset_executor
148+
- get_executor_info
133149

134150
pre_import_check: true
135151
post_import_check: true

projects/code_genesis/install.yaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ prompt:
3434
- Avoid installing development tools (like eslint, prettier) unless they are essential for the project to function
3535
- If the framework description states "No Framework" or "No external dependencies", do NOT create or install unnecessary dependencies
3636
37-
2. After writing dependency files (if needed), you should proactively call shell tools to install dependencies ONLY if:
37+
2. After writing dependency files (if needed), you should proactively call the shell_executor tool to install dependencies ONLY if:
3838
- The project has runtime dependencies that are required for execution
3939
- The project explicitly requires build tools or package managers
4040
- Do NOT install dependencies for simple vanilla web projects that can run without them
@@ -47,16 +47,30 @@ prompt:
4747
max_chat_round: 20
4848

4949
tools:
50-
shell:
50+
code_executor:
5151
mcp: false
52-
timeout: 180
52+
sandbox:
53+
mode: local
54+
type: docker_notebook
55+
image: code-genesis-sandbox:version1
56+
working_dir: /data
57+
timeout: 180
58+
memory_limit: "2g"
59+
cpu_limit: 2.0
60+
network_enabled: true
61+
tools_config:
62+
shell_executor: {}
63+
exclude:
64+
- notebook_executor
65+
- python_executor
66+
- file_operation
67+
- reset_executor
68+
- get_executor_info
5369

5470
file_system:
5571
mcp: false
5672
include:
5773
- read_file
5874
- write_file
5975

60-
tool_call_timeout: 120
61-
6276
help: |

projects/code_genesis/refine.yaml

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ prompt:
6161
* Compress the workspace subdirectory into a zip file and name it workspace.zip in the workspace_dir
6262
* Once the project is working, use the EdgeOne Pages MCP tools to deploy it
6363
* Follow the deployment documentation provided in the user message
64-
* When calling the deployment tool, first use the shell command `pwd` to get the current working directory path, then use "<current_path>/workspace.zip" as the builtFolderPath parameter
64+
* When calling the deployment tool, first use the shell_executor with command `pwd` to get the current working directory path, then use "<current_path>/workspace.zip" as the builtFolderPath parameter
6565
6666
5. If everything is OK, you may exit
6767
* Ignore warnings like unused variables; they don't affect runtime behavior
@@ -72,9 +72,25 @@ prompt:
7272
2. [Secondary] Use as few tokens as possible
7373
7474
tools:
75-
shell:
75+
code_executor:
7676
mcp: false
77-
timeout: 10
77+
sandbox:
78+
mode: local
79+
type: docker_notebook
80+
image: code-genesis-sandbox:version1
81+
working_dir: /data
82+
timeout: 180
83+
memory_limit: "2g"
84+
cpu_limit: 2.0
85+
network_enabled: true
86+
tools_config:
87+
shell_executor: {}
88+
exclude:
89+
- notebook_executor
90+
- python_executor
91+
- file_operation
92+
- reset_executor
93+
- get_executor_info
7894
file_system:
7995
mcp: false
8096
include:
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/bin/bash
2+
3+
# Build Docker sandbox image for code_genesis
4+
# Includes Python + Node.js for full-stack project support
5+
6+
set -e
7+
8+
IMAGE_NAME="code-genesis-sandbox"
9+
IMAGE_TAG="version1"
10+
11+
echo "Building code-genesis sandbox Docker image..."
12+
13+
docker pull python:3.12-slim
14+
15+
cat > Dockerfile.sandbox << 'EOF'
16+
FROM python:3.12-slim
17+
18+
# Install system dependencies and Node.js
19+
RUN apt-get update && apt-get install -y --no-install-recommends \
20+
curl \
21+
git \
22+
build-essential \
23+
&& curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
24+
&& apt-get install -y --no-install-recommends nodejs \
25+
&& apt-get clean && rm -rf /var/lib/apt/lists/*
26+
27+
# Install Jupyter kernel gateway (required by sandbox)
28+
RUN pip install --no-cache-dir \
29+
jupyter_kernel_gateway \
30+
jupyter_client \
31+
ipykernel
32+
33+
# Install Python kernel
34+
RUN python -m ipykernel install --sys-prefix --name python3 --display-name "Python 3"
35+
36+
WORKDIR /data
37+
38+
EXPOSE 8888
39+
CMD ["jupyter", "kernelgateway", "--KernelGatewayApp.ip=0.0.0.0", "--KernelGatewayApp.port=8888", "--KernelGatewayApp.allow_origin=*"]
40+
EOF
41+
42+
echo "Building Docker image: ${IMAGE_NAME}:${IMAGE_TAG}"
43+
docker build -f Dockerfile.sandbox -t "${IMAGE_NAME}:${IMAGE_TAG}" .
44+
45+
rm Dockerfile.sandbox
46+
47+
echo "Done: ${IMAGE_NAME}:${IMAGE_TAG}"
48+
echo "Contains: Python 3.12, Node.js 20, npm, git, curl"

projects/code_genesis/workflow/refine.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ async def run(self, messages, **kwargs):
107107
f'Tech stack (framework.txt): {framework}\n'
108108
f'Communication protocol (protocol.txt): {protocol}\n'
109109
f'File list:\n{file_info}\n'
110-
# f'Your shell tool workspace_dir is {self.output_dir}; '
111-
f'all tools should use this directory as the current working directory.\n'
110+
f'The shell_executor runs inside a Docker sandbox. '
111+
f'Project files are at the current working directory (/data). '
112+
f'All relative paths work directly.\n'
112113
f'When creating the deployment zip file, name it workspace.zip.\n'
113-
f'Python executable: {sys.executable}\n'
114114
f'Please refine the project and deploy it to EdgeOne Pages:'),
115115
]
116116
return await super().run(messages, **kwargs)

0 commit comments

Comments
 (0)