FoundationAgents/OpenManus · error · ToolError

Failed to read {path} in sandbox: {str(e)}

Error message

Failed to read {path} in sandbox: {str(e)}

What it means

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.

Source

Thrown at app/tool/file_operators.py:113

class SandboxFileOperator(FileOperator):
    """File operations implementation for sandbox environment."""

    def __init__(self):
        self.sandbox_client = SANDBOX_CLIENT

    async def _ensure_sandbox_initialized(self):
        """Ensure sandbox is initialized."""
        if not self.sandbox_client.sandbox:
            await self.sandbox_client.create(config=SandboxSettings())

    async def read_file(self, path: PathLike) -> str:
        """Read content from a file in sandbox."""
        await self._ensure_sandbox_initialized()
        try:
            return await self.sandbox_client.read_file(str(path))
        except Exception as e:
            raise ToolError(f"Failed to read {path} in sandbox: {str(e)}") from None

    async def write_file(self, path: PathLike, content: str) -> None:
        """Write content to a file in sandbox."""
        await self._ensure_sandbox_initialized()
        try:
            await self.sandbox_client.write_file(str(path), content)
        except Exception as e:
            raise ToolError(f"Failed to write to {path} in sandbox: {str(e)}") from None

    async def is_directory(self, path: PathLike) -> bool:
        """Check if path points to a directory in sandbox."""
        await self._ensure_sandbox_initialized()
        result = await self.sandbox_client.run_command(
            f"test -d {path} && echo 'true' || echo 'false'"
        )
        return result.strip() == "true"

    async def exists(self, path: PathLike) -> bool:

View on GitHub (pinned to 52a13f2a57)

Solutions

  1. 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.
  2. Confirm the path is correct relative to the sandbox filesystem, not the host filesystem — sandbox paths are container-internal.
  3. Check sandbox health: ensure sandbox_client.sandbox is set and the sandbox runtime (API server) is reachable; recreate the sandbox if it was evicted.
  4. Catch ToolError at the caller and surface the embedded str(e) (FileNotFoundError vs. auth/network) to distinguish missing file from infrastructure failure.

Example fix

// before
content = await sandbox_files.read_file('/workspace/main.py')  # ToolError if missing

// after
if not await sandbox_files.exists('/workspace/main.py'):
    raise FileNotFoundError('/workspace/main.py not present in sandbox')
content = await sandbox_files.read_file('/workspace/main.py')
Defensive patterns

Strategy: try-catch

Validate before calling

if not await sandbox_files.exists(str(path)):
    raise FileNotFoundError(f'{path} not present in sandbox')
content = await sandbox_files.read_file(path)

Type guard

def is_readable_sandbox_path(p: str | Path) -> bool:
    return isinstance(p, (str, Path)) and bool(str(p).strip()) and not str(p).endswith('/')

Try / catch

try:
    content = await sandbox_files.read_file(path)
except ToolError as e:
    msg = str(e)
    if 'No such file' in msg or 'not found' in msg:
        handle_missing(path)
    else:
        raise  # transport / sandbox-runtime problem, not a missing file

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of FoundationAgents/OpenManus@52a13f2a57 (2026-08-15). Data as JSON: /api/errors/ecbf4734da678534. Report an issue: GitHub.