{"record":{"id":"1159c40480b3c83e","repo":"microsoft/autogen","slug":"failed-to-set-up-azure-container-working-directory","errorCode":null,"errorMessage":"Failed to set up Azure container working directory","messagePattern":"Failed to set up Azure container working directory","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":272,"sourceCode":"\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}\",\n        }\n        url = self._construct_url(\"files\")\n        async with aiohttp.ClientSession(timeout=timeout) as client:\n            task = asyncio.create_task(\n                client.get(\n                    url,\n                    headers=headers,\n                )\n            )\n            cancellation_token.link_future(task)\n            try:","sourceCodeStart":254,"sourceCodeEnd":290,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/code_executors/azure/_azure_container_code_executor.py#L254-L290","documentation":"Thrown by AzureContainerCodeExecutor._setup_cwd when the bootstrap snippet `import os; os.chdir('/mnt/data')` returns a non-zero exit code inside the Azure container session. This step runs on first execution so that code can access uploaded files. A non-zero exit almost always means the session is unhealthy or /mnt/data does not exist in the container.","triggerScenarios":"First execute_code_blocks call after constructing the executor (or after restart()), where the ACA code session cannot execute the chdir: the session endpoint returned an error, the access token expired and the exec call failed, or the container image lacks the /mnt/data mount provided by default Azure Container Apps sessions.","commonSituations":"Using a custom container image or non-standard Azure Container Apps session pool where /mnt/data is not provisioned; a transient/blanked session (idle timeout) causing exec failures on first use; misconfigured DefaultAzureCredential yielding an invalid token so the exec call fails.","solutions":["Retry the execution: transient session-start failures on first use often succeed on a second call, which re-runs setup","Call restart() to force a brand-new session id, then retry","If using a custom image/session pool, ensure /mnt/data exists (create it in the Dockerfile) or is mounted by the session pool config","Check that DefaultAzureCredential used by the executor is valid and has the ACASessions roles assigned, since exec failures surface as non-zero exit"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try:\n    result = await executor.execute_code_blocks(blocks, ct)\nexcept ValueError as e:\n    if \"working directory\" in str(e):\n        await executor.restart()  # new session re-runs _setup_cwd\n        result = await executor.execute_code_blocks(blocks, ct)","preventionTips":["Create the executor per task rather than holding it indefinitely","Call restart() when reusing an executor after long idle periods so setup re-runs on a fresh session","If using a custom image, ensure /mnt/data exists in it"],"tags":["azure","code-execution","session","filesystem"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}