{"record":{"id":"57aebdb50e20ead0","repo":"zylon-ai/private-gpt","slug":"code-execution-failed-message","errorCode":null,"errorMessage":"Code execution failed: {message}","messagePattern":"Code execution failed: (.+?)","errorType":"exception","errorClass":"CodeExecutionError","httpStatus":null,"severity":"error","filePath":"private_gpt/components/tabular/pandasai_sandbox.py","lineNumber":302,"sourceCode":"                )\n\n            processed_code = self._prepare_code_for_execution(code)\n            full_code = \"\\n\\n\".join(\n                part for part in (self._PREAMBLE, datasets_code, processed_code) if part\n            )\n\n            execution_result = self._run(\n                self._client.run_code(\n                    full_code,\n                    SandboxCodeOptions(language=\"python\", timeout=self._timeout),\n                )\n            )\n            return self._process_execution_result(execution_result)\n\n        except Exception as e:\n            message = get_clean_exception_info(e)\n            logger.debug(\"Code execution failed: %s\", message)\n            raise CodeExecutionError(f\"Code execution failed: {message}\")  # noqa: B904\n\n    def _process_sql_queries(\n        self, sql_queries: list[str], environment: dict[str, Any]\n    ) -> tuple[str, list[Exception]]:\n        if not sql_queries:\n            return \"\", []\n\n        temp_dir = f\"/tmp/{self._user_id}\"\n        datasets_map: dict[str, str] = {}\n        exceptions: list[Exception] = []\n\n        for sql_query in sql_queries:\n            execute_sql_query_func = environment.get(\"execute_sql_query\")\n            if execute_sql_query_func is None:\n                logger.warning(\"execute_sql_query function not found in environment\")\n                continue\n\n            try:","sourceCodeStart":284,"sourceCodeEnd":320,"githubUrl":"https://github.com/zylon-ai/private-gpt/blob/4a030776a31a901ad80b1bf4d7faa2c1a367efbb/private_gpt/components/tabular/pandasai_sandbox.py#L284-L320","documentation":"The outer catch-all of _exec_code(): any exception during remote code execution — SQL pre-processing, code preparation, or self._client.run_code — is cleaned via get_clean_exception_info and re-raised as a pandasai CodeExecutionError. The '# noqa: B904' marks an intentional missing 'from e'. The interpolated message is the cleaned traceback of the underlying failure, frequently the user's generated Python erroring inside the sandbox.","triggerScenarios":"Generated Python raises at runtime in the remote sandbox (NameError, KeyError, pandas errors); the sandbox times out (SandboxCodeOptions timeout=self._timeout); transport errors from _client.run_code; chained from the SQL-preprocess ValueError at line 281.","commonSituations":"LLM-generated code referencing columns that do not exist in the dataframe; long-running analysis exceeding the configured sandbox timeout; network blips between app and sandbox; incompatible library versions inside the sandbox vs. what the generated code assumes.","solutions":["Read the embedded cleaned traceback — it pinpoints the exact line of generated code that failed.","For timeout: raise the sandbox timeout configuration for the adapter.","For code errors: retry the analysis; add corrective feedback (the error text) into the follow-up prompt so the LLM fixes its code.","For recurring schema mistakes: enrich the dataframe description passed to PandasAI.","For transport errors: verify sandbox service health and retry once."],"exampleFix":"# before\noutput = sandbox._exec_code(code, env)\n\n# after\nfrom pandasai.exceptions import CodeExecutionError\n\ntry:\n    output = sandbox._exec_code(code, env)\nexcept CodeExecutionError as e:\n    logger.warning(\"Generated code failed once, retrying with feedback: %s\", e)\n    code_v2 = regenerate_with_error_feedback(code, str(e))\n    output = sandbox._exec_code(code_v2, env)","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"from pandasai.exceptions import CodeExecutionError\n\ntry:\n    out = sandbox._exec_code(code, env)\nexcept CodeExecutionError as e:\n    out = sandbox._exec_code(regenerate_with_feedback(code, str(e)), env)","preventionTips":["Feed the cleaned traceback back to the LLM for self-correction","Set a sandbox timeout comfortably above worst-case analysis time","Keep sandbox library versions aligned with what generated code assumes"],"tags":["sandbox","code-execution","llm-output","wrapper-exception","timeout"],"backgroundTag":null,"analyzedSha":"4a030776a31a901ad80b1bf4d7faa2c1a367efbb","analyzedAt":"2026-08-15T03:51:26.951Z","schemaVersion":2},"datasetVersion":"2026-08-16T03:17:38.424Z"}