ssh_exec
Run shell commands on a remote server over SSH, capturing exit codes and output. Supports single or multiple commands, detached background jobs, and sudo.
Instructions
Runs one command or a list of them on a server and returns the exit code, stdout and stderr of each. Every command gets its own shell, so a variable set or a directory entered in one is gone in the next. Work measured in minutes should be detached rather than given a longer timeout: a detached call returns a job id at once and outlives this request. Reach for it last — files, logs, transfers, health and jobs each have a tool that batches the round trips and parses the answer.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cwd | No | Directory to start in, detached jobs included. Cannot be entered -> the command stops, it does not run elsewhere. | |
| sudo | No | Execute command(s) with sudo. Default: false | |
| detach | No | Background job on the server: returns an id at once, outlives this call, timeout does not apply. Follow with ssh_job_status / ssh_job_output, stop with ssh_job_kill. One command. With sudo the job runs as root and every later call follows it as root, provided the profile has a password or sudo needs none. Default: false | |
| command | Yes | One command, or a list: ["hostname", "whoami"]. Each runs in its own shell — no shared variable, no shared cd; cwd applies to all. A non-zero exit does not stop the list. | |
| profile | Yes | Machine name. | |
| timeout | No | Milliseconds, per command in a list, not for the whole list; default 30000. Work measured in minutes -> detach, not a bigger number. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| job_id | No | ||
| legend | No | What the words in this answer mean. A key names the field before the value — "state=limited", "jobs[].state=lost" — and only the values this answer actually used are listed. | |
| commands | No |