Execute a shell command
POST/command/shell
Execute a command through /bin/sh -c. Supports shell features like pipes, redirects, and variable expansion.
Request
Query Parameters
Default value: _any
Target: _any (load-balanced), _all (broadcast), hostname (direct), or key:value (label group, e.g., group:web.dev).
- application/json
Body
required
The shell command to execute.
The full shell command string.
Working directory for the command.
Possible values: >= 1 and <= 300
Default value: 30
Timeout in seconds (default 30, max 300).
Responses
- 202
- 400
- 401
- 403
- 500
Shell command execution accepted.
- application/json
- Schema
- Example (from schema)
Schema
Array [
]
The job ID used to process this request.
results
object[]
required
The hostname of the agent that executed the command.
Standard output of the command.
Standard error output of the command.
Exit code of the command.
Execution time in milliseconds.
Whether the command modified system state.
Error message if the agent failed to process the request.
{
"job_id": "550e8400-e29b-41d4-a716-446655440000",
"results": [
{
"hostname": "string",
"stdout": "string",
"stderr": "string",
"exit_code": 0,
"duration_ms": 0,
"changed": true,
"error": "string"
}
]
}
Invalid request payload.
- application/json
- Schema
- Example (from schema)
Schema
A description of the error that occurred.
Additional details about the error.
The error code.
{
"error": "Failed to retrieve status.",
"details": "Failed due to network timeout.",
"code": 500
}
Unauthorized - API key required
- application/json
- Schema
- Example (from schema)
Schema
A description of the error that occurred.
Additional details about the error.
The error code.
{
"error": "Failed to retrieve status.",
"details": "Failed due to network timeout.",
"code": 500
}
Forbidden - Insufficient permissions
- application/json
- Schema
- Example (from schema)
Schema
A description of the error that occurred.
Additional details about the error.
The error code.
{
"error": "Failed to retrieve status.",
"details": "Failed due to network timeout.",
"code": 500
}
Error executing shell command.
- application/json
- Schema
- Example (from schema)
Schema
A description of the error that occurred.
Additional details about the error.
The error code.
{
"error": "Failed to retrieve status.",
"details": "Failed due to network timeout.",
"code": 500
}