agentscope-ai/agentscope · error · RuntimeError

Bubblewrap write failed (exit {result.exit_code}): {result.s

Error message

Bubblewrap write failed (exit {result.exit_code}): {result.stderr.decode(errors='replace')}

What it means

Generic RuntimeError raised by _write_via_cat when the sandboxed write command fails with an exit code other than 65. The message contains the exit status and decoded stderr of the sandboxed process, which usually pinpoints disk, permission, or bwrap launch problems.

Source

Thrown at src/agentscope/workspace/_bubblewrap/_bubblewrap_backend.py:328

                    "/workspace|/workspace/*|/tmp|/tmp/*) ;; "
                    "*) exit 65 ;; "
                    "esac; "
                    'mkdir -p -- "$resolved_parent" && '
                    'target="$resolved_parent/$(basename -- "$1")" && '
                    '[ ! -L "$target" ] || exit 65; '
                    'cat > "$target"'
                ),
                "sh",
                sandbox_path,
            ],
            data,
        )
        if result.exit_code == 65:
            raise PermissionError(
                f"path escapes writable Bubblewrap mounts: {path}",
            )
        if not result.ok():
            raise RuntimeError(
                "Bubblewrap write failed "
                f"(exit {result.exit_code}): "
                f"{result.stderr.decode(errors='replace')}",
            )

    async def _exec_with_input(
        self,
        command: list[str],
        data: bytes | AsyncIterator[bytes],
        *,
        cwd: str | None = None,
        timeout: float | None = None,
    ) -> ExecResult:
        """Run a sandbox command with ``data`` piped to stdin.

        An async iterator is fed chunk by chunk, so a large payload
        never materializes. Safe only because the commands run this way
        write nothing to stdout — otherwise a full pipe would deadlock

View on GitHub (pinned to e90f1c7592)

Solutions

  1. Create parent directories inside the sandbox before writing
  2. Check the embedded stderr and host disk space (df -h on the workdir)
  3. Ensure the target path is not an existing directory
  4. Re-run bwrap manually to confirm the runtime is healthy

Example fix

# before
await ws.write_file('/workspace/a/b/c.txt', data)  # a/b missing
# after
await ws.run_command('mkdir -p /workspace/a/b')
await ws.write_file('/workspace/a/b/c.txt', data)
Defensive patterns

Strategy: fallback

Validate before calling

await ws.run_command(f'mkdir -p {posixpath.dirname(sandbox_path)}')  # before write

Type guard

null

Try / catch

try:
    await ws.write_file(p, data)
except RuntimeError as e:
    log.error('write failed: %s', e); raise

Prevention

When it happens

Trigger: Destination directory missing inside the sandbox, disk full, file exists as a directory, or bwrap failing to start the shell.

Common situations: Writing into a subdirectory never created in the sandbox, ENOSPC on the host backing the workdir bind mount, or a damaged bwrap runtime.

Related errors


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