agentscope-ai / agentscope-ai/agentscope-java

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

Aperta
#2,924 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
bug
Lingua principale
Java
Stelle
5.6k
Fork
1.3k
Merge medio
4g 12h
PR unite (30g)
77

Descrizione

**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).

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.