{"record":{"id":"c34f78e6e73c12ac","repo":"agentscope-ai/agentscope","slug":"not-found-in-opensandbox-sandbox-path","errorCode":null,"errorMessage":"not found in OpenSandbox sandbox: {path}","messagePattern":"not found in OpenSandbox sandbox: (.+?)","errorType":"exception","errorClass":"FileNotFoundError","httpStatus":null,"severity":"warning","filePath":"src/agentscope/workspace/_opensandbox/_opensandbox_backend.py","lineNumber":138,"sourceCode":"        Returns:\n            `bytes`:\n                The raw file contents.\n\n        Raises:\n            `FileNotFoundError`:\n                If the path does not exist inside the sandbox.\n        \"\"\"\n        try:\n            data = await self._sandbox.files.read_bytes(path)\n        except FileNotFoundError:\n            raise\n        except Exception as exc:  # noqa: BLE001\n            # OpenSandbox surfaces missing files through the HTTP\n            # transport today (httpx.HTTPStatusError with a 404\n            # response). Keep a message fallback for SDK wrappers that\n            # do not expose the response object.\n            if self._is_not_found_error(exc):\n                raise FileNotFoundError(\n                    f\"not found in OpenSandbox sandbox: {path}\",\n                ) from exc\n            raise\n        return data\n\n    async def write_file(self, path: str, data: bytes) -> None:\n        \"\"\"Write raw bytes to a file inside the sandbox.\n\n        Creates parent directories via ``exec_shell`` first.\n\n        Args:\n            path (`str`):\n                Destination path inside the sandbox.\n            data (`bytes`):\n                The raw bytes to write.\n        \"\"\"\n        parent = posixpath.dirname(path)\n        if parent:","sourceCodeStart":120,"sourceCodeEnd":156,"githubUrl":"https://github.com/agentscope-ai/agentscope/blob/e90f1c7592896cc95f6e5ee506194f533378247d/src/agentscope/workspace/_opensandbox/_opensandbox_backend.py#L120-L156","documentation":"Raised by OpenSandboxBackend.read_file when the remote sandbox reports a missing file. OpenSandbox surfaces 404s through the HTTP transport (httpx.HTTPStatusError); the backend detects it via _is_not_found_error and re-raises as the standard Python FileNotFoundError with a path-qualified message, so callers get idiomatic not-found semantics.","triggerScenarios":"await backend.read_file(path) where the file does not exist in the sandbox: reading output paths before the agent created them, wrong relative/absolute path, or reading after the sandbox was reset.","commonSituations":"Assuming a file exists after running a command that silently failed, path mismatches (leading '/', cwd differences between local and sandbox), or sandbox ephemeral storage wiped between calls.","solutions":["Verify the path: list the parent directory in the sandbox before reading.","Create the file (or run the command that produces it) before read_file.","Catch FileNotFoundError and treat as 'not produced yet' in polling loops.","If the sandbox was recycled, re-run setup steps that materialize the file."],"exampleFix":"# before\ndata = await backend.read_file(\"/workspace/out.txt\")  # FileNotFoundError\n\n# after\ntry:\n    data = await backend.read_file(\"/workspace/out.txt\")\nexcept FileNotFoundError:\n    await backend.run_command(\"touch /workspace/out.txt\")\n    data = await backend.read_file(\"/workspace/out.txt\")","handlingStrategy":"try-catch","validationCode":"try:\n    entries = await backend.list_dir(str(PurePosixPath(path).parent))\n    exists = PurePosixPath(path).name in entries\nexcept Exception:\n    exists = False","typeGuard":null,"tryCatchPattern":"try:\n    data = await backend.read_file(path)\nexcept FileNotFoundError:\n    data = None  # treat as not-yet-produced","preventionTips":["Poll with FileNotFoundError tolerance when waiting on generated artifacts.","Use absolute sandbox paths consistently; remember cwd differs from your local machine.","Recreate required files after any sandbox reset before reading."],"tags":["agentscope","opensandbox","file-not-found","read-file","sandbox"],"backgroundTag":"file-not-found","analyzedSha":"e90f1c7592896cc95f6e5ee506194f533378247d","analyzedAt":"2026-08-28T18:24:12.087Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}