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

# Run a script

Authentication: required

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

## Paths

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

#### Path parameters

- `space_id` (string) — optional
  An identifier for the space. If `space_id` is not provided in the URL, the default space is used. Refer to [Spaces](https://www.elastic.co/docs/deploy-manage/manage-spaces) for more information.

## Description

Run a shell command on an endpoint.

## Request body

`application/json`

- `parameters` (union oneOf) — required
  Exactly one of 'Raw', 'HostPath', or 'CloudFile' must be provided. CommandLine and Timeout are optional for all.
  - **RawScriptParameters**
    - `commandLine` (string · min length: 1) — optional
      Command line arguments.
    - `raw` (string · min length: 1) — required
      Raw script content.
    - `timeout` (integer · min: 1) — optional
      Timeout in seconds.
  - **HostPathScriptParameters**
    - `commandLine` (string · min length: 1) — optional
      Command line arguments.
    - `hostPath` (string · min length: 1) — required
      Absolute or relative path of script on host machine.
    - `timeout` (integer · min: 1) — optional
      Timeout in seconds.
  - **CloudFileScriptParameters**
    - `cloudFile` (string · min length: 1) — required
      Script name in cloud storage.
    - `commandLine` (string · min length: 1) — optional
      Command line arguments.
    - `timeout` (integer · min: 1) — optional
      Timeout in seconds.

## Response

OK

`application/json`

Type: `object`

## Code examples

#### Console

```console
POST kbn:/api/endpoint/action/runscript
{
  "parameters": {
    "raw": "string"
  }
}
```

#### curl

```curl
curl -X POST "${KIBANA_URL}/api/endpoint/action/runscript" \
  -H "Authorization: ApiKey ${API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "parameters": {
      "raw": "string"
    }
  }'
```

## Response examples

#### 200

`application/json`

Generated from the API spec. Values are representative. Unions use the first variant; deeply nested or large bodies may omit fields.

```json
{}
```

