Skip to content

[Bug]:docker exec commands with double-quoted $(...) substitution break on Windows hosts — write_file/edit_file in sandbox always fail #3850

Closed

Description

@CameronSun

Issue: docker exec commands with double-quoted $(...) substitution break on Windows hosts — write_file/edit_file in sandbox always fail

Repo: https://github.com/agentscope-ai/agentscope-java

Summary

When the agent runs inside a Docker sandbox on a Windows host (e.g. Windows 10/11 + Docker Desktop), write_file (and edit_file) fail with Failed to write file, even though the same sandbox works perfectly on Linux/macOS hosts.

Root cause: BaseSandboxFilesystem.write() builds a check command that contains a double-quoted command substitution:

if [ -e '<path>' ]; then echo 'EXISTS'; exit 1; fi; mkdir -p "$(dirname '<path>')" 2>&1

On Windows, the docker CLI corrupts command arguments containing "$(...)" during argument passing (quoting is mangled before the container shell ever sees it). The container shell then reports Syntax error: end of file unexpected (exit code 2), so write() never reaches the success path and returns Failed to write file.

edit_file has the same problem — it builds python3 -c "..." with the whole Python script wrapped in double quotes.

Affected versions

Verified by decompiling io.agentscope.harness.agent.filesystem.sandbox.BaseSandboxFilesystem:

Version write check command edit command Fixed?
2.0.3 mkdir -p "$(dirname ...)" python3 -c "..." ❌
2.0.4 mkdir -p "$(dirname ...)" python3 -c "..." ❌
2.1.0-BETA1 mkdir -p "$(dirname ...)" python3 -c "..." ❌

Steps to reproduce

  1. Windows host with Docker Desktop installed.
  2. Start the app with sandbox mode enabled (default).
  3. Call write_file with a path that does not exist yet (or edit_file).
  4. Observe the failure: Error: Failed to write file '<path>'.

Logs from the sandbox command (exit 2):

Syntax error: end of file unexpected

Expected behavior

write_file / edit_file should succeed inside the sandbox on Windows hosts, identical to Linux/macOS.

Verification notes (what we already tested)

  • Removing the double quotes — mkdir -p $(dirname '<path>') — works on both Windows and Linux hosts (same pattern already used by move()).
  • A plain quoted variable reference "$f" passes through fine; only double-quoted $(...) substitutions get corrupted.
  • We validated a base64-over-stdin variant for edit_file (script shipped via heredoc, python3 -c 'import base64,sys;exec(base64.b64decode(sys.stdin.read()))' — single quotes only) and it works inside the sandbox: returns {"count": 1}.

Suggested fix

  • write(): drop the double quotes around $(dirname ...).
  • edit(): avoid double quotes in the docker exec command entirely — e.g. ship the script as base64 over stdin as described above.
  • (Optional) write() already has an uploadFiles transport added in 2.0.4; the check command blocks it with exit 2 before it can be used. Fixing the check command would unlock the cleaner upload path.

Environment

  • OS: Windows 10/11 (host)
  • Docker: Docker Desktop (Windows containers off, Linux containers)
  • Java: JDK 17+ (backend runs Spring Boot / WebFlux)
  • agentscope-harness: 2.0.3 / 2.0.4 / 2.1.0-BETA1 (confirmed identical bytecode for these methods)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions