alpacon exec
Run a command or verified script on a remote server.
Usage
alpacon exec [flags] [USER@]SERVER [--] [COMMAND...]
alpacon exec [command]
Key facts
- Place every CLI flag before the server name.
- Use
--after the server to separate the remote command. - Use
--detachfor background execution andexec logs JOB_IDfor results. - Use
--fileto submit a script for verified execution.
Flags
Command and account
| Flag | Type | Description |
|---|---|---|
-u, --username | string | Specify the username for command execution. |
-g, --groupname | string | Specify the group name for command execution. |
--env | strings | Pass KEY to read a value from your shell, or KEY=VALUE for a literal value. Repeatable. Use the key-only form for secrets; literal values remain in local command history. |
--work-session | string | Attach this command to a work-session. Overrides the workspace’s active session set via ‘alpacon work-session use’. |
--purpose | string | Explain this command’s purpose in up to 2,000 characters. State facts specific to this host; purpose does not reduce the command’s risk. |
Script execution
| Flag | Type | Description | Default |
|---|---|---|---|
--file | string | Absolute script path on the server. Reads matching local content (up to 64 KB); arguments follow --. Cannot use a command line or --env. | — |
--file-from | string | Read the script from this local path. Its contents must match the server file. | — |
--upload | bool | Write the local script to --file before submitting it. Existing files need --overwrite; the path cannot contain ., .., repeated slashes, or a trailing slash. | false |
--overwrite | bool | With --upload, replace an existing file while keeping its owner and mode. | false |
--from-server | bool | Read the script on the server as the selected account and group. Cannot combine with --upload or --file-from. | false |
--interpreter | string | Absolute interpreter path for --file. | /bin/bash |
--reuse-days | int | Propose 1–366 days of approval reuse for --file. The approver decides; requests above the workspace limit are refused. | — |
Approval and output
| Flag | Type | Description | Default |
|---|---|---|---|
--detach | bool | Return the job ID without waiting for completion. Read results with exec logs JOB_ID; an agent command may still wait for its purpose. | false |
--wait | bool | Wait and retry a sudo command until console approval or timeout (5 minutes by default). | false |
--wait-approval | string | Set a custom approval wait, such as 30m. Implies --wait; the usual wait is 5m. | — |
-h, --help | bool | help for exec | false |
--output | string | Output format: table or json | table |
Examples
Execute a command on a server
alpacon exec my-server ls -la /var/logExecute as a specific user
alpacon exec admin@my-server cat /etc/hostname
alpacon exec -u admin my-server cat /etc/hostnameExecute with a specific group
alpacon exec -g developers my-server whoamiUse -- to pass flags to the remote command
alpacon exec root@db-server -- docker exec postgres psql -U myproject -d myproject
alpacon exec my-server -- grep -r "pattern" /var/logRun multiple commands—the quotes keep && from being interpreted by your local shell
alpacon exec my-server -- "df -h && free -m"Shell metacharacters (;, |, &, $) are interpreted by your local shell first—quote the remote command to send them to the server, where the remote shell interprets them again. To pass one as a literal character, add inner quotes so the remote shell does not interpret it either
alpacon exec my-server -- "echo 'hello;world'"Attach the command to a specific work session
alpacon exec --work-session 11111111-2222-3333-4444-555555555555 my-server -- df -hPass an environment variable to the remote command
alpacon exec --env="KEY1=VALUE1" --env="KEY2=VALUE2" my-server -- printenv KEY1Read a secret from the current shell without putting it on the command line or in the audit log
alpacon exec --env="PGPASSWORD" db-server -- psql -h localhost -U app -c 'SELECT 1'If a secret ends up on the command line anyway—a secret-like KEY=VALUE pair, a password flag (e.g. -pSecret123), or a connection string with an embedded password—the server rejects the command with command_inline_credential before it runs. Move the secret to --env instead.
Details
Execute a command directly on a remote server without opening an interactive terminal session. This is useful for running one-off commands, automation scripts, or retrieving output from a server.
All flags must be placed before the server name—everything after the server name is treated as the remote command. Use -- to separate the remote command explicitly, so its flags (such as -U or -d) are not interpreted as alpacon flags.
Subcommands
alpacon exec ls: List recent command executions.alpacon exec logs JOB_ID: Fetch an asynchronous execution result.alpacon exec purpose JOB_ID PURPOSE: Answer a held command’s purpose request.
exec ls
List recent remote command executions, most recent first.
alpacon exec ls [flags]
Aliases: ls, list
| Flag | Type | Description | Default |
|---|---|---|---|
-h, --help | bool | help for ls | false |
-s, --server | string | Filter by server name | — |
-t, --tail | int | Number of command entries to show, newest first | 25 |
-u, --user | string | Filter by requesting user | — |
--output | string | Output format: table or json | table |
List the 25 most recent executions
alpacon exec lsNarrow to one server and one user
alpacon exec ls --tail 10 --server my-server --user admin--tail returns exactly the number of entries you ask for—--tail 250 gets you 250 entries.
exec purpose
When a command from an AI agent’s work session would wait for a person, Alpacon may hold it and ask what it is for instead. alpacon exec then exits with code 7 and prints the job ID. Answer within about a minute and the command is judged again with your answer in hand; if you don’t answer, it continues on its usual path. Only the requester who submitted the command can answer.
alpacon exec purpose JOB_ID PURPOSE [flags]
Answer a held command
alpacon exec purpose a1b2c3d4-5678-abcd-ef01-234567890abc \
'The host clock is 40s ahead, so the renewed cert reads as not-yet-valid.'To skip the question, state the purpose when you run the command
alpacon exec --purpose 'chronyd drifted; the cert reads as future-dated' \
prod-web -- systemctl restart chronydA useful purpose states a fact about this server that the work session’s description doesn’t already say. It can’t lower a command’s own risk.
Verified file execution
Use --file to run a script on the target server, instead of typing a command line. The reviewer sees the exact bytes you are about to run, and the platform makes sure the server executes those same bytes—not whatever happens to be at that path by the time the command runs.
--file PATH takes the absolute path of the script on the target server. The CLI reads the script’s content from the same path on your local machine, unless you pass --file-from LOCAL_PATH to read it from somewhere else. Either way, the local copy must be byte-identical to the file on the server, or the agent refuses to run it. Two flags save you from putting the script in both places by hand:
--uploadwrites the local script to the--filepath on the server, then submits the same bytes, in one step. The file is written as the account and group the script runs as (-uorUSER@,-g, or the server’s default account when neither is given); a new file takes that account’s umask, missing directories are created, and no execute bit is needed. A file already at that path is refused unless you pass--overwrite, and an overwritten file keeps its owner and mode. The path must be clean: no.or..and no repeated or trailing slash. A failed write stops the run before anything is submitted; a successful write stays on the server even if the submission is then refused.--from-serverreads the script from the--filepath on the server, as the account and group the script runs as, and submits those bytes, so no local copy is needed. A file that cannot be read, is empty, exceeds 64 KB, or is not UTF-8 text is refused before anything is submitted.--from-servercannot be combined with--uploador--file-from.
In both cases the agent still checks the file on the server against the submitted bytes when it runs.
--interpreter PATH sets the interpreter that runs the script (default /bin/bash) and must be an absolute path. Script arguments go after --; --file does not take a command line or --env.
An approval binds those exact bytes, on that server, as that account, with those arguments—not “the file in general”. A reviewer can mark an approval as standing, and an unchanged re-run then stops asking anyone; one changed byte sends it back for review.
--reuse-days N proposes 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, after the proposed days or at the workspace ceiling, which is 1 to 366 days (90 by default). If N is above the ceiling, the server refuses the request with file_exec_reuse_exceeds_max rather than shortening it; resubmit with a shorter --reuse-days or none. Without the flag, the request proposes no duration, and the approver may still grant reuse up to the ceiling. --reuse-days requires --file.
The reviewer sees the script’s arguments along with its content, so never put a secret in an argument or in the script itself. Have the script read it from an environment variable or a file on the host at run time. The server refuses a script that carries a credential, the same way it refuses a command line that does. The script itself is limited to 64 KB.
Run a script the reviewer can read, verified byte-for-byte on the server:
alpacon exec --file /opt/deploy.sh root@prod-web -- --fastRead the local copy from a different path and choose an interpreter:
alpacon exec --file /opt/deploy.sh --file-from ./deploy.sh --interpreter /bin/sh prod-webRun a script that exists only on the server:
alpacon exec --file /opt/deploy.sh --from-server root@prod-web -- --fastWrite a local script to the server and run it, in one step:
alpacon exec --upload --file /opt/deploy.sh --file-from ./deploy.sh root@prod-web -- --fastPropose that the approval stay reusable for 30 days:
alpacon exec --file /opt/deploy.sh --reuse-days 30 root@prod-web -- --fastAsynchronous execution
Use --detach to submit a command and return immediately instead of waiting for it to finish. The CLI prints Job submitted: JOB_ID to stdout (or {"job_id": "..."} with --output json).
alpacon exec --detach web-server -- apt-get updateRetrieve the result later with alpacon exec logs:
alpacon exec logs a1b2c3d4-5678-abcd-ef01-234567890abcJOB_ID must be a UUID. exec logs reports the job’s status as follows:
| Job status | Exit code |
|---|---|
| Running, queued, delivered, verifying, acknowledged, or scheduled | 0; check the same job again later |
| Awaiting purpose, if your workspace asks for one | 7 |
| Awaiting approval | 4 |
| Rejected | 6 |
| Stuck, error, or cancelled | 1 |
| Finished | The remote command’s exit code |
A 0 while the command is still running does not mean it finished. For work that may take longer than about 10 minutes, use --detach: a foreground exec reports stuck and exits 1 after 10 minutes without a result following acknowledgment or delivery, while the command keeps running on the server for up to 30 minutes. See long-running commands.
Exit codes
For a finished command, alpacon exec returns the remote command’s exit code. CLI failures and held commands have these outcomes:
- 1: general failure, including stuck, error, cancelled, the CLI giving up its wait for a result (
client_timeout, set byALPACON_EXEC_TIMEOUT), an inline credential refusal, or any other flag or argument the command rejects. - 2:
exec lswith a--tailof zero or less. - 6: rejected, or not approved before the request expired.
- 7: purpose required, if your workspace asks for one. Answer with
alpacon exec purpose JOB_ID PURPOSE.
See command troubleshooting for recovery steps.
Exit code 3 indicates the command was denied by the work session gate (for example, no active session or the session does not cover the target server). With --output json, a machine-readable diagnostic is printed to stderr. See Gate errors for the error codes.
Exit code 4 indicates the sudo command is pending human approval. Approve it in the Alpacon console, then re-run—or pass --wait to block until it is approved. If --wait ends before anyone decides, because the wait timed out or the CLI could not read the approval status, the command is still pending and the CLI also exits 4. With --output json, the CLI emits {"status": "pending_approval", ...} on stdout.
A command held for approval in the Alpacon console also exits with code 4, and so does a --wait on it that ends before anyone decides. The exception is a run where the CLI warns that real-time output is unavailable and falls back to polling: there, a --wait that runs out exits 1 with client_timeout. When that command runs a script on the server, such as bash /opt/deploy.sh, the pending-approval message also suggests the --file --from-server form of it; a sudo request waiting for approval gets no suggestion. If the command named its interpreter by a bare name such as bash, the suggestion carries an --interpreter placeholder; replace it with the absolute path that command -v bash prints on the server. The suggestion is left out when the command used --env. The held command stays queued and runs if approved, and the CLI cannot cancel it. Cancel it in the Alpacon console’s command history before you submit the suggested form, or the script waits on two approval requests.
Work session requirement
When you sign in with browser login, alpacon exec requires an active work session that includes the command scope; --upload and --from-server also need the webftp scope. Service-token authentication bypasses this requirement.
New personal API tokens cannot hold command-execution or file-transfer scopes. Existing tokens with those scopes keep working without a work session. Use a service token for automation and CI.
The session to attach is resolved from the --work-session flag, the ALPACON_WORK_SESSION environment variable, or the active session set with alpacon work-session use—in that order.
MFA authentication
When executing commands as a system account (e.g., root@my-server), your workspace’s Authentication settings may require additional MFA verification. The CLI MFA flow is the same as alpacon websh—see websh MFA authentication for details.
API token ACLs
A token must have ACL rules for each command you intend to execute. Tokens cannot open interactive Websh; non-interactive exec commands require matching command ACL rules.
# Allow the commands this token can run on servers
alpacon token acl command add my-token --command="df *"
alpacon token acl command add my-token --command="cat /etc/hostname"--upload and --from-server also need a file ACL that covers the --file path: the upload action for --upload, and the download action for --from-server. See alpacon token acl file add.
See Token ACL management for details on wildcard patterns.