From 0e3e602121aa83411e3748ef15377e2a93e1929c Mon Sep 17 00:00:00 2001 From: Jiaqing Liang Date: Fri, 17 Apr 2026 16:06:13 +0800 Subject: [PATCH] fix: inline_eval exec() exception escaping crash; update schema description --- assets/tools_schema.json | 2 +- assets/tools_schema_cn.json | 2 +- ga.py | 5 +++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/assets/tools_schema.json b/assets/tools_schema.json index 989ade3..4d91a26 100644 --- a/assets/tools_schema.json +++ b/assets/tools_schema.json @@ -7,7 +7,7 @@ "type": {"type": "string", "enum": ["python", "powershell"], "description": "Code type", "default": "python"}, "timeout": {"type": "integer", "description": "in seconds", "default": 60}, "cwd": {"type": "string", "description": "Working directory, defaults to cwd"}, - "inline_eval": {"type": "boolean", "description": "Only when usage is explicitly specified."}}} + "inline_eval": {"type": "boolean", "description": "DO NOT USE except explicitly specified."}}} }}, {"type": "function", "function": { "name": "file_read", diff --git a/assets/tools_schema_cn.json b/assets/tools_schema_cn.json index fbf729d..77e5eae 100644 --- a/assets/tools_schema_cn.json +++ b/assets/tools_schema_cn.json @@ -7,7 +7,7 @@ "type": {"type": "string", "enum": ["python", "powershell"], "description": "代码类型", "default": "python"}, "timeout": {"type": "integer", "description": "执行超时时间(秒)", "default": 60}, "cwd": {"type": "string", "description": "工作目录,默认为当前工作目录"}, - "inline_eval": {"type": "boolean", "description": "仅在明确要求时使用"}}} + "inline_eval": {"type": "boolean", "description": "不允许使用除非明确要求"}}} }}, {"type": "function", "function": { "name": "file_read", diff --git a/ga.py b/ga.py index 9e746c6..1ad9836 100644 --- a/ga.py +++ b/ga.py @@ -290,8 +290,9 @@ class GenericAgentHandler(BaseHandler): old_cwd = os.getcwd() try: os.chdir(cwd) - try: result = repr(eval(code, ns)) - except SyntaxError: exec(code, ns); result = ns.get('_r', 'OK') + try: + try: result = repr(eval(code, ns)) + except SyntaxError: exec(code, ns); result = ns.get('_r', 'OK') except Exception as e: result = f'Error: {e}' finally: os.chdir(old_cwd) else: result = yield from code_run(code, code_type, timeout, cwd, code_cwd=code_cwd, stop_signal=self.code_stop_signal)