| description | Run a multi-line shell script via stdin to `sh -s --` |
|---|
Tier: dangerous | Group: exec | Tags: {dangerous, group:exec}
The script body is streamed via stdin to sh -s -- on the remote, so it
never appears in argv, process listings, or audit lines. This is the right
choice for anything multi-line or anything you'd rather not show in a ps
listing.
No command allowlist check is performed against the script body -- the
allowlist only inspects argv tokens, and the body is on stdin. Inspect what
you execute. Disabled unless ALLOW_DANGEROUS_TOOLS=true.
POSIX-only. Pipes the script body to sh -s --. Windows targets
raise PlatformNotSupported.
| name | type | required | default | notes |
|---|---|---|---|---|
host |
str | yes | -- | Alias or hostname |
script |
str | yes | -- | The script body. Sent verbatim to sh -s -- stdin. |
timeout |
int | no | SSH_COMMAND_TIMEOUT |
Per-call timeout in seconds |
Same ExecResult shape as ssh_exec_run, including
output_warnings (INC-057). Script
stdout is a prime injection vector -- check the field before treating
the result as trustworthy.
- Multi-line shell logic (loops, conditionals, intermediate variables).
- A script that contains values you don't want logged in argv (paths, IDs, but not secrets -- they still get logged at the OS level if your script echoes them).
- You'd otherwise have to chain commands with
&& \\and quote everything carefully.
- A single command --
ssh_exec_runis simpler and cheaper. - Long-running output -- use
ssh_exec_run_streaming. - Anything sudoy -- use
ssh_sudo_run_script(Phase 4).
script = """\
set -euo pipefail
for f in /var/log/nginx/*.log; do
lines=$(wc -l < "$f")
echo "$f: $lines"
done
"""
ssh_exec_script(host="web01", script=script, timeout=30)Because the script is on stdin, you don't have to escape $, backticks, or
quotes the way you would for ssh_exec_run. Write the script as you'd write
a .sh file. Prepend set -euo pipefail if you want strict failure semantics.
ConnectError-- TCP, auth, or transport failure.HostBlocked/HostNotAllowed-- see host policy.timed_out=true-- script ran past the timeout. Pkill cleanup attempted onsh -s --.
ssh_exec_run-- single-command variant with allowlist enforcement.ssh_exec_run_streaming-- for scripts that produce continuous output.