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.
- 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.
- 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.
Language | Default image | beforeCommands example | Script example | Commands example |
---|---|---|---|---|
Python | python | pip install requests kestra | print("Hello, World!") | python hello.py |
R | r-base | Rscript -e "install.packages('dplyr')" | print("Hello, World!") | Rscript hello.R |
Julia | julia | julia -e 'using Pkg; Pkg.add("CSV")' | println("Hello, World!") | julia hello.jl |
Ruby | ruby | gem install httparty | puts "Hello, World!" | ruby hello.rb |
Node.js | node | npm install json2csv | console.log('Hello, World!'); | node hello.js |
Shell | ubuntu | apt-get install curl | echo "Hello, World!" | ./hello.bash |
PowerShell | mcr.microsoft.com/powershell | Install-Module -Name ImportExcel | Write-Output "Hello, World!" | .\hello.ps1 |
Go | golang | go mod init go_script | println("Hello, World!") | go run hello.go |
Deno | denoland/deno | N/A | console.log("Hello from Kestra!") | deno run main.ts |
Lua | nickblah/lua | N/A | print("Hello from Kestra!") | lua -e 'print("Hello from Kestra!")' |
Bun | over/bun | bun add cowsay | console.log("Hello, World!") | bun run index.ts |
PHP | php | N/A | echo "Hello, World!"; | php main.php |
Perl | perl | N/A | print "Hello from Kestra!\n"; | perl -e 'print "Hello from Kestra!\n"' |
Groovy | groovy | N/A | println "Hello, $name!" | groovy HelloWorld.groovy |
Full class names:
- io.kestra.plugin.scripts.python.Commands
- io.kestra.plugin.scripts.python.Script
- io.kestra.plugin.scripts.r.Commands
- io.kestra.plugin.scripts.r.Script
- io.kestra.plugin.scripts.julia.Commands
- io.kestra.plugin.scripts.julia.Script
- io.kestra.plugin.scripts.ruby.Commands
- io.kestra.plugin.scripts.ruby.Script
- io.kestra.plugin.scripts.node.Commands
- io.kestra.plugin.scripts.node.Script
- io.kestra.plugin.scripts.shell.Commands
- io.kestra.plugin.scripts.shell.Script
- io.kestra.plugin.scripts.powershell.Commands
- io.kestra.plugin.scripts.powershell.Script
- io.kestra.plugin.scripts.go.Script
- io.kestra.plugin.scripts.go.Commands
- io.kestra.plugin.scripts.deno.Script
- io.kestra.plugin.scripts.deno.Commands
- io.kestra.plugin.scripts.bun.Script
- io.kestra.plugin.scripts.bun.Commands
- io.kestra.plugin.scripts.php.Script
- io.kestra.plugin.scripts.php.Commands
- io.kestra.plugin.scripts.perl.Script
- io.kestra.plugin.scripts.perl.Commands
- io.kestra.plugin.scripts.groovy.Script
- io.kestra.plugin.scripts.groovy.Commands
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
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
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
:
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:
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:
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
:
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?