> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xsoar-8-on-prem/8.14/configure-cortex-xsoar/playbooks/scripts/create-a-script.md).

# Create a script

Developing scripts in Cortex XSOAR helps to automate repetitive tasks, streamline security operations, and make incident response more efficient. Customizing scripts can improve threat detection, mitigation, and remediation processes specific to your organization's needs.

Rather than creating a script from scratch, you can edit existing scripts. If the script was installed from a content pack, by default, the script is attached, which means that it is not editable. To edit the script, you need to either make a copy or detach it. While the script is detached, it is not updated by the content pack. This may be useful when you want to update the script without breaking customization. If you want to update the script through content pack updates, you need to reattach it, but any changes are overridden by the content pack on upgrade. If you want to keep the changes, make a copy before reattaching.

{% hint style="info" %}

### Note

* You can enable/disable a script in the Settings, without having to detach or duplicate the script.
* You can view recently modified or deleted scripts by clicking version history for all scripts ![versionhistory.png](/files/GKmWOBbkuITdiHw3N4H9).
  {% endhint %}

1. Select **Scripts** → **New Script**.
2. Add an identifying name for the script.
3. Save the script.

<details>

<summary>Basic script settings</summary>

Define the relevant Basic script parameters.

| Parameter     | Description                                                                                                                                                                                                                                                                                                                                                                                                        |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Name          | An identifying name for the script.                                                                                                                                                                                                                                                                                                                                                                                |
| Language type | Select the script language type.                                                                                                                                                                                                                                                                                                                                                                                   |
| Description   | A meaningful description of the script.                                                                                                                                                                                                                                                                                                                                                                            |
| Tags          | <p>Predefined script identifiers.</p><p>For example, if a script is intended for phishing, tagging it with the phishing tag helps organize, classify, and manage the script among other scripts.</p><p>Organizations can also implement policies or restrictions based on tags associated with scripts. For example, they may restrict certain users from accessing or executing a script tagged for phishing.</p> |
| Enabled       | Whether the script is available for playbook tasks and indicator types, or to run in the CLI.                                                                                                                                                                                                                                                                                                                      |

**Tags**

Script tags enable you to use the script in a specific area in Cortex XSOAR. For example, a script can be tagged to use in post-processing, indicator formatting, field display, and indicator enhancement. The following table includes the commonly used tags:

| Tag Value                       | Description                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Condition                       | <p>Conditional script in a playbook task</p><div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note</strong></p><p>All custom scripts are available for conditional tasks, including scripts without the condition tag. System scripts are only available for use in conditional tasks if they have the condition tag.</p></div> |
| dynamic-indicator-section       | General purpose dynamic section script for indicator layout                                                                                                                                                                                                                                                                                                                 |
| dynamic-section                 | General purpose dynamic section script for incident layout                                                                                                                                                                                                                                                                                                                  |
| enhancement                     | Indicator enhancement script                                                                                                                                                                                                                                                                                                                                                |
| field-change-triggered          | Script to run on incident field change                                                                                                                                                                                                                                                                                                                                      |
| field-display                   | Field display script                                                                                                                                                                                                                                                                                                                                                        |
| filter                          | Script used as a filter or conditional operator in a playbook task                                                                                                                                                                                                                                                                                                          |
| general-dynamic-section         | General purpose dynamic section script for object layouts (excluding incidents and indicator layouts)                                                                                                                                                                                                                                                                       |
| incident-action-button          | Incident layout action button script                                                                                                                                                                                                                                                                                                                                        |
| indicator-action-button         | Indicator layout action button script                                                                                                                                                                                                                                                                                                                                       |
| indicator-format                | Indicator formatting script                                                                                                                                                                                                                                                                                                                                                 |
| post-processing                 | Incident post-processing script                                                                                                                                                                                                                                                                                                                                             |
| preProcessing                   | Pre-process rule script                                                                                                                                                                                                                                                                                                                                                     |
| reputation                      | Indicator reputation script                                                                                                                                                                                                                                                                                                                                                 |
| sla                             | SLA breach script                                                                                                                                                                                                                                                                                                                                                           |
| threatIntelReport-action-button | Threat Intel Report layout action button script                                                                                                                                                                                                                                                                                                                             |
| transformer                     | Script used as a transformer in a playbook task                                                                                                                                                                                                                                                                                                                             |
| widget                          | Script that can be used to generate a dashboard/report widget                                                                                                                                                                                                                                                                                                               |

</details>

<details>

<summary>Arguments</summary>

You can create, edit, or delete arguments as required.

| Parameter    | Description                                                    |
| ------------ | -------------------------------------------------------------- |
| Argument     | An identifying name.                                           |
| Mandatory    | Makes the argument mandatory.                                  |
| Default      | Makes the argument the default.                                |
| Sensitive    | Hides the argument from being displayed in the UI and in logs. |
| Description  | A meaningful description of the argument.                      |
| Default      | The default value for the argument.                            |
| Is array     | Specifies that the argument is an array.                       |
| Type         | Select Unknown (default), Key-Value, or Text Area.             |
| List options | A comma-separated list of argument values.                     |

