> 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

### 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>

* **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>

* **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/Cleanup <a href="#environment-setupcleanup" id="environment-setupcleanup"></a>

* **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

#### Monitoring and Alerting <a href="#monitoring-and-alerting" id="monitoring-and-alerting"></a>

* **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>

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](/files/QOmiyBKOL3txDGR4YoLC)

#### 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](/files/PQ1QbkGwvbvCrxnejwOb)

#### 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](/files/iwIzXb57bY7hBLfS1cfw)

#### 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

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

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