agentscope-ai / agentscope-ai/agentscope-runtime

Replace string-executed runtime wrappers in MCPWrapper and wheel_packager

未关闭
#501 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
863
派生
168
PR 合并指标
30 天内没有已合并 PR

描述

This is not a security report, just a small runtime-maintainability note from a hermescheck pass.

I noticed two production wrapper paths that both build a command/function as a string and then execute that string at runtime:

- `src/agentscope_runtime/tools/mcp_wrapper.py` in `MCPWrapper.wrap()` -> inner `create_decorated_async_function()`: the wrapper body is assembled into `code = f"""..."""` and executed with `exec(code, namespace)` at line 184.
- `src/agentscope_runtime/engine/deployers/utils/wheel_packager.py` in `build_wheel()`: the generated `deploy_starter/main.py` ends up launching `cmd_str` with `subprocess.Popen(cmd_str, cwd=str(workdir), shell=True, env=env)` at line 298 of the generated starter source template.

Why this seems worth tightening:

- both paths are runtime-critical wrapper layers rather than one-off dev scripts;
- both depend on string assembly to preserve behavior that looks structurally expressible without string execution;
- it makes the execution path harder to reason about and test when debugging tool wrapping or deployment startup failures.

A narrow fix would be to replace these string-executed wrappers with structured callables/argv lists:

- in `mcp_wrapper.py`, build the async wrapper as a normal closure instead of emitting Python source and `exec`-ing it;
- in `wheel_packager.py`, normalize `CMD` into an argv list and launch it without `shell=True` in the generated starter.

A quick verification step after any refactor could just be:

```bash
rg -n "exec\(|shell=True" src/agentscope_runtime/tools/mcp_wrapper.py src/agentscope_runtime/engine/deployers/utils/wheel_packager.py
```

Project link for the scanner used here: https://github.com/huangrichao2020/hermescheck

Feel free to close this if this tradeoff is intentional or not useful.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。