Command execution tools

These tools let an AI agent run shell commands and reviewed scripts on one or more servers and review what has already run. They back requests like “run df -h on web-01 and tell me the result,” “deploy this config to every server in the staging fleet,” or “run the deploy script I just uploaded.”

Command execution always requires ACL permission on the caller—see Command ACLs for how those rules are managed. MCP OAuth/browser callers also need an active, approved Work Session that includes the command scope, plus the webftp scope when execute_file writes or reads the script on the server. From December 1, 2026 (00:00 UTC), the same requirement applies to personal API tokens that still have the required command-execution scopes (see Token restrictions). Service tokens retain their endpoint-specific authorization rules. Pass work_session_id to link a command to a specific session, or set the ALPACON_WORK_SESSION environment variable to supply a default when the argument is omitted.

Note

All tools accept workspace (required) and region (optional, defaults to the configured region). These common parameters are omitted from the tables below.

Summary

ToolDescriptionAccess
list_commandsList recent command execution historyRead-only
check_command_statusRead one command’s state and result by its IDRead-only
execute_commandRun a command on a server and wait for the result, or return its ID at onceAdditive
execute_command_multi_serverRun the same command on multiple serversAdditive
execute_fileRun a reviewed script on a serverAdditive
state_command_purposeAnswer a command’s pending purpose requestAdditive

Command history

list_commands

Lists recent commands executed on servers, including status, output, and timestamps. Filter by server_id to scope the history to a single server. Use this to review what has already run before executing something new, or to check the outcome of a command submitted earlier.

Access: Read-only

Parameters

ParameterTypeRequiredDescription
server_idstringNoFilter results to commands run on this server
limitintegerNoMaximum number of results to return (default: 20)

Example

“Show me the last 10 commands run on the db-01 server”

The agent calls list_commands with server_id set to db-01’s UUID and limit=10, returning each command’s status, output, and timestamp.

check_command_status

Reads one command’s state and result by command_id, in a single call that never waits. Use it to follow a command that execute_command returned without waiting for, one whose wait timed out, one held for approval or a purpose, or one entry of execute_command_multi_server. It only reads: it never resubmits, cancels, or approves anything.

The response takes the same shapes execute_command reports: the result once the command has finished, a pending-approval result while a human must approve it, purpose_required while the server asks what it is for, and an error for a command that was refused. A command that hasn’t finished returns success with a message saying so, the command in data, and a next_action to check again. That includes stuck, which the server shows once the agent hasn’t reported for over 10 minutes: the command may still finish, so treat it as unfinished and do not submit it again.

Access: Read-only

Parameters

ParameterTypeRequiredDescription
command_idstringYesCommand ID from the result or timeout error of execute_command, execute_file, or state_command_purpose, or from an execute_command_multi_server entry

Example

“Is the backup I started on db-01 done yet?”

The agent calls check_command_status with the command_id it got when it submitted the backup, and reports the output if the command has finished, or that it is still running.

Running commands

execute_command

Runs a shell command on a server and waits for the result, returning stdout, stderr, and exit code in a single call. This is the recommended way to run a command—list_commands only reviews history, it does not execute anything. The tool polls for completion up to timeout seconds (default 300, i.e. 5 minutes), resetting the deadline while the command is actively running, with a hard cap at three times the timeout to prevent indefinite waiting.

Supports dependency chains (run_after), scheduled execution (scheduled_at), and stdin input (data). If the command is refused—denied or rejected—the tool stops polling and returns an error immediately instead of waiting out the timeout. A stuck command is not refused: the server shows that status once the agent hasn’t reported for over 10 minutes, but the command can still finish, so the tool keeps waiting until timeout.

A wait that ends before the command does returns an error with error_type: "timeout", the command_id, and a next_action naming check_command_status. The command stays on the server: it may still be running, or still waiting to start, such as a scheduled_at command or one queued behind run_after. Read its result with that tool instead of submitting it again, which would run it twice.

Pass wait: false for work that may outlast a single call. The tool submits the command and returns its command_id at once, with a next_action naming check_command_status. A command the server refuses at creation, such as one an ACL denies, still returns its error. No purpose request is opened in this mode, since nobody is waiting to answer it, so state purpose up front.

If the command itself needs human approval before it can run at all (a Work Session gate, separate from the sudo handling below), the tool returns a structured pending-approval result with status pending_approval and category COMMAND_AWAITING_APPROVAL. A human approves it out-of-band, and the command then runs by itself. Do not re-run the command while it is pending: resubmitting requires its own separate approval and risks double-executing the command once the original request is approved. Wait for the approval, then check the outcome with check_command_status.

