[Bug]: Compile fails at sandbox init on Windows because DirectBackend runs POSIX commands through cmd.exe
Issue Origin
Observed or reproduced in a real environment
Bug Description
On Windows, a Compile task fails before it starts because the compile sandbox sends POSIX-only commands through cmd.exe.
vikingbot/compile/sandbox.py initializes the task sandbox with:
await self._backend.execute(f"mkdir -m 700 -- {directory}")
await self._backend.execute(f"chmod 600 {shlex.quote(self._config_path)}")
and later prepends unset ...; export OPENVIKING_CLI_CONFIG_FILE=...; to commands. On POSIX this is fine. On Windows, DirectBackend.execute() uses asyncio.create_subprocess_shell which goes through COMSPEC=cmd.exe; cmd.exe does not support mkdir -m, --, chmod, or the unset/export form. The task dies in stage=sandbox with an INTERNAL error, and the real cause is only visible in task stderr as GBK-mojibake text.
Steps to Reproduce
- Windows 11, OpenViking 0.5.1 installed with
uv tool, server in dev mode. - Create a Compile skill/instruction and submit a tiny compile task with
directsandbox backend. - Task fails immediately in
stage=sandboxwith:- task error:
INTERNAL: Compile credentials directory failed - stderr:
命令语法不正确。(cmd.exe: "The syntax of the command is incorrect.")
- task error:
- Reproduce the same two commands manually from
cmd.exe:mkdir -m 700 -- C:\tmp\ov_compile_test→ syntax errorchmod 600 C:\tmp\ov_config.json→'chmod' is not recognized
Expected Behavior
Compile sandbox initialization should work on Windows when the direct backend is selected, without users patching the installed package. The backend should either execute the required operations natively (translate the small POSIX subset) or reject direct on Windows with a clear error.
Actual Behavior
- Every compile task fails at sandbox initialization on Windows.
- The failure is reported as an opaque
INTERNALerror; the actionable cause (cmd.execannot parse POSIX commands) is not in the task error. - stderr is decoded as UTF-8 while cmd.exe writes GBK on Chinese Windows, so logs are garbled.
Minimal Reproducible Example
import asyncio
from pathlib import Path
from vikingbot.sandbox.backends.direct import DirectBackend
from vikingbot.config.schema import Config
backend = DirectBackend(Config().sandbox, "test", Path("C:/tmp/ov_compile_probe"))
await backend.start()
# Mirrors vikingbot/compile/sandbox.py initialization
print(await backend.execute("mkdir -m 700 -- C:/tmp/ov_compile_probe/credentials"))
print(await backend.execute("chmod 600 C:/tmp/ov_compile_probe/ov.conf"))
Error Logs
task.error = "INTERNAL: Compile credentials directory failed"
task.stage = "sandbox"
task stderr = "命令语法不正确。"
task result = failed (no workspace created, no pages published)
OpenViking Version
0.5.1
Python Version
3.12 (uv tool environment at D:\AccessoryTools\uv_tools\openviking)
Operating System
Windows
Model Backend
Other
Additional Context
A minimal fix was validated locally: handle only the fixed POSIX forms Compile needs (mkdir -p, mkdir -m 700 --, chmod 600, and the unset ...; export OPENVIKING_CLI_CONFIG_FILE=...; prefix) inside DirectBackend.execute() when os.name == "nt", and approximate 0700/0600 with icacls (/inheritance:r + owner/SYSTEM/Administrators). All other commands continue through the existing shell path.
Affected lines:
bot/vikingbot/compile/sandbox.py(sandbox initialization)bot/vikingbot/sandbox/backends/direct.py(execute)
Fix prepared and validated on Windows 11 with the 0.5.1 tool environment; PR: #6372