fix: inline_eval exec() exception escaping crash; update schema description
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
5
ga.py
5
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)
|
||||
|
||||
Reference in New Issue
Block a user