> For the complete documentation index, see [llms.txt](https://developer.harness.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://developer.harness.io/resilience-testing/chaos-testing/actions/custom-script-action.md).

# Custom Script Action

Configure a custom script action in Harness Resilience Testing to run scripts or commands at any point during chaos experiment execution

## What is a custom script action? <a href="#what-is-a-custom-script-action" id="what-is-a-custom-script-action"></a>

A **Custom Script Action** allows you to execute custom scripts or commands during chaos experiment execution. This provides powerful flexibility to:

* Run custom validation logic beyond standard probes
* Perform setup or cleanup operations specific to your environment
* Execute application-specific commands or API calls
* Integrate with external systems, tools, or monitoring platforms
* Implement complex business logic validation
* Perform data collection or analysis during experiments

## When to use custom script actions <a href="#when-to-use-custom-script-actions" id="when-to-use-custom-script-actions"></a>

Custom Script Actions are particularly valuable in the following scenarios:

### Custom validation <a href="#custom-validation" id="custom-validation"></a>

Use cases in this category include the following:

* **Business Logic Validation**: Verify application-specific business rules
* **Data Integrity Checks**: Validate data consistency across systems
* **Performance Metrics**: Collect custom performance measurements
* **Complex Assertions**: Implement validation logic that goes beyond simple HTTP checks

### System integration <a href="#system-integration" id="system-integration"></a>

Use cases in this category include the following:

* **External API Calls**: Interact with external services or APIs
* **Database Operations**: Perform database queries or validations
* **File System Operations**: Check file system state or perform file operations
* **Network Diagnostics**: Run custom network connectivity tests

### Environment setup and cleanup <a href="#environment-setupcleanup" id="environment-setupcleanup"></a>

Use cases in this category include the following:

* **Pre-experiment Setup**: Prepare the environment before chaos injection
* **Post-experiment Cleanup**: Clean up resources after experiment completion
* **State Preparation**: Set up specific system states required for the experiment
* **Resource Management**: Manage test data or temporary resources

### Observability and alerts <a href="#monitoring-and-alerting" id="monitoring-and-alerting"></a>

Use cases in this category include the following:

* **Custom Metrics Collection**: Gather application-specific metrics
* **Alert Validation**: Verify that alerts are triggered correctly
* **Log Analysis**: Parse and analyze application logs
* **Dashboard Updates**: Update custom dashboards or reporting systems

## How to configure a custom script action <a href="#how-to-configure-a-custom-script-action" id="how-to-configure-a-custom-script-action"></a>

### Step 1: Create a new action <a href="#step-1-create-a-new-action" id="step-1-create-a-new-action"></a>

Perform the following steps:

1. Navigate to your **Probes & Actions** and go to the **Actions** tab
2. Click **New Action** and select **Custom Script** from the dropdown.

   ![delay action](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-6c3973c4ec55b809ab6b42bdc0d2cc67a743aad3%2Fcreate-delay-action.png?alt=media)

### Step 2: Configure script parameters <a href="#step-2-configure-script-parameters" id="step-2-configure-script-parameters"></a>

Configure the following parameters for your custom script action:

* **Action Name**: Provide a descriptive name for the custom script action
* **Infrastructure Type**: Select the target infrastructure (e.g., Kubernetes)

  ![configure custom script action](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-138fd08ed8fb8dcb835d1272358a60194d6df466%2Fconfigure-custom-script-action.png?alt=media)

### Step 3: Configure action properties <a href="#step-3-configure-action-properties" id="step-3-configure-action-properties"></a>

In the Action Properties section, configure the script details:

* **Command**: Enter the command or script to execute (e.g., `/bin/sh`)
* **Arguments**: Add command arguments or script parameters
  * You can add multiple arguments by clicking the **Add** button
  * Each argument can be edited or removed using the edit/delete icons
* **Environment Variables**: Define environment variables needed by the script
  * Click **Add** to add new environment variables
  * Set key-value pairs for variables your script requires

    ![custom script action properties](https://3217710372-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRmV5EkLS9r45VPaoUnJZ%2Fuploads%2Fgit-blob-5432a5e6ae26b97b37396136434d599f9ecdde88%2Fcustom-script-action-properties.png?alt=media)

### Step 4: Position the action <a href="#step-4-position-the-action" id="step-4-position-the-action"></a>

Place the custom script action at the appropriate point in your experiment workflow:

* **Pre-experiment**: Setup or validation before chaos injection
* **Mid-experiment**: Validation or data collection during chaos
* **Post-experiment**: Cleanup or final validation after chaos
* **Between Phases**: Transition logic between different experiment phases

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

<details>

<summary>A Kubernetes custom script action does not run in a Linux or Windows experiment</summary>

Kubernetes actions run in a Linux or Windows experiment only when a Kubernetes infrastructure is mapped to the experiment or to the action. Go to [Remote Kubernetes execution](https://developer.harness.io/resilience-testing/chaos-testing/actions.md#remote-kubernetes-execution) to map a Kubernetes infrastructure.

</details>

<details>

<summary>The script cannot reach an external system or API</summary>

The script makes its calls from the chaos infrastructure, so that infrastructure requires network connectivity to the endpoint. Confirm that the chaos infrastructure can reach the endpoint, and that any credentials the script requires are defined in **Environment Variables**.

</details>

## Next steps <a href="#next-steps" id="next-steps"></a>

* [Learn about Delay Actions](https://developer.harness.io/resilience-testing/chaos-testing/actions/delay-action.md)
* Explore experiment timeline view (see Experiments documentation)
* [Create experiments with actions](https://developer.harness.io/resilience-testing/chaos-testing/experiments.md)
* [Learn about Probes](https://developer.harness.io/resilience-testing/chaos-testing/probes.md)

{% @harness-feedback/feedback %}
