session_exec
Run a shell command in an existing session and return structured JSON (stdout, stderr, exit code). Shape output with an optional budget.
Instructions
Run a command in a session; returns ExecResult JSON (stdout, stderr, exit_code, duration_ms, cwd, truncated). Non-interactive: stdin is closed - no prompts, REPLs, or editors; use sudo -n. Default timeout 120s (EXECKIT_MCP_EXEC_TIMEOUT); timeout_secs overrides per call (max 3600). On timeout the command is interrupted (exit_code 124, timed_out:true); the session stays usable. For long jobs, background: nohup CMD > /tmp/x.log 2>&1 & then poll cat /tmp/x.log. exit, or a set -e failure, ends the shell and closes the session. Optional budget shapes output: {grep:{pattern,context?}, keep:{mode:"all"|"tail"|"head"|"head_tail",n?|head?+tail?}, max_chars?} - line-based, after redaction; never changes exit code/side effects; adds a report (mode + lines_total/lines_kept). Truncated unbudgeted output adds a hint. Redacted output is not file-accurate: never write it back to a file.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| budget | No | Shape THIS command's output (overrides the session default). | |
| command | Yes | The shell command to run. | |
| session_id | Yes | Session id from session_create. | |
| timeout_secs | No | Timeout for THIS command in seconds (default 120, or EXECKIT_MCP_EXEC_TIMEOUT; clamped to 1..=3600). On timeout the command is interrupted and the session stays usable. |