Commands and Script Tasks​Commands and ​Script ​Tasks

Types of tasks for executing programming languages.


For each of the supported languages (e.g., Python, R, Node.js, Shell), Kestra provides two task types: Script and Commands.

  1. Script tasks are written inline in the YAML flow configuration. They’re best for short scripts and make it easy to pass data from flow inputs and other tasks to your code.
  2. Commands tasks are better for longer or multi-file scripts, typically added to Kestra as namespace files.

The table below gives an overview of script-related tasks and example configuration snippets.

LanguageDefault imagebeforeCommands exampleScript exampleCommands example
Pythonpythonpip install requests kestraprint("Hello, World!")python hello.py
Rr-baseRscript -e "install.packages('dplyr')"print("Hello, World!")Rscript hello.R
Juliajuliajulia -e 'using Pkg; Pkg.add("CSV")'println("Hello, World!")julia hello.jl
Rubyrubygem install httpartyputs "Hello, World!"ruby hello.rb
Node.jsnodenpm install json2csvconsole.log('Hello, World!');node hello.js
Shellubuntuapt-get install curlecho "Hello, World!"./hello.bash
PowerShellmcr.microsoft.com/powershellInstall-Module -Name ImportExcelWrite-Output "Hello, World!".\hello.ps1
Gogolanggo mod init go_scriptprintln("Hello, World!")go run hello.go
Denodenoland/denoN/Aconsole.log("Hello from Kestra!")deno run main.ts
Luanickblah/luaN/Aprint("Hello from Kestra!")lua -e 'print("Hello from Kestra!")'
Bunover/bunbun add cowsayconsole.log("Hello, World!")bun run index.ts
PHPphpN/Aecho "Hello, World!";php main.php
PerlperlN/Aprint "Hello from Kestra!\n";perl -e 'print "Hello from Kestra!\n"'
GroovygroovyN/Aprintln "Hello, $name!"groovy HelloWorld.groovy

Full class names:

Check available blueprints to get started.

When to use Script over Commands?

Advantages of Script:

  • Simplicity: script code is stored and versioned with the flow’s revision history alongside orchestration logic.
  • Easy templating: when the workflow is defined in a single file, it’s straightforward to access inputs, variables, and pass outputs to downstream tasks.

Disadvantages of Script (vs. Commands):

  • Readability: long inline scripts are harder to read and test than code in separate files (which also benefit from the embedded code editor).
  • Complex use cases: for multi-file projects or shared modules, use Commands instead.

Recommendation: use Commands for advanced production workloads; Script is great for simple use cases and quick iteration.

Examples

Below is the same Python logic implemented with both Script and Commands tasks.

Script task

yaml
id: python_script
namespace: company.team

tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Script
    beforeCommands:
      - pip install requests kestra
    script: |
      from kestra import Kestra
      import requests

      response = requests.get('https://kestra.io')
      print(response.status_code)

      Kestra.outputs({'status': response.status_code, 'text': response.text})

Commands task

yaml
id: python_commands
namespace: company.team

tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Commands
    namespaceFiles:
      enabled: true
      include:
        - main.py
    beforeCommands:
      - pip install requests kestra
    commands:
      - python main.py

main.py:

python
from kestra import Kestra
import requests

response = requests.get('https://kestra.io')
print(response.status_code)

Kestra.outputs({'status': response.status_code, 'text': response.text})

Pass values into code

You can pass values into your code using expressions. Below, the expression is used directly inside a Script task:

yaml
id: python_script_dynamic
namespace: company.team

inputs:
  - id: uri
    type: STRING
    defaults: https://kestra.io

tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Script
    beforeCommands:
      - pip install requests kestra
    script: |
      from kestra import Kestra
      import requests

      response = requests.get('{{ inputs.uri }}')
      print(response.status_code)

      Kestra.outputs({'status': response.status_code, 'text': response.text})

To pass values into Commands tasks, use environment variables:

yaml
id: python_commands_dynamic
namespace: company.team

inputs:
  - id: uri
    type: STRING
    defaults: https://kestra.io

tasks:
  - id: python
    type: io.kestra.plugin.scripts.python.Commands
    namespaceFiles:
      enabled: true
      include:
        - main.py
    beforeCommands:
      - pip install requests kestra
    commands:
      - python main.py
    env:
      URI: "{{ inputs.uri }}"

main.py:

python
from kestra import Kestra
import requests
import os

response = requests.get(os.environ['URI'])
print(response.status_code)

Kestra.outputs({'status': response.status_code, 'text': response.text})

Was this page helpful?