Script
Executes user-defined code. User can write custom workflow logic in Bash, JavaScript or Python programming languages.
Categories: Helpers, Developer Tools
Type: script/v1
Actions
JavaScript
Name: javascript
Executes custom JavaScript code.
Properties
| Name | Label | Type | Description | Required |
|---|---|---|---|---|
| input | Input | OBJECT Properties{} | Initialize parameter values used in the custom code. | false |
| script | JavaScript Code | STRING | Add your JavaScript custom logic here. | true |
| taskRunner | Task Runner | OBJECT Properties{STRING(type), STRING(image), [STRING](entrypoint), STRING(user), NUMBER(cpu), STRING(memory), STRING(networkMode), [STRING](extraHosts), BOOLEAN(privileged), {STRING(registry), STRING(username), STRING(password), STRING(registryToken)}(credentials), STRING(killGracePeriod), STRING(pullPolicy), BOOLEAN(resume), BOOLEAN(delete), STRING(waitUntilRunning), STRING(waitUntilCompletion), STRING(mode), STRING(interpreter), BOOLEAN(inheritEnvironment)} | Chooses where and how this task's code runs. Each runner type shows its own settings, and only the runners an operator has enabled are offered. | false |
| env | Environment | OBJECT Properties{} | Environment variables the script or commands see, as name and value pairs. The host's own environment is not passed on unless the Process runner's Inherit Environment option is on, so add every variable the code needs here. ByteChef also sets BYTECHEF_WORKING_DIR (the folder the code runs in), BYTECHEF_OUTPUT_DIR, BYTECHEF_INPUT_FILE and, when the task has connections, BYTECHEF_CONNECTIONS_FILE. | false |
| inputFiles | Input Files | OBJECT Properties{} | Files placed in the working folder (BYTECHEF_WORKING_DIR) before the code runs, keyed by file name. A name may include folders, such as data/orders.csv. A value is either inline text, written as is, or a file from an earlier step, such as another task's output file, whose content is copied in. The code reads them by name, relative to the working folder. | false |
| outputFiles | Output Files | ARRAY Items[STRING] | Glob patterns for the files to keep from the output folder (BYTECHEF_OUTPUT_DIR) after the code finishes, such as *.csv or charts/summary.png. Each matching file is stored and returned in the task's outputFiles, keyed by its path relative to the output folder, so a later step can use it, for example task_1.outputFiles['report.csv']. Without patterns no file is kept and outputFiles is empty. Files that match no pattern are discarded, and output.json is never kept as a file because it becomes the task's vars. | false |
| timeout | Timeout (seconds) | INTEGER | How many seconds the code may run before it is stopped and the task fails. When empty, Process and GraalVM's Trusted mode stop it after 5 minutes, and container runners use Wait Until Completion. For container runners the operator's max-wait caps it. | false |
Example JSON Structure
{
"label" : "JavaScript",
"name" : "javascript",
"parameters" : {
"input" : { },
"script" : "",
"taskRunner" : {
"type" : "",
"image" : "",
"entrypoint" : [ "" ],
"user" : "",
"cpu" : 0.0,
"memory" : "",
"networkMode" : "",
"extraHosts" : [ "" ],
"privileged" : false,
"credentials" : {
"registry" : "",
"username" : "",
"password" : "",
"registryToken" : ""
},
"killGracePeriod" : "",
"pullPolicy" : "",
"resume" : false,
"delete" : false,
"waitUntilRunning" : "",
"waitUntilCompletion" : "",
"mode" : "",
"interpreter" : "",
"inheritEnvironment" : false
},
"env" : { },
"inputFiles" : { },
"outputFiles" : [ "" ],
"timeout" : 1
},
"type" : "script/v1/javascript"
}Output
The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.
Python
Name: python
Executes custom Python code.
Properties
| Name | Label | Type | Description | Required |
|---|---|---|---|---|
| input | Input | OBJECT Properties{} | Initialize parameter values used in the custom code. | false |
| script | Python Code | STRING | Add your Python custom logic here. | true |
| taskRunner | Task Runner | OBJECT Properties{STRING(type), STRING(image), [STRING](entrypoint), STRING(user), NUMBER(cpu), STRING(memory), STRING(networkMode), [STRING](extraHosts), BOOLEAN(privileged), {STRING(registry), STRING(username), STRING(password), STRING(registryToken)}(credentials), STRING(killGracePeriod), STRING(pullPolicy), BOOLEAN(resume), BOOLEAN(delete), STRING(waitUntilRunning), STRING(waitUntilCompletion), STRING(mode), STRING(interpreter), BOOLEAN(inheritEnvironment)} | Chooses where and how this task's code runs. Each runner type shows its own settings, and only the runners an operator has enabled are offered. | false |
| env | Environment | OBJECT Properties{} | Environment variables the script or commands see, as name and value pairs. The host's own environment is not passed on unless the Process runner's Inherit Environment option is on, so add every variable the code needs here. ByteChef also sets BYTECHEF_WORKING_DIR (the folder the code runs in), BYTECHEF_OUTPUT_DIR, BYTECHEF_INPUT_FILE and, when the task has connections, BYTECHEF_CONNECTIONS_FILE. | false |
| inputFiles | Input Files | OBJECT Properties{} | Files placed in the working folder (BYTECHEF_WORKING_DIR) before the code runs, keyed by file name. A name may include folders, such as data/orders.csv. A value is either inline text, written as is, or a file from an earlier step, such as another task's output file, whose content is copied in. The code reads them by name, relative to the working folder. | false |
| outputFiles | Output Files | ARRAY Items[STRING] | Glob patterns for the files to keep from the output folder (BYTECHEF_OUTPUT_DIR) after the code finishes, such as *.csv or charts/summary.png. Each matching file is stored and returned in the task's outputFiles, keyed by its path relative to the output folder, so a later step can use it, for example task_1.outputFiles['report.csv']. Without patterns no file is kept and outputFiles is empty. Files that match no pattern are discarded, and output.json is never kept as a file because it becomes the task's vars. | false |
| timeout | Timeout (seconds) | INTEGER | How many seconds the code may run before it is stopped and the task fails. When empty, Process and GraalVM's Trusted mode stop it after 5 minutes, and container runners use Wait Until Completion. For container runners the operator's max-wait caps it. | false |
Example JSON Structure
{
"label" : "Python",
"name" : "python",
"parameters" : {
"input" : { },
"script" : "",
"taskRunner" : {
"type" : "",
"image" : "",
"entrypoint" : [ "" ],
"user" : "",
"cpu" : 0.0,
"memory" : "",
"networkMode" : "",
"extraHosts" : [ "" ],
"privileged" : false,
"credentials" : {
"registry" : "",
"username" : "",
"password" : "",
"registryToken" : ""
},
"killGracePeriod" : "",
"pullPolicy" : "",
"resume" : false,
"delete" : false,
"waitUntilRunning" : "",
"waitUntilCompletion" : "",
"mode" : "",
"interpreter" : "",
"inheritEnvironment" : false
},
"env" : { },
"inputFiles" : { },
"outputFiles" : [ "" ],
"timeout" : 1
},
"type" : "script/v1/python"
}Output
The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.
Bash
Name: bash
Executes a Bash script in the selected task runner.
Properties
| Name | Label | Type | Description | Required |
|---|---|---|---|---|
| input | Input | OBJECT Properties{} | Initialize parameter values used in the script. Each one is exported as INPUT_<name>, a non-string value as JSON; all of them are also in the JSON file named by BYTECHEF_INPUT_FILE. | false |
| script | Bash Script | STRING | Add your Bash script here. Write a JSON result to $BYTECHEF_OUTPUT_DIR/output.json to return it as vars. | true |
| taskRunner | Task Runner | OBJECT Properties{STRING(type), STRING(image), [STRING](entrypoint), STRING(user), NUMBER(cpu), STRING(memory), STRING(networkMode), [STRING](extraHosts), BOOLEAN(privileged), {STRING(registry), STRING(username), STRING(password), STRING(registryToken)}(credentials), STRING(killGracePeriod), STRING(pullPolicy), BOOLEAN(resume), BOOLEAN(delete), STRING(waitUntilRunning), STRING(waitUntilCompletion), STRING(interpreter), BOOLEAN(inheritEnvironment)} | Chooses where and how this task's code runs. Each runner type shows its own settings, and only the runners an operator has enabled are offered. | false |
| env | Environment | OBJECT Properties{} | Environment variables the script or commands see, as name and value pairs. The host's own environment is not passed on unless the Process runner's Inherit Environment option is on, so add every variable the code needs here. ByteChef also sets BYTECHEF_WORKING_DIR (the folder the code runs in), BYTECHEF_OUTPUT_DIR, BYTECHEF_INPUT_FILE and, when the task has connections, BYTECHEF_CONNECTIONS_FILE. | false |
| inputFiles | Input Files | OBJECT Properties{} | Files placed in the working folder (BYTECHEF_WORKING_DIR) before the code runs, keyed by file name. A name may include folders, such as data/orders.csv. A value is either inline text, written as is, or a file from an earlier step, such as another task's output file, whose content is copied in. The code reads them by name, relative to the working folder. | false |
| outputFiles | Output Files | ARRAY Items[STRING] | Glob patterns for the files to keep from the output folder (BYTECHEF_OUTPUT_DIR) after the code finishes, such as *.csv or charts/summary.png. Each matching file is stored and returned in the task's outputFiles, keyed by its path relative to the output folder, so a later step can use it, for example task_1.outputFiles['report.csv']. Without patterns no file is kept and outputFiles is empty. Files that match no pattern are discarded, and output.json is never kept as a file because it becomes the task's vars. | false |
| timeout | Timeout (seconds) | INTEGER | How many seconds the code may run before it is stopped and the task fails. When empty, Process and GraalVM's Trusted mode stop it after 5 minutes, and container runners use Wait Until Completion. For container runners the operator's max-wait caps it. | false |
Example JSON Structure
{
"label" : "Bash",
"name" : "bash",
"parameters" : {
"input" : { },
"script" : "",
"taskRunner" : {
"type" : "",
"image" : "",
"entrypoint" : [ "" ],
"user" : "",
"cpu" : 0.0,
"memory" : "",
"networkMode" : "",
"extraHosts" : [ "" ],
"privileged" : false,
"credentials" : {
"registry" : "",
"username" : "",
"password" : "",
"registryToken" : ""
},
"killGracePeriod" : "",
"pullPolicy" : "",
"resume" : false,
"delete" : false,
"waitUntilRunning" : "",
"waitUntilCompletion" : "",
"interpreter" : "",
"inheritEnvironment" : false
},
"env" : { },
"inputFiles" : { },
"outputFiles" : [ "" ],
"timeout" : 1
},
"type" : "script/v1/bash"
}Output
The output for this action is dynamic and may vary depending on the input parameters. To determine the exact structure of the output, you need to execute the action.
Additional Instructions
Calling a Component Inside a Script
To call a component inside a script, you need to use the context.component object which gives you references to components and their actions.
For example, to call logger component and its info action in javascript you can use the following code:
function perform(input, context) {
context.component.logger.info({'text': 'Hello World!!!'})
return null;
}Adding Component Connection
If you want to call an action of a component which requires a connection you can define its connection inside the Script editor:
- Click on + button.
- Click on add Script component to the workflow.
- Choose Python action.
- Click on Properties tab.
- Click on Open Code Editor.
- Click on Add Component.
- Enter name of your connection.
- Click on Select... and choose your component connection.
- Click on Add.
- Select connection you want to use in the Script for that component.
Example of usage:
function perform(input, context) {
context.component.googleMaps.getAddress({'latitude': 12.5, 'longitude': 45.8});
return null;
}Defining Multiple Connections
You can also define multiple connections of the same component and then reference a particular connection when calling the action:
- Click on Add Component.
- Add another Google Maps connection with different name.
- To define which connection will be used for what action call, add connection name as the parameter of the action.
- In this case it looks like this:
context.component.googleMaps.getAddress({'latitude': 12.5, 'longitude': 45.8}, 'googleMaps2');.
Example of usage:
function perform(input, context) {
context.component.googleMaps.getAddress({'latitude': 12.5, 'longitude': 45.8}, 'googleMaps2');
context.component.googleMaps.getAddress({'latitude': 12.5, 'longitude': 45.8}, 'googleMaps');
return null;
}Reading Connection Parameters
Declare perform with a connection argument between input and context to read the parameters of the connections defined in the Connections panel at the bottom right of the Script editor, keyed by the connection name, the same way input holds the input parameters:
function perform(input, connection, context) {
const token = connection['googleMaps'].api_token;
return null;
}In Python, read a parameter by subscript:
def perform(input, connection, context):
token = connection["googleMaps"]["api_token"]
return NoneDeclare connection as a plain, required parameter. ByteChef counts the required parameters of perform to decide whether to pass it, so a JavaScript default value on connection makes the script receive perform(input, context) instead. Scripts that declare perform(input, context), with or without further optional parameters, keep working unchanged.
The same perform(input, connection, context) receives the connections under the Process, Docker, Kubernetes and AWS Batch runners, read from the task's connections.json file. See Connections In External Runners.
Datastream item processors and AI skill scripts receive an empty connection. A Script tool's return value is sent to the AI model, so don't return connection parameters from a tool.
Writing to the Execution Log
Call context.log(level, message) to write a message to the task's execution log. The level is one of trace, debug, info, warn or error, in any letter case; any other level fails the script with an error that lists the valid levels. context.log is available on the GraalVM runner only.
function perform(input, context) {
context.log('info', 'my-task ran');
return null;
}Task Runners
Each action runs in the environment its Task Runner property selects. The runners an installation offers depend on what the operator enabled with bytechef.script.runners.<type>.enabled, so the Type list in your editor may be shorter than this table. The Task Runners guide documents every runner, property and operator setting in full.
| Runner | Type | Edition | What it does |
|---|---|---|---|
| GraalVM | graalvm | Community | Runs the script inside the server process, in the script sandbox. The only runner where context.component.* is available. Enabled in the shipped configuration. |
| Process | process | Community | Runs the script in a child process on the server's host. The server's environment is cleared first: only PATH is kept, HOME is set to the working directory, and the task's Environment and the BYTECHEF_* variables are added. |
| Docker | docker | Community | Runs the script in a single-use container. The task chooses the image, CPU, memory, user and network; the operator chooses the daemon. |
| Kubernetes | kubernetes | Enterprise | Runs the script as a single-use pod on the cluster the task's Kubernetes connection names. |
| AWS Batch | aws-batch | Enterprise | Runs the script as an AWS Batch job in the account the task's AWS connection names. |
When Task Runner is left unset, the JavaScript and Python actions run on GraalVM, so existing Script steps keep working unchanged. The Bash action has no GraalVM fallback; see The Bash Action.
The Script Task Runners Demo sample workflow (demo/script-runners.json in automation-demo-config, seeded into the Demo project on a demo profile install) is a single javascript action that takes a workflow input through Input, declares perform(input, connection, context), and returns a computed value. It leaves Task Runner unset, so it runs on GraalVM under the shipped configuration. Once an operator enables process or docker, setting the task's taskRunner.type to it is the only edit needed, and the result changes to the five-key map described under Result Shape.
The GraalVM Runner's Modes
- Strict (default): no file system, no environment, no process creation, and the CPU and heap limits of
bytechef.script.sandbox. Use this unless you have a specific reason not to. - Trusted: every restriction lifted. The script runs inside the server process with full reflection, so it can reach anything the server can, including other tenants' data. It has no CPU or heap limit, and a wall-clock timeout of 5 minutes unless the task sets
timeout. The option is offered whilebytechef.script.trusted.enabledistrue, which is the shipped self-hosted default; set it tofalseon a multi-tenant deployment.
The GraalVM runner does not accept Environment, Input Files or Output Files, and its strict mode does not accept a Timeout: strict already runs under CPU and heap limits, and a wall clock would kill a script that is only waiting on a slow component call.
Input Files, Output Files, Environment And Timeout
These properties appear for every runner except GraalVM.
- Input Files: file name to content, inline text or a file entry, written into the working directory before the script starts.
BYTECHEF_WORKING_DIRholds the directory's path. - Output Files: glob patterns matched against
BYTECHEF_OUTPUT_DIRafter the run. Every match is stored and returned inoutputFiles, keyed by its relative path. - Environment: variables the script sees. Their values are evaluated as workflow expressions.
- Timeout (seconds): how long the script may run. Without one, the Process runner allows 5 minutes and the Docker, Kubernetes and AWS Batch runners their
waitUntilCompletion(defaultPT1H), capped by the operator'smax-wait.
BYTECHEF_INPUT_FILE names input.json, which holds the Input values as JSON.
Workflow data reaches a script through the Input property, not by interpolating expressions into the source.
Connections In External Runners
Under Process, Docker, Kubernetes and AWS Batch the connections a task declares (except taskRunner) are written to connections.json in the working directory, beside the input file, as one JSON object that maps each connection's name to its parameters: the same map a GraalVM script receives. BYTECHEF_CONNECTIONS_FILE holds its path (inside the container on Docker, Kubernetes and AWS Batch), and the task's own Environment cannot override it. No connection parameter is exported as an environment variable, and the file lies outside the output directory, so it never comes back in outputFiles.
The appended bootstrap loads the file and passes the map to perform when perform declares three or more required parameters (in Python, required positional parameters, counted with inspect.signature), and otherwise calls perform(input, context) as before:
def perform(input, connection, context):
token = connection["slack"]["token"]
return {"authorized": bool(token)}function perform(input, connection, context) {
const token = connection["slack"].token;
return {authorized: Boolean(token)};
}On these runners context is a placeholder: reading any member of it, such as context.component, fails with an error saying it is not available under that runner. A JavaScript perform may be async; the bootstrap awaits it.
A Bash script, or a command of the Commands component, reads the file itself, for example jq -r '.slack.token' "$BYTECHEF_CONNECTIONS_FILE".
Values of 6 or more characters, each connection's JSON form and the whole file's JSON are replaced by ****** in stdout, stderr, failure messages and the server log, except the top-level parameters named authorizationType, region, baseUri, baseUrl, url, uri, instanceUrl, endpoint, host, hostname, port and domain, which are delivered but never masked. Very long lines (over 8192 characters) are split before logging, so a secret crossing that split may appear in fragments in the server log. Masking is best effort, and vars and outputFiles are not masked. With bytechef.script.inject-connections off, no file is written and connection is an empty map. The Commands component's documentation has the exposure table for each runner.
Result Shape
The shape of an action's result depends on which runner ran it, and this is the change most likely to break a workflow that switches runners.
Under GraalVM, the action returns exactly what the script's perform() function returned.
Under Process, Docker, Kubernetes or AWS Batch, the action always returns this map:
{
"exitCode": 0,
"stdout": "...",
"stderr": "",
"vars": {},
"outputFiles": {}
}vars is perform()'s return value: the appended bootstrap serializes it to output.json in the output directory, and the runner reads that file back into vars. So a script that returns {"total": 42} is read as ${myScript.total} under GraalVM, and as ${myScript.vars.total} under the other runners. Moving a script between GraalVM and an external runner means updating every downstream reference to its output, not just the Task Runner property.
A non-zero exit code, including an exception thrown out of perform, fails the task with the tails of stdout and stderr in the message, so a returned result always carries exitCode 0.
Language Support By Runner
The Process, Docker, Kubernetes and AWS Batch runners can only start an interpreter for JavaScript, Python, Bash and shell. Any other language is rejected by the runner's own validation before anything starts, with a message that names the language, for example "Language 'ruby' cannot be executed by an external task runner."
That check is deliberately not enforced earlier, in the editor: the Task Runner select is built from what each enabled runner declares it can do, not from what languages it can run.
In the current build this only matters for JavaScript, Python and Bash, the three languages this component's actions ship, and all three run on the external runners. The Ruby, Java and R actions exist in the codebase but are not registered on this component, for reasons unrelated to task runners.
The Bash Action
The Bash action runs its script with bash, so it needs the Process, Docker, Kubernetes or AWS Batch runner; GraalVM cannot run it. When Task Runner is left unset, it uses the first enabled runner that can run it, in alphabetical order of type; if none is enabled, the task fails with a message naming bytechef.script.runners.process.enabled=true.
- Each Input value is exported as
INPUT_<name>: a string as it is, any other value as JSON,nullas an empty string. A name that is not a valid shell variable name is not exported, but every value is also in the JSON file named byBYTECHEF_INPUT_FILE. An Environment entry of the same name wins. - Writing a JSON object to
$BYTECHEF_OUTPUT_DIR/output.jsonreturns it invars. - The default script starts with
set -euo pipefail, so the first failing command fails the task.
set -euo pipefail
echo "Hello, $INPUT_name"
printf '{"greeted": "%s"}' "$INPUT_name" > "$BYTECHEF_OUTPUT_DIR/output.json"Under Docker, Kubernetes and AWS Batch the default image is ubuntu:24.04. It has bash but not jq, python3 or curl, so a script that needs them, including one that reads BYTECHEF_INPUT_FILE or BYTECHEF_CONNECTIONS_FILE with jq, must set the runner's Image to one that ships them. The Process runner uses whatever the host has on its PATH.
The Bash action replaces the deprecated Bash component, which runs its script directly on the server with the server's own environment and no timeout. The Task Runners guide has a step-by-step migration.
Inheriting The Host Environment
The Process runner clears the environment before the script starts and keeps only PATH: the server process holds datasource passwords and cloud credentials, and a script must not be able to read them by name.
A workflow author can ask for the server's full environment instead, through the runner's Inherit Environment option. It is off by default; turning it on hands the child process everything the server process holds, including datasource passwords and cloud credentials, so use it only on a deployment where workflow authors are trusted with the server itself. It does not affect connections, which arrive in connections.json either way.
Limitations
Workflow expressions are not evaluated in script source. A ${…} written in the JavaScript Code, Python Code or Bash Script field reaches the interpreter exactly as you typed it. A JavaScript template literal such as `Hi ${name}` is your code, not a workflow expression, and this holds under every runner.
Previously the source was passed through the workflow expression evaluator, and that is a breaking change if you relied on it: a bare ${name} was substituted whenever the workflow context happened to carry a matching name, and anything more involved, such as `Total: ${a + b}`, a ternary or a function call, failed the whole task with Invalid expression, naming neither the script nor the property. Such a script now runs, and a script that did rely on the substitution receives a literal ${name} instead of a value.
Workflow data reaches a script through the Input property, whose values are evaluated normally: declare the value as an input and read it from input inside perform().
Two limitations of the external runners are deliberate trade-offs, not oversights:
- A backgrounded descendant is not reaped under the Process runner. A script whose shell command ends in something like
sleep 600 &outlives the task: the task itself is bounded, since the wait for its output has a ceiling, but the orphaned descendant keeps running after the task ends. On a timeout the runner kills the process and its descendants. The Docker runner does not have this problem: removing the container takes everything running inside it with it. stdoutandstderrin the result are truncated. Each stream keeps the first and the last half of a byte budget, with the number of elided bytes written between them: 64 KiB per stream on the Process runner, and the operator'smax-log-bytes(1 MB by default) on Docker, Kubernetes and AWS Batch. The full, untruncated stream still reaches the server log, line by line, as it is produced.
How is this guide?
Last updated on