| タイトル | https://github.com/xlang-ai/ OpenAgents commit ff2e46440699af1324eb25655b622c4a131265bb Code Injection |
|---|
| 説明 | Data Agent default 'local' Python execution mode runs LLM-generated code unsandboxed
Affected version: confirmed on commit `ff2e46440699af1324eb25655b622c4a131265bb` (current default branch tip).
## Summary
The Data Agent's `"local"` Python execution mode runs LLM-generated code directly inside the Flask backend process via `IPython`'s `InteractiveShell.run_cell`, with no sandbox of any kind. This is the project's own documented default: `backend/app.py` sets `CODE_EXECUTION_MODE = os.getenv("CODE_EXECUTION_MODE", "local")`, and the shipped `docker-compose.yml` sets `CODE_EXECUTION_MODE=local` explicitly while leaving the sandboxed `code_interpreter` service entirely commented out (with the comment "Necessary if you want the code executed in sandbox" next to the disabled block). Anyone following the README's own `docker-compose up` instructions gets this unsandboxed configuration.
Separately, the `check_danger_code()` function in the same file, which is supposed to gate "unsafe" code in both execution modes, is non-functional: it always returns `is_safe=True` and an empty "dangerous packages" list regardless of code content, so no package/import filtering is ever applied in either mode.
## Details
`real_agents/data_agent/python/base.py` (`PythonChain._call`) extracts a Python code block from the LLM's completion and calls:
```python
repl = PythonEvaluator(
code_execution_mode=self.code_execution_mode,
jupyter_kernel_pool=self.jupyter_kernel_pool,
)
result = repl.run(code + f"\n{self.get_answer_expr}", user_id=self.user_id, chat_id=self.chat_id)
```
`real_agents/data_agent/evaluation/python_evaluator.py`'s `run()` dispatches on `code_execution_mode`, and `run_program_local()` executes the code in-process:
```python
shell = InteractiveShell.instance()
shell.enable_gui = lambda x: False
with capture_output() as captured:
ip = get_ipython()
code = "%matplotlib inline\n" + program
result = ip.run_cell(code)
```
There is no container, subprocess, or resource/network restriction here. `ip.run_cell` runs arbitrary Python with the same privileges as the backend process, which also holds `OPENAI_API_KEY` and other secrets in its environment, and has access to the `backend-data` volume shared across all users.
`docker-compose.yml` ships with:
```yaml
# Necessary if you want the code executed in sandbox
# code_interpreter:
# image: xlanglab/xlang-code-interpreter-python
...
environment:
...
- CODE_EXECUTION_MODE=local #if code_interpreter running set docker,else local
```
The `check_danger_code()` gate that both `run_program_local()` and `run_program_docker()` rely on to reject unsafe code is dead code:
```python
def check_danger_code(code):
code_line = []
for line in code.split("\n"):
if not line.startswith("%"):
code_line.append(line)
code = "\n".join(code_line)
def check_imports(code):
ast_failed = False
try:
tree = ast.parse(code)
except Exception as e:
ast_failed = str(e)
return ast_failed
return ast_failed
ast_failed = check_imports(code)
return True, ast_failed, []
```
`is_safe` is hardcoded `True`; the parsed AST is discarded without inspecting imports or calls. So even in `"docker"` mode, there is no package/import filtering, only whatever boundary the (disabled-by-default) container provides.
## Steps To Reproduce
(available upon request)
## Impact
In the project's default deployment configuration, any Data Agent chat turn that results in generated Python code (including code influenced by an uploaded/grounded data source the model echoes) executes with the full privileges of the backend process. This gives an attacker:
- Arbitrary code execution as the backend container/process.
- Access to `OPENAI_API_KEY` and any other secrets in that process's environment.
- Read/write access to `backend-data`, the volume shared by all users' uploaded files.
- A foothold for lateral movement to Redis, MongoDB, and the internal network from inside the backend container.
|
|---|
| ソース | ⚠️ https://github.com/xlang-ai/OpenAgents/issues/164 |
|---|
| ユーザー | carfeii (UID 97470) |
|---|
| 送信 | 2026年11月06日 18:03 (22 日 ago) |
|---|
| モデレーション | 2026年11月29日 03:36 (22 days later) |
|---|
| ステータス | 承諾済み |
|---|
| VulDBエントリ | 445145 [xlang-ai OpenAgents 迄 ff2e46440699af1324eb25655b622c4a131265bb Data Agent python_evaluator.py run_program_local 特権昇格] |
|---|
| ポイント | 20 |
|---|