agentscope-ai/agentscope · error · FileNotFoundError

not found in container

Error message

not found in container: {path}\nstderr: {result.stderr.decode(errors='replace')}

What it means

AppleContainerWorkspace's read_file runs `cat <path>` inside the container via exec_shell; a non-zero exit code (usually 'No such file or directory') is surfaced as FileNotFoundError with the path and container stderr.

Solutions

  1. Use the path relative to the container workspace root, not a host path.
  2. Verify the file exists first: await workspace.list_dir(...) or exec `test -f <path>`.
  3. Create/write the file before reading it.
  4. Handle FileNotFoundError and fall back to a default.

Example fix

# before
data = await ws.read_file("/Users/me/project/main.py")

# after
data = await ws.read_file("main.py")  # path inside the container
Defensive patterns

Strategy: try-catch

Validate before calling

entries = await ws.list_dir(dirname(path))
assert any(e.name == basename(path) for e in entries), "file missing"

Try / catch

try:
    data = await ws.read_file(path)
except FileNotFoundError:
    data = default_bytes  # or create the file first

Prevention

When it happens

Trigger: Calling await workspace.read_file(path) where path does not exist inside the container filesystem, or is a directory/unreadable (cat fails). Paths are container-relative, not host-relative.

Common situations: Using host absolute paths like /Users/me/file.txt that don't exist in the container, reading a file before it was written into the workspace, typos in relative paths, or wrong working directory assumption inside the container.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of agentscope-ai/agentscope@e90f1c7592 (2026-08-28). Data as JSON: /api/errors/7ee2edea6d141fda. Report an issue: GitHub.

Appendix: source

Thrown at src/agentscope/workspace/_applecontainer/_applecontainer_backend.py:159

    async def read_file(self, path: str) -> bytes:
        """Read a file from the container via ``container exec cat``.

        Args:
            path (`str`):
                Path to the file inside the container.

        Returns:
            `bytes`:
                The raw file contents.

        Raises:
            `FileNotFoundError`:
                If the path does not exist inside the container.
        """
        result = await self.exec_shell(["cat", path])
        if result.exit_code != 0:
            raise FileNotFoundError(
                f"not found in container: {path}\n"
                f"stderr: {result.stderr.decode(errors='replace')}",
            )
        return result.stdout

    async def write_file(self, path: str, data: bytes) -> None:
        """Write *data* to a file inside the container via
        ``container cp``.

        Writes *data* to a host-side temp file, then copies it into the
        container.

        Args:
            path (`str`):
                Destination path inside the container.
            data (`bytes`):
                The raw bytes to write.
        """

View on GitHub (pinned to e90f1c7592)