{"record":{"id":"fbf2695bd781e3e4","repo":"microsoft/autogen","slug":"functions-failed-to-load-exec-result-output","errorCode":null,"errorMessage":"Functions failed to load: {exec_result.output}","messagePattern":"Functions failed to load: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py","lineNumber":283,"sourceCode":"\n            packages = shlex.join(required_packages)\n\n            result = await self._execute_code_dont_check_setup(\n                [CodeBlock(code=f\"python -m pip install {packages}\", language=\"sh\")], cancellation_token\n            )\n\n            if result.exit_code != 0:\n                stdout = result.output\n                stderr = result.output\n                raise ValueError(f\"Pip install failed. {stdout}, {stderr}\")\n\n        # Attempt to load the function file to check for syntax errors, imports etc.\n        exec_result = await self._execute_code_dont_check_setup(\n            [CodeBlock(code=func_file_content, language=\"python\")], cancellation_token\n        )\n\n        if exec_result.exit_code != 0:\n            raise ValueError(f\"Functions failed to load: {exec_result.output}\")\n\n        self._setup_functions_complete = True\n\n    async def _kill_running_command(self, command: List[str]) -> None:\n        if self._container is None or not self._running:\n            return\n        await asyncio.to_thread(self._container.exec_run, [\"pkill\", \"-f\", \" \".join(command)])\n\n    async def _execute_command(self, command: List[str], cancellation_token: CancellationToken) -> Tuple[str, int]:\n        if self._container is None or not self._running:\n            raise ValueError(\"Container is not running. Must first be started with either start or a context manager.\")\n\n        exec_task = asyncio.create_task(asyncio.to_thread(self._container.exec_run, command))\n        cancellation_token.link_future(exec_task)\n\n        # Wait for the exec task to finish.\n        try:\n            result = await exec_task","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/docker/_docker_code_executor.py#L265-L301","documentation":"Docker executor counterpart of the Azure 'Functions failed to load' error: during _setup_functions, the executor writes the generated functions module into the container and executes it; a non-zero exit raises this with the execution output. It surfaces syntax errors, bad imports, and runtime errors at module level in the provided functions.","triggerScenarios":"Constructing DockerCommandLineCodeExecutor(functions=[...]) and calling execute_code_blocks (setup runs lazily on first call, or after restart). Any function with a syntax error, an import of a package not listed in required_packages (or not in the image), or code with import-time side effects that fails will trigger it.","commonSituations":"Same as Azure: undeclared third-party imports; functions relying on host-only state (env vars, files) at import time; a package that installed but its binary import fails in the slim image (missing system libs like libgomp for numpy/opencv on python:3-slim).","solutions":["Read exec_result.output in the message — it is the traceback from inside the container","Declare the missing imports in the function's required_packages, or use an image that already has them","For binary wheels failing on slim images, switch the image (e.g. python:3 full) or apt-install system libs into a custom image","Test the generated functions module locally in a clean venv mirroring the image"],"exampleFix":"# before\nexecutor = DockerCommandLineCodeExecutor(functions=[load_csv])  # load_csv imports pandas undeclared\n\n# after\nexecutor = DockerCommandLineCodeExecutor(functions=[(load_csv, [\"pandas\"])])","handlingStrategy":"validation","validationCode":"import ast, sys\n\ndef check_function_imports(fn, declared: list[str]) -> list[str]:\n    tree = ast.parse(inspect.getsource(fn))\n    roots = set()\n    for node in ast.walk(tree):\n        if isinstance(node, ast.Import):\n            roots |= {a.name.split(\".\")[0] for a in node.names}\n        elif isinstance(node, ast.ImportFrom) and node.module:\n            roots.add(node.module.split(\".\")[0])\n    return sorted(roots - set(declared) - set(sys.stdlib_module_names))  # non-empty = will fail","typeGuard":"null","tryCatchPattern":"try:\n    await executor.execute_code_blocks(blocks, ct)\nexcept ValueError as e:\n    if \"Functions failed to load\" in str(e):\n        log.error(\"container traceback: %s\", e)\n        raise","preventionTips":["Declare required_packages for every third-party import in each function","Test functions in a container-matching venv before wiring them into the executor","Avoid import-time side effects (env vars, file reads) in executor functions"],"tags":["docker","code-execution","functions","dependencies"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}