{"record":{"id":"ecbf4734da678534","repo":"FoundationAgents/OpenManus","slug":"failed-to-read-path-in-sandbox-str-e","errorCode":null,"errorMessage":"Failed to read {path} in sandbox: {str(e)}","messagePattern":"Failed to read (.+?) in sandbox: (.+?)","errorType":"exception","errorClass":"ToolError","httpStatus":null,"severity":"error","filePath":"app/tool/file_operators.py","lineNumber":113,"sourceCode":"\nclass SandboxFileOperator(FileOperator):\n    \"\"\"File operations implementation for sandbox environment.\"\"\"\n\n    def __init__(self):\n        self.sandbox_client = SANDBOX_CLIENT\n\n    async def _ensure_sandbox_initialized(self):\n        \"\"\"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:","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/FoundationAgents/OpenManus/blob/52a13f2a57d8c7f6737eefb02ccf569594d44273/app/tool/file_operators.py#L95-L131","documentation":"Raised by SandboxFileOperator.read_file (app/tool/file_operators.py:113) when the underlying sandbox_client.read_file call throws for any reason. The bare `except Exception` wraps every failure mode — missing file, permission denied, sandbox runtime/network errors, even a failed implicit sandbox creation path — into a single ToolError with the original message appended. Note that `from None` discards the original traceback, so the appended str(e) is the only diagnostic you get.","triggerScenarios":"Calling read_file(path) where: (1) the file does not exist inside the sandbox filesystem, (2) the path is a directory or otherwise unreadable, (3) the path is outside the sandbox's mounted/allowed scope, or (4) the sandbox client's HTTP/API connection to the sandbox runtime fails after _ensure_sandbox_initialized created it. Any non-TimeoutError exception from sandbox_client.read_file triggers it.","commonSituations":"Agent/tool pipelines that assume a workspace file (e.g. repo file written in a previous session) is present in a freshly created sandbox; misconfigured sandbox runtime URLs or expired sandbox tokens; paths built from host-side absolute paths that do not exist inside the container; sandbox evicted/idle-timeout between calls.","solutions":["Verify the file exists in the sandbox first: `if not await operator.exists(path): ...` (exists() is implemented via `test -e` over run_command) before calling read_file.","Confirm the path is correct relative to the sandbox filesystem, not the host filesystem — sandbox paths are container-internal.","Check sandbox health: ensure sandbox_client.sandbox is set and the sandbox runtime (API server) is reachable; recreate the sandbox if it was evicted.","Catch ToolError at the caller and surface the embedded str(e) (FileNotFoundError vs. auth/network) to distinguish missing file from infrastructure failure."],"exampleFix":"// before\ncontent = await sandbox_files.read_file('/workspace/main.py')  # ToolError if missing\n\n// after\nif not await sandbox_files.exists('/workspace/main.py'):\n    raise FileNotFoundError('/workspace/main.py not present in sandbox')\ncontent = await sandbox_files.read_file('/workspace/main.py')","handlingStrategy":"try-catch","validationCode":"if not await sandbox_files.exists(str(path)):\n    raise FileNotFoundError(f'{path} not present in sandbox')\ncontent = await sandbox_files.read_file(path)","typeGuard":"def is_readable_sandbox_path(p: str | Path) -> bool:\n    return isinstance(p, (str, Path)) and bool(str(p).strip()) and not str(p).endswith('/')","tryCatchPattern":"try:\n    content = await sandbox_files.read_file(path)\nexcept ToolError as e:\n    msg = str(e)\n    if 'No such file' in msg or 'not found' in msg:\n        handle_missing(path)\n    else:\n        raise  # transport / sandbox-runtime problem, not a missing file","preventionTips":["Call exists() before read_file for any path not written earlier in the same session.","Treat sandbox paths as container-internal; never pass host absolute paths.","Monitor sandbox liveness; recreate the sandbox on transport-style failures instead of retrying reads against a stale client."],"tags":["sandbox","file-io","tool-error","async"],"backgroundTag":null,"analyzedSha":"52a13f2a57d8c7f6737eefb02ccf569594d44273","analyzedAt":"2026-08-15T02:33:49.993Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}