Skip to main content

Run Script Action

Run a saved script on a device as part of an automation, with support for passing automation variables into the script.

Introduction

Run a saved script on a device as part of an automation. Supports PowerShell, Bash, Python, and other languages. If your script needs data from outside itself — like a custom field value or an automation variable — you can map that in without modifying the script logic.


⚙️ Prerequisites

  • A saved script must exist in your script library, or you can create one inline. See Scripts for how to create and organize scripts.

  • An automation must exist before adding actions. See Getting Started with Automations if you haven't set one up yet.


Run Script Action

From the automation pipeline in edit mode, click + and select Run script from the System category.

Run Script Action

The action panel opens showing the Script field and two buttons: an external link icon to browse your saved scripts, and Create script to write a new one inline.

Run Script Action

Selecting a Script

Click the external link icon next to the Script field to open the saved script picker. Scripts are organized into folders — expand any folder to browse its contents, or use the search field to find a script by name.

Selecting a Script

Creating a Script Inline

Click Create script to write a new script without leaving the automation editor. The script editor opens as a side panel.

Creating a Script

Configure the following:

Script name A descriptive name for the script. It will be saved to your script library and available for use in other automations.

Language The scripting language for this script.

Supported languages: Ansible, Bash, Go, osquery, PowerShell, Python, Zsh.

Timeout (in seconds) How long Level waits for the script to complete before marking it as failed. Default is 100 seconds.

Run as The account context the script runs under.

Option

Behavior

Local system

Runs as the SYSTEM account — elevated, no user context

Current user

Runs as the currently logged-in user — useful for user-context operations like applying wallpaper, configuring user settings, etc.

Write your script in the code editor. Click {x} to reference variables and custom fields inline in the script. When finished, click Create script to save and attach it to the action.


Script Variables

Script variables are named values defined in a script's Variables tab. In the Run Script action, mapping a script variable to an automation variable lets the saved script receive input and send an updated value back to later automation steps.

  • Before execution, Level renders the automation variable's current value into the mapped script variable.

  • During execution, the script can assign a new value to that script variable. Level writes the new value back to the mapped automation variable.

ℹ️ NOTE: You can also insert device system variables or custom fields directly through the {x} picker in the script editor. Use a mapped script variable when the value comes from an automation variable or when the saved script should use its own reusable variable name.

When a script with defined variables is selected, a Script variables section appears in the action panel.

To map a script variable to an automation variable:

  1. In the Script variables section, find the script variable you want to map.

  2. Open the Automation variables dropdown on the same row.

  3. Select an existing automation variable, or click Create new variable.

When the script starts, the mapped script variable receives the automation variable's current value. Reference it in the saved script with {{script_variable_name}}. To send a new value back to the automation, assign the script variable with {{script_variable_name=value_expression}}.

See Automation Variables for the full reference on creating and using automation variables.

Script Variable

ℹ️ NOTE: The Script variables section only appears when the selected script has at least one variable defined in its Variables tab. Scripts without variables don't show this section.

Managing Script Variables

Script variables are defined in the script itself, not in the action panel. Open the script editor and navigate to the Variables tab to add, edit, or remove them.

Script Variables

Capturing Script Output

There are two ways to capture a value from a script and make it available to subsequent actions in the pipeline.

Assign a mapped script variable

Use {{script_variable_name=value_expression}} in the saved script to update a mapped automation variable. For example, if a PowerShell script variable named local_ip is mapped to an automation variable, use {{local_ip=$ip}} after calculating $ip.

Before execution, Level replaces the assignment with the correct variable-setting command for the script's shell. It is not parsed from the script's standard output. The script variable must exist in the script's Variables tab and be mapped in the Run Script action.

Use this option when the script produces logs or other output and you only need to carry one specific value forward.

Assign full output to a variable

In Additional options, use Assign action output to variable to capture the script's entire stdout into an automation variable. This works for any script without requiring any changes to the script itself — but captures everything the script outputs, not just the value you need.

💡 TIP: Use a mapped script-variable assignment when the script produces other output you do not want in the variable. Use Assign action output to variable when the script's only output is the value you want to capture.


Exit Codes

Level uses the script's exit code to determine whether the action succeeded or failed.

Exit code

Result

0

Action marked as successful

Non-zero (e.g. 1)

Action marked as failed

Your On action failure setting in Additional options controls what happens next — whether the pipeline stops or continues.

Make sure your scripts exit explicitly with the appropriate code. If a script exits 0 after encountering an error it didn't handle, Level will treat the action as successful.


Conditions

The Conditions section lets you restrict when this action runs based on device attributes or the outcome of a previous action.

See Action Conditions for the full reference on condition types, operators, and values.


Additional Options

Expand Additional options for action name, failure behavior, output variable assignment, retries, and the enabled toggle.

See Actions Overview for the full reference on additional options available on every action.


FAQ

  • What's the difference between Run Script and Shell? Run script executes a saved script from your library — the script is version-controlled and reusable across automations. Shell runs an ad-hoc script written directly in the action panel. Use Run script when the same logic needs to be shared or maintained; use Shell for one-off inline commands.

  • Can an automation variable provide input to a saved script? Yes. Define a script variable in the script's Variables tab, map it to an automation variable in the Run Script action, and reference the script variable in the saved script. Level renders the automation variable's current value before execution.

  • Can the script write output that other actions can read? Yes. Assign a mapped script variable with {{script_variable_name=value_expression}} to write one specific value back to the mapped automation variable. Or use Assign action output to variable in Additional options to capture the script's entire stdout.

  • What happens if the script times out? The action is marked as failed. The On action failure setting in Additional options controls whether the pipeline stops or continues.

  • Who can add or modify Run Script actions? Technicians with permission to edit automations in the relevant group. See Workspace → Permissions for access control configuration.

Did this answer your question?