agentscope-ai / agentscope-ai/agentscope-runtime

Replace string-executed runtime wrappers in MCPWrapper and wheel_packager

Aperta
#501 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
863
Fork
168
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.