A sudo inside the command never waits for a person. When no Work Session sudo policy covers it, the server denies it at once, and the command finishes with the denial in its result. The tool then attaches sudo_hint, a free-text hint describing the denial. For the six categories a human can resolve out-of-band, it also attaches sudo_denial, a structured pending-approval block, so an agent can branch on its category and next_action instead of parsing prose:

  • SUDO_APPROVAL_REQUIRED: the command needs a reviewer’s approval. When the approval gate denied it, an approval request is open and a reviewer approves it; when the risk gate did, no request stands behind this attempt. list_approval_requests shows whether one is open.
  • SUDO_INTENT_DEVIATION: the command was judged off-purpose for the Work Session. An approval request is open only when the approval gate denied it, as with SUDO_APPROVAL_REQUIRED. The agent can also restate what the session is for with work_session_update.
  • SUDO_PRESENCE_REQUIRED: a human completes an MFA step-up.
  • SUDO_NO_WORKSESSION_POLICY: no session-authorized sudo policy covers the command. A human sets one up in the Alpacon web console or with the CLI’s work-session update --sudo.
  • SUDO_POLICY_MFA_REQUIRED: a sudo policy covers the command but doesn’t let the session approval take the place of MFA, which a command can never supply. A person can enable this in the web console on any plan. The policy must be linked to a usable Work Session.
  • WORK_SESSION_SCOPE_NOT_ALLOWED: the Work Session doesn’t carry the sudo scope. Add it with work_session_update, or open a session that has it.

Once the human acts, run the whole command again. A sudo_hint with no sudo_denial, such as SUDO_RISK_DENIED from runtime risk assessment, is a hard denial: no request stands behind it, so there is nothing to wait for, and running the same command again gets the same answer.

A command that isn’t routine may come back with a result of purpose_required instead of running—the server is asking why this particular command is needed on this host. Passing purpose up front (a sentence or two, stating something specific to this host rather than restating context the caller already gave) can let the command clear immediately instead of pausing; if you omit it and the server asks anyway, answer with state_command_purpose within about a minute.

Access: Additive

Parameters

ParameterTypeRequiredDescription
server_idstringYesTarget server ID
commandstringYesShell command to execute
shellstringNoShell to run the command in (default: system)
usernamestringNoSystem user to run the command as
groupnamestringNoSystem group to run the command as (default: alpacon)
envobjectNoEnvironment variables to set for the command
run_afterarrayNoCommand IDs this command should run after
scheduled_atstringNoSchedule the command for a future time instead of running immediately
datastringNoData to pass to the command’s stdin
timeoutintegerNoSeconds to wait for completion before timing out (default: 300)
work_session_idstringNoWork Session to link this command to, for audit. Falls back to ALPACON_WORK_SESSION if omitted
purposestringNoWhy this command is needed on this host, in a sentence or two. Answers a purpose_required result up front instead of pausing for it
waitbooleanNoWait for the result (default: true). Set false to return the command_id at once and read the result later with check_command_status

If command contains an inline credential—a secret-like KEY=VALUE pair, a password flag, or a connection string with an embedded password—the server rejects the call with command_inline_credential before the command is stored. Pass secrets through env instead; it’s write-only and never appears in command history or audit logs.

For a script, a heredoc, or anything you’d otherwise run as bash /path/to/file, use execute_file instead—an approved script can be re-run unchanged without pausing for another approval, which a plain shell line never can.

When execute_command comes back with pending_approval for a line that runs a script on the server, such as bash /opt/deploy.sh, the response may carry execute_file_suggestion: the execute_file arguments for the same script, with read_from_server: true, ready to pass on the next call. A state_command_purpose response that ends in pending_approval can carry the same suggestion. If the held line named a bare interpreter such as bash, arguments.interpreter in the suggestion is null, and the suggestion adds interpreter_name and an instruction that asks you to set it to the interpreter’s absolute path on the host, for example from command -v bash there. A held command that was given data gets no suggestion. The held command stays queued and runs if approved, and no MCP tool cancels it: have a human cancel it in the Alpacon console’s command history before switching to execute_file, or the script waits on two approval requests.

