agentscope-ai / agentscope-ai/agentscope-java
[Bug]:DockerSandbox.doExec() strips nested double quotes on Windows
- Langage dominant
- Java
- Étoiles
- 5.6k
- Forks
- 1.3k
- Merge moyen
- 4 j 12 h
- PR mergées (30 j)
- 77
Description
**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).
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.