{"record":{"id":"21600079e8be8be9","repo":"microsoft/autogen","slug":"functions-failed-to-load-exec-result-output-stri","errorCode":null,"errorMessage":"Functions failed to load: {exec_result.output.strip()}","messagePattern":"Functions failed to load: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py","lineNumber":261,"sourceCode":"\n            if self._available_packages is None:\n                await self._populate_available_packages(cancellation_token)\n\n            if self._available_packages is not None:\n                missing_pkgs = set(required_packages - self._available_packages)\n                if len(missing_pkgs) > 0:\n                    raise ValueError(f\"Packages unavailable in environment: {missing_pkgs}\")\n\n        func_file = self.work_dir / f\"{self._functions_module}.py\"\n        func_file.write_text(self._func_code)\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=self._func_code, language=\"python\")], cancellation_token\n        )\n\n        if exec_result.exit_code != 0:\n            raise ValueError(f\"Functions failed to load: {exec_result.output.strip()}\")\n\n        self._setup_functions_complete = True\n\n    async def _setup_cwd(self, cancellation_token: CancellationToken) -> None:\n        # Change the cwd to /mnt/data to properly have access to uploaded files\n        exec_result = await self._execute_code_dont_check_setup(\n            [CodeBlock(code=\"import os; os.chdir('/mnt/data')\", language=\"python\")], cancellation_token\n        )\n\n        if exec_result.exit_code != 0:\n            raise ValueError(\"Failed to set up Azure container working directory\")\n        self._setup_cwd_complete = True\n\n    async def get_file_list(self, cancellation_token: CancellationToken) -> List[str]:\n        self._ensure_access_token()\n        timeout = aiohttp.ClientTimeout(total=float(self._timeout))\n        headers = {\n            \"Authorization\": f\"Bearer {self._access_token}\",","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py#L243-L279","documentation":"Thrown by AzureContainerCodeExecutor._setup_functions when the generated functions module (built from the `functions` passed to the constructor) fails to execute inside the Azure container with a non-zero exit code. The executor pre-executes the function file to surface syntax errors, bad imports, or missing dependencies before the first real code block runs. The full stdout/stderr of that failed execution is embedded in the message.","triggerScenarios":"Constructing AzureContainerCodeExecutor with `functions=[...]` (or functions whose imports reference packages not installed), then calling execute_code_blocks for the first time. Any Python syntax error in a function body, an import of a package missing from `required_packages`, or a package unavailable in the container image triggers it. Also re-triggered after restart() resets _setup_functions_complete=False.","commonSituations":"Passing plain callables that import third-party libs (numpy, pandas) without listing them in each function's required_packages; a typo/syntax error in a decorated function; a package listed but not installable in the ACA sandbox (missing_pkgs check passed via pip install but import still failed, e.g. binary wheels unavailable).","solutions":["Read the embedded exec_result.output: it is the actual Python traceback (SyntaxError / ImportError / ModuleNotFoundError) from the container","Fix the offending function's code, or add missing imports to its `required_packages` list so the executor pip-installs them during setup","Verify each function compiles locally: `python -c \"import ast; ast.parse(open('functions.py').read())\"` or run the module in a clean venv matching the container image","If a package cannot install in the sandbox, vendor the dependency or use a custom container image that already includes it"],"exampleFix":"# before\nfrom autogen_ext.code_executors.azure import AzureContainerCodeExecutor\nexecutor = AzureContainerCodeExecutor(functions=[fn_that_imports_numpy])  # numpy never installed\n\n# after\nfrom autogen_ext.code_executors.azure import AzureContainerCodeExecutor\nfrom autogen_core.tools import FunctionTool\nexecutor = AzureContainerCodeExecutor(\n    functions=[(numpy_fn, [\"numpy\"])]  # declare required_packages so setup pip-installs numpy\n)","handlingStrategy":"validation","validationCode":"import ast\nfrom autogen_ext.code_executors.azure import AzureContainerCodeExecutor\n\ndef validate_functions(functions: list) -> None:\n    for fn in functions:\n        src = inspect.getsource(fn)\n        ast.parse(src)  # raises SyntaxError locally before the container does\n        imported = {n.split(\".\")[0] for node in ast.walk(ast.parse(src))\n                    if isinstance(node, ast.Import) for n in node.names} \\\n                 | {node.module.split(\".\")[0] for node in ast.walk(ast.parse(src))\n                    if isinstance(node, ast.ImportFrom) and node.module}\n        undeclared = imported - {m for f in functions for m in getattr(f, \"__required_packages__\", [])} - set(sys.stdlib_module_names)\n        if undeclared:\n            raise ValueError(f\"Declare required_packages for: {undeclared}\")","typeGuard":"def is_loadable_function(fn: Callable) -> bool:\n    try:\n        ast.parse(inspect.getsource(fn))\n        return True\n    except SyntaxError:\n        return False","tryCatchPattern":"try:\n    await executor.execute_code_blocks(blocks, ct)\nexcept ValueError as e:\n    if \"Functions failed to load\" in str(e):\n        # str(e) contains the container-side traceback; fix functions and rebuild executor\n        ...","preventionTips":["Compile every function locally with ast.parse before passing it to the constructor","Declare required_packages for every third-party import in each function","Smoke-test the functions module in a venv that mirrors the container image"],"tags":["azure","code-execution","docker","dependencies","functions"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}