Run a command in WSL
wsl_execRun shell commands inside a configured WSL distro and return stdout, stderr and the exit code; reuse a named session to keep the working directory between calls.
Instructions
Run a shell command in the configured WSL distro (as the configured user, in a login bash) and return stdout, stderr and the exit code. Pass 'session' to reuse a session, which remembers its working directory; omit it for a one-off call. A non-zero exit code is reported as normal output, not as a tool error — read the exit code and stderr to judge the outcome. Almost everything is permitted: package installs, service restarts, sudo, interpreters. Refused outright: catastrophic operations (wiping the filesystem root, formatting a disk, powering off or shutting down the distro), and — unless the profile opens them — Windows interop executables and writes under /mnt//. stdin is closed. A job that must outlive the call needs all three descriptors detached: nohup cmd > log 2>&1 < /dev/null &
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Absolute directory to run in, with no shell metacharacters. With a session, the session also moves there. | |
| command | Yes | Shell command, exactly as it would be typed in a terminal. Chaining with ';', '&&', '||' and pipes is allowed; each part is screened separately. | |
| session | No | Session id from wsl_connect. Keeps the working directory across calls. | |
| timeoutMs | No | Lowers the command timeout for this call; it cannot exceed the profile's own limit. wsl.exe is killed when it elapses; the process inside the distro may survive. |