Skip to content

Code Executor

Runs user-provided Python code against a single input in a restricted, safe environment. Captures stdout/stderr into an execution log and returns the computed result, a log summary, and a success flag. Designed to work with any input type while blocking dangerous operations.
Preview

Usage

Use this node when you need a quick, flexible transformation or computation on data flowing through your workflow. Provide Python code that reads from 'input_data' and either returns a value or assigns it to a variable named 'result' or 'output'. Typical use cases include lightweight data cleaning, formatting, simple math, or conditional logic before passing data to subsequent nodes.

Inputs

FieldRequiredTypeDescriptionExample
python_codeTrueSTRINGPython code to execute. Access the incoming value via 'input_data'. The result should be returned, or stored in a variable named 'result' or 'output'.# Access input data = input_data # Transform result = data * 2 if isinstance(data, (int, float)) else str(data).upper() return result
timeout_secondsTrueFLOATSuggested timeout window for execution in seconds. Keep code short-running.10.0
input_dataFalse*Any input to be processed by the Python code. Available inside your code as 'input_data'.5

Outputs

FieldTypeDescriptionExample
result*The computed value from the executed code. If no explicit return is used, the node attempts to use 'result', 'output', or the last evaluated expression.10
execution_logSTRINGA textual summary including captured stdout and any warnings printed during execution.Execution completed successfully \| Output: processed OK
successBOOLEANIndicates whether the code executed without errors.true

Important Notes

  • Safe environment: Dangerous operations are blocked (e.g., imports like os/sys/subprocess, exec/eval, file I/O, raw input).
  • How to return a value: Prefer 'return '. If omitted, define 'result' or 'output'; otherwise, the last expression may be used.
  • Available helpers: Built-ins like len, sum, range, and modules such as json, time, math, random, datetime are exposed.
  • Input flexibility: 'input_data' can be any type (string, number, dict, list, etc.).
  • Logging: stdout/stderr are captured and included in 'execution_log'.
  • Timeout behavior: Keep code short-running. Long-running code may not be forcibly interrupted.
  • No external access: Avoid network/file system access or module imports—these are intentionally restricted for safety.

Troubleshooting

  • Invalid Python code or blocked operations: If 'success' is false and the log mentions dangerous patterns, remove imports (e.g., os, sys) or disallowed functions (exec, eval) and try again.
  • No result returned: Ensure your code 'return's a value or assigns to 'result' or 'output'.
  • Unexpected result type downstream: The output type is '*'. If a downstream node expects a specific type, cast or format the result accordingly in your code.
  • Missing prints in log: Only stdout/stderr printed during execution are captured; ensure you use 'print' within your code if you expect to see messages.
  • Long-running or hanging code: Simplify logic, remove loops that can hang, and ensure computations finish within the intended time.