Aller au contenu principal

Function

Category: Integration
Node id: function
Maturity: production
Risk tier: none

Executes custom code in JavaScript, Python, or Bash. NOTE: sandbox isolation is not yet enabled — code runs with service privileges, so only trusted, reviewed code belongs in this node.

What it does​

  • Four runtime environments: JavaScript, Python, Bash, Go
  • Configurable execution timeout
  • JSON input/output serialization for data exchange
  • Stdout/stderr capture for debugging
  • Execution duration tracking in milliseconds

Use cases​

  • Run custom data transformation logic not covered by built-in nodes
  • Execute Python scripts for clinical data normalization
  • Run shell commands for system integration tasks

Runtime​

  • Performance tier: variable

Input ports​

NameTypeRequiredDescription
codetextNoSource code to execute (overrides config)
inputsanyNoInput data passed to the function as a variable. When nothing is wired here, the other wired ports are passed by name (inputs.<port>)

Output ports​

NameTypeRequiredDescription
outputanyNoFunction return value
resultjsonNoExecution metadata: execution object, stdout, stderr, runtime, error
successbooleanNoAlways true on output: an exception, non-zero exit or timeout fails the node instead

Settings​

Basic​

SettingNameTypeRequiredDefaultAllowed valuesDescription
RuntimeruntimeenumYesjavascriptjavascript, python, bash, goProgramming language runtime
CodecodetextNoSource code to execute (used if no code input)

Advanced​

SettingNameTypeRequiredDefaultAllowed valuesDescription
Timeout (seconds)timeoutnumberNo30min 1; max 300Maximum execution time in seconds
Allow Stdoutallow_stdoutbooleanNotrueInclude stdout in output
Max Input Bytesmax_input_bytesnumberNo33554432min 1; max 1073741824Largest serialized inputs (JSON bytes) the node hands to the code; larger inputs fail the node with a clear error

Errors​

CodeDescription
EXECUTION_FAILEDCode execution failed with a runtime error
TIMEOUT_EXCEEDEDExecution exceeded the configured timeout
UNSUPPORTED_RUNTIMEThe specified runtime is not available
MISSING_CODENo code provided via config or input

Runtime notes​

  • output is the code's return value (JavaScript/Python: return a JSON-serialisable value; the runtime writes it as the last __OUTPUT__:JSON line, so never print __OUTPUT__ yourself). bash prints __OUTPUT__:<json> as its last line; without a marker output is the raw stdout string
  • Python: code is the body of a function (user_function) and the runtime indents it, so it runs whether its lines start at column 0 or are all indented by the same amount; json, sys, inputs and context are predefined; use return, not print, for the result. An IndentationError means inconsistent indentation inside the code, not a missing indent
  • print/console.log output is kept in result.stdout for debugging; it becomes output only when the code returns nothing (null/None/undefined)
  • Go runtime is declared but not yet implemented — use javascript, python, or bash
  • Function code receives inputs as a pre-parsed variable (JS: inputs; Python: inputs dict); bash reads them as JSON on standard input
  • Function code receives the run context as a separate variable context = {run_id, pipeline_id, pipeline_version, node_id, started_at} (bash: HYDRA_RUN_ID, HYDRA_PIPELINE_ID, HYDRA_PIPELINE_VERSION, HYDRA_NODE_ID, HYDRA_RUN_STARTED_AT, HYDRA_RUN_CONTEXT); it never carries the caller identity, org id or secrets
  • Code and inputs reach the interpreter on standard input (bash: a 0600 script file removed after the run), never on the command line; max_input_bytes bounds the serialized inputs
  • An exception (JavaScript/Python), a non-zero exit (bash) or a timeout fails the node; the error carries the message and the top of the stack (truncated). Use node-level error_handling (continue/fallback) to proceed past a failure
  • No sandbox: code executes with the service's OS privileges — treat configs as trusted code (BR-2)

See Build any workflow for how to put nodes together and Ports, types and data flow for how port types connect.

Quelque chose n'est pas clair ? Envoyez vos commentaires sur la documentation par courriel.