Run a command inside a VPS
POST /api/v2/vps/{id}/agent/exec
Starts a command inside the VPS through the QEMU Guest Agent and returns its process ID. Check available on GET /api/v2/vps/{id}/agent/exec first. The VPS must be running with the agent installed. On Linux the command runs with /bin/sh -c. It is stopped after 30 seconds when the VPS has the timeout command. On Windows it runs in PowerShell. Some destructive commands are refused with 400, for example rm -rf / and mkfs. Poll pollUrl until exited is true, then read stdout, stderr and exitCode.
Authentication: An API key with the scope write:vm. About keys and scopes
Request
Path parameters
idstringrequiredThe VPS ID (
vps_…).Body
commandstringrequiredThe command to run. At most 4096 characters.
Example
curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/agent/exec" \ -H "Authorization: Bearer $HOSTUP_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "command": "uname -a" }'curl -X POST "https://cloud.hostup.se/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/agent/exec" \ -H "Authorization: Bearer $HOSTUP_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "command": "df -h /" }'Responses
200 The command started. Poll pollUrl for its output.
{ "pid": 4242, "pollUrl": "/api/v2/vps/vps_01hxa3b4c5d6e7f8g9h0j1k2m3/agent/exec?pid=4242"}Response fields
pidintegerpollUrlstringPoll this URL until
exited is true.Errors
Errors are Problem Details with a stable code. Branch on the code, not on the text.
| 400 | Invalid request. The response body is an RFC 7807 Problem Details document. |
| 401 | Unauthorized. Authentication is required. |
| 403 | Forbidden. The caller lacks a required scope or does not own the resource. |
| 404 | Not found. The resource does not exist or is not owned by the caller; code is vps_not_found. |
| 409 | The command cannot start now. Branch on code: guest_agent_unavailable (the VPS runs but the agent does not answer; install or restart it inside the server), vps_not_running (start the VPS first) or vps_not_ready (the VPS is still being set up). Retrying without fixing the cause gives the same answer. |
| 429 | Rate limited. Retry after the limit resets. 429 responses include Retry-After seconds plus X-RateLimit-* headers. |
| 500 | Internal error. Retry later or contact support if the issue persists. |