When the held line instead carries a script body (a multi-line program passed to an interpreter such as python -c or bash -c, a heredoc, or an encoded body decoded into an interpreter such as base64 -d | bash; a plain one-line pipeline such as cat x.py | python3 does not count, and chaining commands with && does not count by itself), the server can report it. The pending_approval result of execute_command, check_command_status, or state_command_purpose then carries script_body_suggestion ({"signal": "embedded_script"}), and its message says to move the body into a file and run it with execute_file and write_file: true. For code that runs inside a container or pod, the message says to put the container command and the whole program in one host script. The approver then reviews the code itself, and a standing approval can cover unchanged re-runs of that file; the first run still waits for approval. execute_file_suggestion takes precedence when both apply; a held command that was given data, or one held for the Work Session assignee’s own confirmation (approval_lane: "assignee"), gets neither. Nothing is rewritten or resubmitted: the held command stays queued, so have a human cancel it as above before sending the script.

Example

“Run df -h on web-01 and show me the disk usage”

The agent calls execute_command with server_id set to web-01’s UUID and command="df -h", waits for the result, and reports stdout back to the user.

“Restart nginx on api-02 inside my current work session”

The agent passes work_session_id (or relies on ALPACON_WORK_SESSION) so the restart is recorded against that session for audit.

execute_command_multi_server

Runs the same shell command on multiple servers, either in parallel (default) or sequentially with parallel=false. Returns per-server success/failure status. This tool only submits the commands—it does not wait for results. Each accepted server entry carries its command_id; read that server’s result with check_command_status, or browse with list_commands.

Use this for fleet-wide operations: deploying a config change, checking a version, or running the same diagnostic across many servers in one call instead of repeated execute_command calls.

Access: Additive

Parameters

ParameterTypeRequiredDescription
server_idsarrayYesTarget server IDs
commandstringYesShell command to execute
shellstringNoShell to run the command in (default: system)
usernamestringNoSystem user to run the command as
groupnamestringNoSystem group to run the command as (default: alpacon)
envobjectNoEnvironment variables to set for the command
parallelbooleanNoSubmit to all servers concurrently (default: true); set false to submit sequentially
work_session_idstringNoWork Session to link these commands to, for audit. Falls back to ALPACON_WORK_SESSION if omitted
purposestringNoWhat the batch is for, sent with every command. This tool never waits on a command, so it is never asked for a purpose afterward; stating one here is the only chance. A purpose over 2,000 characters is trimmed, and the response then carries purpose_truncated: true

Example

“Run systemctl status nginx on all three web servers”

The agent calls execute_command_multi_server with server_ids set to the three UUIDs and command="systemctl status nginx", then reports which servers succeeded and which failed.

Verified script execution

execute_file

Run a script on a server as a reviewed execution: you submit its exact contents along with the path, and the run only proceeds if the bytes on the host’s disk still hash to what you submitted. Prefer this over execute_command for anything longer than a one-off line—a deploy script, a heredoc, anything you’d otherwise run as bash /path/to/file.

The advantage over a plain shell line shows up on repeat runs: once a reviewer approves a script, an unchanged re-run of it—same bytes, same server, same account, same arguments—can proceed without pausing for another approval. A shell line passed to execute_command never earns that, because nothing about a path alone proves what will actually run. Approval covers exactly those bytes, on that server, as that account, with those arguments; changing even one byte sends the script back for review. The interpreter, its libraries, and anything the script fetches or runs at runtime are the script’s own responsibility—only this entry point is checked.

Pass reuse_days to propose how long a standing approval stays reusable, from 1 to 366 days. A proposal is not a grant: the approver decides whether to grant reuse at all. A standing approval always expires, at the latest at the workspace ceiling, which is 1 to 366 days (90 by default). A proposal above the ceiling is refused with file_exec_reuse_exceeds_max rather than shortened; resubmit with a shorter reuse_days or none. Without reuse_days, the request proposes no duration, and the approver may still grant reuse up to the ceiling.

content must be byte-for-byte identical to the file at path on the target host, including any trailing newline; a mismatch fails the run rather than guessing at what was meant. The file gets there in one of three ways:

  • Already on the host: pass read_from_server: true and omit content. The call reads the file at path as username and submits its exact bytes. An empty file, a file over 64 KB, or one that is not UTF-8 text is refused before anything is submitted. read_from_server cannot be combined with write_file or content.
  • Written in the same call: pass content with write_file: true. The call writes content to path as username, waits until the host reports the file written, and only then submits the same bytes. A file already at path is refused unless overwrite is also true, and a replaced file keeps its owner and mode. Pass username whenever ownership matters: without it, the server’s default account writes the file. If the write fails, nothing is submitted; if the run is later denied, the written file stays on the host.
  • Uploaded separately: upload it first, e.g. with webftp_upload_content, then pass content.

