Skip to content

Run a command on a VM

POST/v1/vms/{uid}/exec

Runs one non-interactive command on a running VM over SSH and waits for it to finish. The command runs as bash -lc '<command>'.

  • Command execution through the API is off by default. A workspace owner or admin must turn it on in workspace settings, otherwise this returns 403.
  • Requires the runtime connect permission (owner, admin or developer role).
  • The command times out after 30 seconds by default, or timeout_seconds (max 60).
  • stdout and stderr are each capped at 64 KiB. Truncation is flagged in the response.
  • Each user can have at most 4 console sessions and commands open at once.
  • The first command on an older VM may return 409 while command access is set up. Retry after about 30 seconds.

A non-zero exit_code is still a 200 response. When the command times out, timed_out is true and exit_code is usually 124, or -1 if the VM never returned one.

Authentication

Send your API key as Authorization: Bearer <token>. The request is scoped to the workspace in X-Workspace-Slug.

Path parameters

uidstringRequired

The VM's uid.

Headers

X-Workspace-SlugstringRequired

Slug of the workspace the request acts on. You can also pass it as the workspace_slug query parameter.

Request body

commandstringRequired

Shell command to run. Leading and trailing whitespace is trimmed. At most 8192 bytes.

max length 8192

timeout_secondsinteger

Seconds to let the command run. Values above 60 are capped at 60. 0 or omitted means 30.

Default 30min 1 · max 60

Response

200

The command ran. Check exit_code to see whether it succeeded.

successbooleanRequired

true when the request succeeded.

messagestringRequired

Human-readable status message.

dataobject
Show attributes
exit_codeintegerRequired

Exit status of the command. 124 usually means it hit the timeout. -1 means no exit status was returned.

stdoutstringRequired

Standard output, up to 64 KiB. Invalid UTF-8 is replaced.

stderrstringRequired

Standard error, up to 64 KiB. Invalid UTF-8 is replaced.

stdout_truncatedboolean

Present and true when stdout was cut at 64 KiB.

stderr_truncatedboolean

Present and true when stderr was cut at 64 KiB.

timed_outboolean

Present and true when the command was stopped by the timeout.

duration_msintegerRequired

How long the command ran, in milliseconds.

Errors

StatusMeaning
400command is missing or empty (command is required), or longer than 8192 bytes (command is too long).
401The API key is missing, invalid, expired or revoked.
403Your role cannot connect to VMs, or command execution is turned off for this workspace.
404The resource does not exist or you cannot access it.
409The command could not be run right now: vm is not running, vm network route is not ready, too many open console sessions or commands; try again shortly, enabling command access on this VM; retry in about 30 seconds, this VM can't accept commands yet; connect with SSH instead, or unable to reach the VM over SSH.

Errors use the standard error format.