myagent-ai 1.23.41 → 1.23.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/executor/engine.py +60 -0
- package/package.json +1 -1
package/executor/engine.py
CHANGED
|
@@ -268,6 +268,55 @@ class ExecutionEngine:
|
|
|
268
268
|
except Exception:
|
|
269
269
|
return True
|
|
270
270
|
|
|
271
|
+
def _check_self_run(self, code: str, work_dir: str) -> Optional[str]:
|
|
272
|
+
"""[v1.23.41] 自保护检查:阻止 Agent 启动 myagent 自身进程
|
|
273
|
+
|
|
274
|
+
检测模式:
|
|
275
|
+
1. 直接运行 main.py / main.pyc(python main.py, python3 main.py, ./main.py 等)
|
|
276
|
+
2. 通过 myagent-ai start 等命令启动服务
|
|
277
|
+
3. 运行 start.sh / start.js / start.ps1 等启动脚本
|
|
278
|
+
|
|
279
|
+
只在 work_dir 是 myagent 安装目录时拦截。
|
|
280
|
+
"""
|
|
281
|
+
import os
|
|
282
|
+
code_stripped = code.strip()
|
|
283
|
+
|
|
284
|
+
# 判断 work_dir 是否是 myagent 安装目录(包含 main.py + start.sh/js)
|
|
285
|
+
_is_myagent_dir = (
|
|
286
|
+
work_dir
|
|
287
|
+
and os.path.isfile(os.path.join(work_dir, "main.py"))
|
|
288
|
+
and (
|
|
289
|
+
os.path.isfile(os.path.join(work_dir, "start.sh"))
|
|
290
|
+
or os.path.isfile(os.path.join(work_dir, "start.js"))
|
|
291
|
+
)
|
|
292
|
+
)
|
|
293
|
+
if not _is_myagent_dir:
|
|
294
|
+
return None
|
|
295
|
+
|
|
296
|
+
# 模式 1: python/python3 main.py [args]
|
|
297
|
+
import re
|
|
298
|
+
if re.search(r'\b(?:python3?|\.\/)?\s*main\.py\b', code_stripped):
|
|
299
|
+
return (
|
|
300
|
+
"[自保护] 禁止启动 myagent 自身进程 (main.py)。"
|
|
301
|
+
"如果你需要测试 myagent 的功能,请使用 'myagent-ai' CLI 命令。"
|
|
302
|
+
"如果你在调试 myagent 项目代码,请直接测试具体的 Python 模块,"
|
|
303
|
+
"例如: python -c 'from agents.main_agent import MainAgent; print(MainAgent)'"
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
# 模式 2: myagent-ai start / start.sh / start.js
|
|
307
|
+
if re.search(r'\bmyagent-ai\s+(?:start|run|launch)\b', code_stripped):
|
|
308
|
+
return (
|
|
309
|
+
"[自保护] 禁止在 myagent 内部启动 myagent 服务。"
|
|
310
|
+
"myagent 服务已经在运行中,请勿重复启动。"
|
|
311
|
+
)
|
|
312
|
+
if re.search(r'\b(?:bash|sh|\.\/)?\s*start\.(?:sh|ps1|bat)\b', code_stripped):
|
|
313
|
+
return (
|
|
314
|
+
"[自保护] 禁止运行 myagent 启动脚本。"
|
|
315
|
+
"myagent 服务已经在运行中,请直接测试你需要的功能。"
|
|
316
|
+
)
|
|
317
|
+
|
|
318
|
+
return None
|
|
319
|
+
|
|
271
320
|
# ======================================================================
|
|
272
321
|
# 启动时一次性检测
|
|
273
322
|
# ======================================================================
|
|
@@ -534,6 +583,17 @@ class ExecutionEngine:
|
|
|
534
583
|
metadata={**metadata, "mode": self.execution_mode},
|
|
535
584
|
)
|
|
536
585
|
|
|
586
|
+
# [v1.23.41] 自保护检查:阻止 Agent 启动 myagent 自身进程
|
|
587
|
+
_self_check = self._check_self_run(code, work_dir)
|
|
588
|
+
if _self_check:
|
|
589
|
+
return ExecResult(
|
|
590
|
+
success=False,
|
|
591
|
+
error=_self_check,
|
|
592
|
+
language=language,
|
|
593
|
+
code=code,
|
|
594
|
+
metadata={**metadata, "mode": self.execution_mode, "self_protect": True},
|
|
595
|
+
)
|
|
596
|
+
|
|
537
597
|
self._execution_count += 1
|
|
538
598
|
exec_id = f"exec_{self._execution_count}"
|
|
539
599
|
|