{"record":{"id":"491532d1f3e37a02","repo":"FoundationAgents/OpenManus","slug":"failed-to-write-file-e","errorCode":null,"errorMessage":"Failed to write file: {e}","messagePattern":"Failed to write file: (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"app/sandbox/core/sandbox.py","lineNumber":230,"sourceCode":"            resolved_path = self._safe_resolve_path(path)\n            parent_dir = os.path.dirname(resolved_path)\n\n            # Create parent directory\n            if parent_dir:\n                await self.run_command(f\"mkdir -p {parent_dir}\")\n\n            # Prepare file data\n            tar_stream = await self._create_tar_stream(\n                os.path.basename(path), content.encode(\"utf-8\")\n            )\n\n            # Write file\n            await asyncio.to_thread(\n                self.container.put_archive, parent_dir or \"/\", tar_stream\n            )\n\n        except Exception as e:\n            raise RuntimeError(f\"Failed to write file: {e}\")\n\n    def _safe_resolve_path(self, path: str) -> str:\n        \"\"\"Safely resolves container path, preventing path traversal.\n\n        Args:\n            path: Original path.\n\n        Returns:\n            Resolved absolute path.\n\n        Raises:\n            ValueError: If path contains potentially unsafe patterns.\n        \"\"\"\n        # Check for path traversal attempts\n        if \"..\" in path.split(\"/\"):\n            raise ValueError(\"Path contains potentially unsafe patterns\")\n\n        resolved = (","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/sandbox/core/sandbox.py#L212-L248","documentation":"Catch-all RuntimeError from DockerSandbox.write_file (app/sandbox/core/sandbox.py:230): failures while creating the parent dir (run_command mkdir), building the tar stream (_create_tar_stream), or pushing it with container.put_archive. The underlying cause is in {e}. Note put_archive writes to parent_dir or \"/\" with only the basename in the tar, so path resolution mistakes surface here too.","triggerScenarios":"mkdir -p failing because the parent is read-only or owned by another user in the container; put_archive failing due to permissions on the target dir; tar creation errors (invalid name for very long basenames); Docker API errors (daemon restarting, disk full).","commonSituations":"Writing to system paths (/etc) as a non-root container user; container disk full after heavy use; basename/path mismatch when the caller passes a path ending in '/' (empty basename); volume mount is read-only (mode 'ro' in bindings).","solutions":["Read {e} — it distinguishes mkdir failure vs put_archive failure.","Write inside config.work_dir (the rw-mounted volume) rather than container-system paths.","Check the volume bindings are mode 'rw' and the host dir is writable.","Clean container disk (docker system prune inside the image's storage) or increase storage."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"writable = (await sandbox.run_command(f\"test -w {shlex.quote(os.path.dirname(abs_path))} && echo 1\")).strip() == \"1\"","typeGuard":null,"tryCatchPattern":"try:\n    await sandbox.write_file(path, content)\nexcept RuntimeError as e:\n    log.error(\"write failed: %r\", e)\n    raise","preventionTips":["Write only under config.work_dir (rw volume)","Ensure volume bindings use mode 'rw'","Avoid trailing slashes / empty basenames in paths","Keep container disk below capacity"],"tags":["sandbox","file-io","permissions","put-archive","wrapper-exception"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}