{"record":{"id":"1996815227d133ef","repo":"infiniflow/ragflow","slug":"directory-creation-failed-stderr","errorCode":null,"errorMessage":"Directory creation failed: {stderr}","messagePattern":"Directory creation failed: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"agent/sandbox/executor_manager/services/execution.py","lineNumber":231,"sourceCode":"        bundle = _build_execution_bundle(req, workdir)\n        code_name = str(bundle[\"code_name\"])\n        runner_name = str(bundle[\"runner_name\"])\n\n        code_path = os.path.join(workdir, code_name)\n        with open(code_path, \"wb\") as f:\n            f.write(bundle[\"code_bytes\"])\n\n        runner_path = os.path.join(workdir, runner_name)\n        with open(runner_path, \"w\", encoding=\"utf-8\") as f:\n            f.write(str(bundle[\"runner_source\"]))\n\n        args_path = os.path.join(workdir, str(bundle[\"args_name\"]))\n        with open(args_path, \"w\", encoding=\"utf-8\") as f:\n            f.write(str(bundle[\"args_source\"]))\n\n        returncode, _, stderr = await async_run_command(\"docker\", \"exec\", container, \"mkdir\", \"-p\", f\"/workspace/{task_id}\", timeout=5)\n        if returncode != 0:\n            raise RuntimeError(f\"Directory creation failed: {stderr}\")\n\n        tar_proc = await asyncio.create_subprocess_exec(\"tar\", \"czf\", \"-\", \"-C\", workdir, code_name, runner_name, str(bundle[\"args_name\"]), stdout=asyncio.subprocess.PIPE)\n        tar_stdout, _ = await tar_proc.communicate()\n\n        docker_proc = await asyncio.create_subprocess_exec(\n            \"docker\", \"exec\", \"-i\", container, \"tar\", \"xzf\", \"-\", \"-C\", f\"/workspace/{task_id}\", stdin=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE\n        )\n        stdout, stderr = await docker_proc.communicate(input=tar_stdout)\n\n        if docker_proc.returncode != 0:\n            raise RuntimeError(stderr.decode())\n\n        start_time = time.time()\n        try:\n            arguments = req.arguments or {}\n            logger.info(\"Passed in args keys=%s size_bytes=%s\", list(arguments.keys()), len(json.dumps(arguments, ensure_ascii=False).encode(\"utf-8\")))\n            run_args = _build_container_run_args(language=language, task_id=task_id, container=container, runner_name=runner_name)\n","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/agent/sandbox/executor_manager/services/execution.py#L213-L249","documentation":"Raised in the self-managed sandbox executor after `docker exec <container> mkdir -p /workspace/<task_id>` returns a non-zero exit code. It means the Docker CLI ran but the mkdir inside the target container failed. The stderr captured from the docker exec call is embedded in the message.","triggerScenarios":"Calling the executor's run path (which stages code into a container) when: the named container does not exist or has exited (`Error: No such container`), the Docker daemon is unreachable from the executor process, the image lacks /bin/mkdir or a usable shell, or the workspace parent is read-only inside the container.","commonSituations":"Sandbox container was reaped by a cleanup job between creation and code staging; executor runs on a host without Docker installed or without permission to the Docker socket; container name mismatch after restart; minimal distroless image without coreutils.","solutions":["Check the stderr text in the message: 'No such container' means the container id/name is stale — recreate it before dispatching execution.","Verify Docker connectivity from the executor host: `docker exec <container> mkdir -p /workspace/test` manually.","Ensure the executor user has access to /var/run/docker.sock (add to docker group or grant socket permissions).","If using a minimal image, switch to one containing coreutils (mkdir, tar) or add them to the image."],"exampleFix":"# before\nreturncode, _, stderr = await async_run_command(\"docker\", \"exec\", container, \"mkdir\", \"-p\", f\"/workspace/{task_id}\", timeout=5)\nif returncode != 0:\n    raise RuntimeError(f\"Directory creation failed: {stderr}\")\n\n# after: verify the container is alive first and include actionable context\nreturncode, _, stderr = await async_run_command(\"docker\", \"inspect\", \"-f\", \"{{.State.Running}}\", container, timeout=5)\nif returncode != 0 or stderr.strip() != \"true\":\n    raise RuntimeError(f\"Sandbox container {container} is not running; recreate it before executing\")","handlingStrategy":"validation","validationCode":"# Verify the container exists and is running before staging code\nreturncode, out, err = await async_run_command(\n    \"docker\", \"inspect\", \"-f\", \"{{.State.Running}}\", container, timeout=5\n)\nif returncode != 0 or out.strip() != \"true\":\n    raise RuntimeError(f\"Container {container} not running; recreate before execution\")","typeGuard":null,"tryCatchPattern":"try:\n    await run_execution(...)\nexcept RuntimeError as e:\n    if \"Directory creation failed\" in str(e):\n        # container/environment problem: recreate sandbox container and retry once\n        await recreate_container(container)\n    else:\n        raise","preventionTips":["Health-check the sandbox container (docker inspect) before every execution dispatch.","Run the executor on a host with Docker installed and socket access for its user.","Use an image containing coreutils (mkdir, tar).","Monitor container lifetime so cleanup jobs cannot reap live sandboxes."],"tags":["docker","sandbox","subprocess","executor"],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}