---
type: api
title: Run a command
description: **Spaces method and path for this operation:**
url: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-endpointexecuteaction
resource: https://www.elastic.co/elastic/docs-builder/docs/4371/api/doc/kibana/operation/operation-endpointexecuteaction
products:
  - Kibana
---

# Run a command

- Server: `https://{kibana_url}`

## Paths

- `POST` `/api/endpoint/action/execute`
- `POST` `/s/{space_id}/api/endpoint/action/execute`

- [Api key auth](/elastic/docs-builder/docs/4371/api/doc/kibana/authentication#apikeyauth)
- [Basic auth](/elastic/docs-builder/docs/4371/api/doc/kibana/authentication#basicauth)

## Description

Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

Run a shell command on an endpoint.

## Request Body

`application/json`

- `agent_type` (enum) — optional
  List of agent types to retrieve. Defaults to `endpoint`.
  Values: `endpoint`, `sentinel_one`, `crowdstrike`, `microsoft_defender_endpoint`
- `alert_ids` ([] string · min: 1 · max: 50) — optional
  If this action is associated with any alerts, they can be specified here. The action will be logged in any cases associated with the specified alerts. Max of 50.
- `case_ids` ([] string · min: 1 · max: 50) — optional
  The IDs of cases where the action taken will be logged. Max of 50.
- `comment` (string · max: 30000) — optional
  Optional comment
- `endpoint_ids` ([] object · min: 1 · max: 250) — required
  List of endpoint IDs (cannot contain empty strings). Max of 250.
- `parameters` (object) — required
  Parameters object

## Response

Indicates a successful call.

`application/json`

- `data` ({})
  - `agents` ([] string)
    The agent IDs for the hosts that the response action was sent to
  - `agentState` (map string to object)
    The state of the response action for each agent ID that it was sent to
    Map values (object)
    - `completedAt` (string)
      The date and time the response action was completed for the agent ID
    - `isCompleted` (boolean)
      Whether the response action is completed for the agent ID
    - `wasCanceled` (boolean)
      Whether the response action was canceled for the agent ID
    - `wasSuccessful` (boolean)
      Whether the response action was successful for the agent ID
  - `agentType` (enum)
    List of agent types to retrieve. Defaults to `endpoint`.
    Values: `endpoint`, `sentinel_one`, `crowdstrike`, `microsoft_defender_endpoint`
  - `command` (enum  · min: 1)
    The command for the response action
    Values: `isolate`, `unisolate`, `kill-process`, `suspend-process`, `running-processes`, `get-file`, `execute`, `upload`, `scan`, `runscript`, `cancel`, `memory-dump`
  - `completedAt` (string)
    The response action completion time
  - `createdBy` (string)
    The user who created the response action
  - `hosts` (map string to object)
    An object containing the host names associated with the agent IDs the response action was sent to
    Map values (object)
    - `name` (string)
      The host name
  - `id` (string)
    The response action ID
  - `isComplete` (boolean)
    Whether the response action is complete
  - `isExpired` (boolean)
    Whether the response action is expired
  - `outputs` (map string to object)
    The outputs of the response action for each agent ID that it was sent to. Content different depending on the
response action command and will only be present for agents that have responded to the response action
    Map values (object)
    - `content` (string | object)
      The response action output content for the agent ID. Exact format depends on the response action command.
    - `type` (enum)
      Values: `json`, `text`
  - `parameters` (object)
    The parameters of the response action. Content different depending on the response action command
  - `startedAt` (string)
    The response action start time
  - `status` (string)
    The response action status
  - `wasCanceled` (boolean)
    Whether the response action was canceled
  - `wasSuccessful` (boolean)
    Whether the response action was successful
## Code Examples

#### Console

```console
POST /api/endpoint/action/execute
{
  "comment": "Get list of all files",
  "endpoint_ids": [
    "b3d6de74-36b0-4fa8-be46-c375bf1771bf"
  ],
  "parameters": {
    "command": "ls -al",
    "timeout": 600
  }
}
```

#### curl

```curl
curl -X POST "https://{kibana_url}/api/endpoint/action/execute" \
  -H "Content-Type: application/json" \
  -d '{
  "comment": "Get list of all files",
  "endpoint_ids": [
    "b3d6de74-36b0-4fa8-be46-c375bf1771bf"
  ],
  "parameters": {
    "command": "ls -al",
    "timeout": 600
  }
}'
```

## Response Examples

#### Execute action successfully created

```json
{
  "data": {
    "agents": [
      "ed518850-681a-4d60-bb98-e22640cae2a8"
    ],
    "agentState": {
      "ed518850-681a-4d60-bb98-e22640cae2a8": {
        "isCompleted": false,
        "wasSuccessful": false
      }
    },
    "agentType": "endpoint",
    "command": "execute",
    "createdBy": "elastic",
    "hosts": {
      "ed518850-681a-4d60-bb98-e22640cae2a8": {
        "name": "gke-node-1235412"
      }
    },
    "id": "9f934028-2300-4927-b531-b26376793dc4",
    "isCompleted": false,
    "isExpired": false,
    "outputs": {},
    "parameters": {
      "command": "ls -al",
      "timeout": 600
    },
    "startedAt": "2023-07-28T18:43:27.362Z",
    "status": "pending",
    "wasSuccessful": false
  }
}
```

