agentscope-ai / agentscope-ai/agentscope-java

[Bug]:DockerSandbox.doExec() strips nested double quotes on Windows

未關閉
#2,924 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
Java
星號
5.6k
分支
1.3k
平均合併
4 天 12 小時
30 天內合併 PR
77

描述

**Describe the bug**

On Windows, `DockerSandbox.doExec()` fails for any shell command containing nested double quotes (e.g. `mkdir -p "$(dirname ...)"`, `python3 -c "..."`). This breaks `write_file` and `edit_file` tools entirely.

Root cause: `ProcessBuilder` on Windows goes through `cmd.exe /c`, which strips inner double quotes from the `sh -c` argument. Linux/macOS are unaffected (no `cmd.exe`).

**To Reproduce**

```java
// Exact command from BaseSandboxFilesystem.write() line ~165
String cmd = "if [ -e 'test.txt' ]; then echo 'EXISTS'; exit 1; fi; "
+ "mkdir -p \"$(dirname 'test.txt')\" 2>&1";

// Current doExec() approach
ProcessBuilder pb = new ProcessBuilder(
"docker", "exec", "-w", "/workspace", containerId, "sh", "-c", cmd);
Process p = pb.start();
p.waitFor(30, TimeUnit.SECONDS);
System.out.println(p.exitValue()); // Windows: 2, Linux: 0
```

Run on Windows 11 + Docker Desktop → exit code 2, stderr: `'test.txt') 2>&1: 1: Syntax error: end of file unexpected (expecting ")")`

**Expected behavior**

Exit code 0 on all platforms.

**Error messages**

Windows exit code 2, stderr:

```
'test.txt') 2>&1: 1: Syntax error: end of file unexpected (expecting ")")
```

`edit_file` (requires python3 image) stderr:

```
File "", line 1
import
^
SyntaxError: invalid syntax
```

**Environment:**

- AgentScope-Java Version: 2.0.0
- Java Version: 21
- OS: Windows 11
- Docker: Docker Desktop with Linux containers

**Additional context**

- `doHydrateWorkspace()` already uses `docker exec -i` (for tar stdin) and is unaffected.
- Only `doExec()` is affected because it's the only method that passes a shell command via `-c`.
- Suggested fix: pipe command through stdin instead of `-c` argument (see reproduction code above).

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。