{"record":{"id":"3c55b02b6e90ca52","repo":"FoundationAgents/OpenManus","slug":"failed-to-write-to-path-in-sandbox-str-e","errorCode":null,"errorMessage":"Failed to write to {path} in sandbox: {str(e)}","messagePattern":"Failed to write to (.+?) in sandbox: (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"app/tool/file_operators.py","lineNumber":121,"sourceCode":"        \"\"\"Ensure sandbox is initialized.\"\"\"\n        if not self.sandbox_client.sandbox:\n            await self.sandbox_client.create(config=SandboxSettings())\n\n    async def read_file(self, path: PathLike) -> str:\n        \"\"\"Read content from a file in sandbox.\"\"\"\n        await self._ensure_sandbox_initialized()\n        try:\n            return await self.sandbox_client.read_file(str(path))\n        except Exception as e:\n            raise ToolError(f\"Failed to read {path} in sandbox: {str(e)}\") from None\n\n    async def write_file(self, path: PathLike, content: str) -> None:\n        \"\"\"Write content to a file in sandbox.\"\"\"\n        await self._ensure_sandbox_initialized()\n        try:\n            await self.sandbox_client.write_file(str(path), content)\n        except Exception as e:\n            raise ToolError(f\"Failed to write to {path} in sandbox: {str(e)}\") from None\n\n    async def is_directory(self, path: PathLike) -> bool:\n        \"\"\"Check if path points to a directory in sandbox.\"\"\"\n        await self._ensure_sandbox_initialized()\n        result = await self.sandbox_client.run_command(\n            f\"test -d {path} && echo 'true' || echo 'false'\"\n        )\n        return result.strip() == \"true\"\n\n    async def exists(self, path: PathLike) -> bool:\n        \"\"\"Check if path exists in sandbox.\"\"\"\n        await self._ensure_sandbox_initialized()\n        result = await self.sandbox_client.run_command(\n            f\"test -e {path} && echo 'true' || echo 'false'\"\n        )\n        return result.strip() == \"true\"\n\n    async def run_command(","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/tool/file_operators.py#L103-L139","documentation":"Raised by SandboxFileOperator.write_file (app/tool/file_operators.py:121) when sandbox_client.write_file throws. Like read_file, it catches every exception and re-raises as ToolError, discarding the original traceback via `from None`. Typical root causes are missing parent directories, read-only filesystems, path escaping the sandbox's writable scope, or transport-level failures to the sandbox runtime.","triggerScenarios":"Calling write_file(path, content) when: (1) the parent directory of path does not exist in the sandbox, (2) the target is on a read-only mount or disk quota is exhausted, (3) the sandbox client cannot reach the sandbox runtime API after implicit creation, (4) the path collides with an existing directory.","commonSituations":"Agent writes generated artifacts to nested paths (e.g. /workspace/src/gen/out.txt) without mkdir -p first; sandboxes with size limits or tmpfs quotas; sandbox token/URL expired between calls; writing to paths like /etc or other non-writable container locations.","solutions":["Create parent directories first via the command operator: `await operator.run_command(f'mkdir -p {parent}')` before write_file.","Verify the target path is inside a writable sandbox location (e.g. /workspace or /tmp inside the container).","Check sandbox disk space/quota and read-only mounts with a quick `df -h <dir>` run_command if writes repeatedly fail.","If the error message indicates a transport/auth failure rather than a filesystem error, recreate the sandbox (_ensure_sandbox_initialized only creates when sandbox is falsy; a stale-but-set client will not be refreshed — recreate explicitly)."],"exampleFix":"// before\nawait sandbox_files.write_file('/workspace/out/gen/result.md', text)\n\n// after\nawait sandbox_files.run_command('mkdir -p /workspace/out/gen')\nawait sandbox_files.write_file('/workspace/out/gen/result.md', text)","handlingStrategy":"try-catch","validationCode":"parent = PurePosixPath(path).parent\nawait sandbox_files.run_command(f'mkdir -p {parent}')\nawait sandbox_files.write_file(path, content)","typeGuard":null,"tryCatchPattern":"try:\n    await sandbox_files.write_file(path, content)\nexcept ToolError as e:\n    if 'Read-only' in str(e) or 'Permission' in str(e):\n        reroute_to_writable_dir(path)\n    else:\n        raise","preventionTips":["mkdir -p the parent directory before every write to a nested path.","Restrict writes to known-writable sandbox locations (/workspace, /tmp).","Check sandbox disk quota when writes fail repeatedly with size-related messages."],"tags":["sandbox","file-io","tool-error","async"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}