{"record":{"id":"0a28eba470b63bfa","repo":"jd-opensource/joyagent-jdgenie","slug":"error-msg","errorCode":null,"errorMessage":"{error_msg}","messagePattern":"\\{error_msg\\}","errorType":"exception","errorClass":"AgentExecutionError","httpStatus":null,"severity":"error","filePath":"genie-tool/genie_tool/tool/ci_agent.py","lineNumber":197,"sourceCode":"            ):\n                execution_logs = str(self.python_executor.state[\"_print_outputs\"])\n                if len(execution_logs) > 0:\n                    execution_outputs_console = [\n                        Text(\"Execution logs:\", style=\"bold\"),\n                        Text(execution_logs),\n                    ]\n                    memory_step.observations = \"Execution logs:\\n\" + execution_logs\n                    self.logger.log(\n                        Group(*execution_outputs_console), level=LogLevel.INFO\n                    )\n            error_msg = str(e)\n\n            if \"Import of \" in error_msg and \" is not allowed\" in error_msg:\n                self.logger.log(\n                    \"[bold red]Warning to user: Code execution failed due to an unauthorized import - Consider passing said import under `additional_authorized_imports` when initializing your CodeAgent.\",\n                    level=LogLevel.INFO,\n                )\n            raise AgentExecutionError(error_msg, self.logger)\n\n        memory_step.observations = observation\n\n        finalObj = FinalAnswerCheck(\n            input_messages=self.input_messages,\n            execution_logs=execution_logs,\n            model=self.model,\n            task=self.task,\n            prompt_temps=self.prompt_templates,\n            memory_step=memory_step,\n            grammar=self.grammar,\n            request_id=f\"{model_request_id}-final\",\n        )\n        finalFlag, exeLog = finalObj.check_is_final_answer()\n        self.logger.log(Group(*execution_outputs_console), level=LogLevel.INFO)\n        # self.logger.log(f\"check finalanswer 已完成 {finalFlag}  {str(exeLog)}\")\n        memory_step.action_output = exeLog\n","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/jd-opensource/joyagent-jdgenie/blob/2417e0b8b636d941ad5fb14c59b20dddfef5375d/genie-tool/genie_tool/tool/ci_agent.py#L179-L215","documentation":"smolagents-style CodeAgent raises AgentExecutionError in _step_stream when executing the generated code in the sandbox fails (runtime exception in the model-written Python, tool error, or forbidden import). The sandbox error message is passed through verbatim.","triggerScenarios":"Any exception raised while running the model-generated code via the python interpreter (sandboxed_executor/execute_python_code), including unauthorized imports detected by the sandbox (\"Import of X is not allowed\").","commonSituations":"Model writes code calling libraries not in additional_authorized_imports; generated code hits NameError/ZeroDivisionError; sandbox lacks packages the model assumed (requests, pandas); model calls undefined functions.","solutions":["Read the wrapped error_msg to see the actual sandbox exception and fix the model prompt or the code","Pass additional_authorized_imports=[...] to CodeAgent when the model legitimately needs imports like requests or numpy","Add the failing packages to the execution environment the sandbox uses","Increase max_iterations / improve the system prompt so the agent can self-correct on execution failures"],"exampleFix":"# before\nagent = CodeAgent(tools=[python_interpreter])\n# model code 'import requests' -> AgentExecutionError: Import of requests is not allowed\n# after\nagent = CodeAgent(tools=[python_interpreter], additional_authorized_imports=[\"requests\"])","handlingStrategy":"try-catch","validationCode":"authorized = {\"os\", \"math\"} | set(additional_authorized_imports)\nimports = set(re.findall(r'^\\s*(?:import|from)\\s+(\\w+)', generated_code, re.M))\nmissing = imports - authorized  # pass missing into additional_authorized_imports first","typeGuard":null,"tryCatchPattern":"from smolagents import AgentExecutionError\ntry:\n    result = agent.run(task)\nexcept AgentExecutionError as e:\n    if 'is not allowed' in str(e):\n        agent.authorized_imports += [extracted_module]\n    logger.warning('execution failed: %s', e)","preventionTips":["List all needed modules in additional_authorized_imports at init","Ensure sandbox image has required packages installed","Review execution_logs after each run to catch recurring failures","Improve prompts so generated code handles exceptions itself"],"tags":["llm","code-execution","sandbox"],"backgroundTag":"api-error-response","analyzedSha":"2417e0b8b636d941ad5fb14c59b20dddfef5375d","analyzedAt":"2026-09-08T11:28:19.414Z","contentChangedAt":"2026-09-08T11:28:19.414Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}