You can create, edit, or delete outputs as required. Define the outputs according to types such as string, number, date, and boolean. For more information, see [Context and Outputs](https://xsoar.pan.dev/docs/integrations/context-and-outputs).

| Parameter    | Description                                                                                                             |
| ------------ | ----------------------------------------------------------------------------------------------------------------------- |
| Context Path | A dot-notation representation of the path to access the Context. For example, **`ThreatStream.Analysis.ReportID`**.     |
| Description  | A short description of what the context path represents. For example, the ID of the report submitted to the sandbox.    |
| Type         | The value type of the context path, such as string, number, and date Enables Cortex XSOAR to format the data correctly. |

</details>

<details>

<summary>Script permissions</summary>

Define the script permissions to set who can view and execute the script.

| Parameter        | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| Password Protect | Enables you to add a password for the script, which will be required when running the script from the CLI.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| Run as           | <p>Script permissions are determined by the <strong>Run as</strong> and <strong>Role</strong> fields.</p><ul><li><p><strong>Run as</strong>: Defines the permissions with which the script runs.</p><p>By default, most scripts run as a <strong>Limited user</strong> with restricted access and can only perform specific operations allowed by that role.</p><p>If you select the <strong>DBotRole</strong>, user roles can execute with full permission. Users with lower permissions can also view the results. To address this, assign <strong>Run as</strong> according to the user roles you want to give access to the information the script can extract.</p><div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note</strong></p><p>When a script runs automatically (such as from a playbook running on fetched incidents, a display script, a trigger script, or a pre-processing rule) the <strong>Run as</strong> permission defines who can view the playbook results.</p></div></li><li><strong>Role</strong>: Determines which user roles can execute the script.</li></ul><div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p><strong>Note</strong></p><p>Content packs typically use scripts, and the scripts can have dependencies on each other, so it is important to assign the <strong>Run as</strong> and <strong>Role</strong> parameters consistently to ensure scripts run properly.</p><p>If you change permissions for a script, the new permissions do not affect playbooks that are already using the script. The playbooks continue using the previous permissions until the next run, even when the playbook is triggered manually.</p></div> |

Example 23. Script Permissions

In this example, you created a script that searches for all incidents in the system. The following scenarios show how the system behaves using the **Run as** and **Role** configurations.

You restrict the following roles to your incidents:

* Incident 1: Instance administrators
* Incident 2: No role assigned
* Incident 3: Analysts

{% hint style="info" %}

### Note

To limit incident access to specific roles, see [Limit access to investigations using access control](/cortex-xsoar-8-on-prem/8.14/investigate-and-respond-to-threats/incidents-and-indicators-investigation/investigate-an-incident/limit-access-to-investigations-using-access-control.md).
{% endhint %}

| Scenario                                        | How the system behaves                                                                                                                                                                                                                                                                                                                                                                                            | Results                               |
| ----------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------- |
| <p>Run as: Analyst</p><p>Role: Analyst</p>      | <p>Only users with at least the analyst role can execute the script.</p><p>The script is executed with the permissions and access levels associated with the analyst role. The script has the same permission level as an analyst user, allowing you to perform actions based on the assigned role.</p>                                                                                                           | The script returns incidents 2 and 3. |
| <p>Run as: Analyst</p><p>Role: Not set</p>      | All users can execute the script, but only incidents that are viewable by the analyst role are returned.                                                                                                                                                                                                                                                                                                          | The script returns incidents 2 and 3. |
| <p>Run as: Limited User</p><p>Role: Analyst</p> | <p>The analyst role can execute the script.</p><p>The script is executed with restricted permissions and access levels. The limited user role defines the specific operations the script can perform, restricting it from executing unauthorized actions or accessing sensitive information within Cortex XSOAR. This provides a more restricted execution environment with a narrower scope of capabilities.</p> | The script returns 2 and 3.           |
| <p>Run as: DBotRole</p><p>Role: Not set</p>     | All users can execute the script, whether they are Analysts or Instance Administrators, and they have access to all incidents that are returned.                                                                                                                                                                                                                                                                  | All incidents                         |
| <p>Run as: DBotRole</p><p>Role: Analyst</p>     | <p>Any user with at least analyst permissions can execute the script. All other users can't run the script in playbook tasks, run the script manually from the command line or in a playbook.</p><p>All users can see the results of the execution in the War Room.</p>                                                                                                                                           | All incidents                         |

</details>

<details>

<summary>Advanced</summary>

| Parameter                   | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| --------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Timeout (seconds)           | Time (in seconds) before the script times out. Default is 180.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| Docker image name           | <p>For Python scripts, this is the name of the Docker image to use to run the script.</p><p>Cortex XSOAR supports the following Python versions:</p><ul><li>2.7</li><li>3.0 and later</li></ul><p>You can change the Docker image.</p><p>The default Docker image that Cortex XSOAR uses is <code>demisto/python3</code>, but you can use other Docker images from a private image registry. See <a href="/spaces/CkR7os5WSdK8uJZdAMGp/pages/qZV7JUWfyekmMqIY6QEA">Change the Docker image in an integration or script</a> for more information.</p> |
| Run on a separate container | Runs the script on a separate container.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |

</details>

<details>

<summary>Depends on commands</summary>

You can set the commands that the script depends on directly from these settings. You still have the option to set the dependencies in the script YAML file.

</details>

<details>

<summary>Edit existing code or create new code</summary>

Modify parameters, logic, or integrations within a script to adapt it to specific use cases, optimize performance, and address evolving security needs without starting from scratch.

The [Script Helper](https://xsoar.pan.dev/docs/concepts/xsoar-ide#the-script-helper) provides a list of available alphabetically ordered commands and scripts.

See this video for an example using Python code to develop a script. [Writing automations](https://www.youtube.com/watch?v=FaAnSVY6-9g)

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xsoar-8-on-prem/8.14/configure-cortex-xsoar/playbooks/scripts/create-a-script.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