Either way, the agent still checks the file on disk against the submitted bytes when it runs, so a file changed in between fails the run. path and interpreter must be absolute paths (e.g. /opt/deploy.sh, /bin/bash); a bare command name like bash is rejected. Put pipes, redirection, &&, and environment variables inside the script itself—free-form shell composition around a reviewed file isn’t available on this path; use execute_command for a one-off composed command instead.

write_file and read_from_server wait up to about 60 seconds for the host to finish the write or read, before and on top of timeout. If the transfer fails, nothing is submitted, and the result carries error_code file_write_failed or file_write_timeout for a write, or file_read_failed or file_read_timeout for a read. read_from_server combined with write_file or content, or overwrite without write_file, is refused with file_exec_invalid_options before anything reaches the host.

Both options move the script through WebFTP. An OAuth or browser caller’s Work Session needs the webftp scope, and a static API token or service token needs a file ACL that allows upload (for write_file) or download (for read_from_server) on path.

Warning

Because of these options, the commands toolset alone reaches WebFTP. Leaving webftp out of --toolsets doesn’t keep file transfers from the agent.

Otherwise it behaves like execute_command: a sudo inside the script that no Work Session sudo policy covers is denied at once and reported in sudo_denial or sudo_hint the same way, a pending_approval result with category COMMAND_AWAITING_APPROVAL means the script runs on its own once a human approves it, and a result asking for a purpose is answered with state_command_purpose.

Access: Additive

Parameters

ParameterTypeRequiredDescription
server_idstringYesTarget server ID
pathstringYesAbsolute path to the script on the server. Must already exist there unless write_file is true
contentstringNoThe script’s exact contents, byte-for-byte as they are on disk (up to 64 KB). This is what gets reviewed. Required unless read_from_server is true
write_filebooleanNoWrite content to path on the server before submitting, in the same call (default: false)
overwritebooleanNoWith write_file, replace a file already at path (default: false)
read_from_serverbooleanNoRead the script at path on the server and submit those bytes as content (default: false)
interpreterstringNoAbsolute path to the interpreter (default: /bin/bash)
argsarrayNoArguments to pass to the script
reuse_daysintegerNoProposed number of days, 1 to 366, that a standing approval of this script stays reusable. The approver decides whether to grant it
usernamestringNoSystem user to run the script as
groupnamestringNoSystem group to run the script as (default: alpacon)
run_afterarrayNoCommand IDs this run should run after
scheduled_atstringNoSchedule the run for a future time instead of running immediately
timeoutintegerNoSeconds to wait for completion before timing out (default: 300)
work_session_idstringNoWork Session to link this run to, for audit. Falls back to ALPACON_WORK_SESSION if omitted
purposestringNoWhy this run is needed on this host. Answers a purpose request up front instead of pausing for it

Example

“Run the deploy script I just uploaded to /opt/deploy.sh on web-01”

The agent calls execute_file with server_id set to web-01’s UUID, path="/opt/deploy.sh", and content set to the script’s exact text. Once a reviewer approves that script for that server, later unchanged runs proceed without another approval round-trip.

“Run /opt/backup.sh, which is already on db-01”

The agent calls execute_file with path="/opt/backup.sh" and read_from_server=true, so it never has to copy the script’s text itself.

state_command_purpose

Answer a pending purpose request on a command, then wait for the outcome. Use this when execute_command or execute_file returns a result asking for a purpose—the command_id to use here is in that response. The command is re-evaluated once with your purpose attached, and this call returns whatever that produces: the command’s output if it clears, a pending-approval result if a human is still needed, or an error if it’s denied outright.

Answer promptly—the request expires in about a minute—and only once: a late or second answer is refused, and only the caller that submitted the original command may answer for it. State something concrete and specific to this host; repeating context the caller already gave doesn’t change the outcome.

Access: Additive

Parameters

ParameterTypeRequiredDescription
command_idstringYesCommand ID from the result that asked for a purpose
purposestringYesWhy this command is needed on this host
timeoutintegerNoSeconds to wait for the re-evaluated result (default: 300)

Example

“The restart command is asking why—tell it we’re clearing a memory leak reported in last night’s incident”

The agent calls state_command_purpose with the pending command_id and purpose="Restarting nginx to clear a memory leak reported in incident #482", then reports the outcome once the command runs.

Last updated: