Skip to content

Code Executor

Executes custom Python code against a single input value in a restricted, sandbox-like environment. It captures stdout/stderr into a concise execution log and returns the computed result as any data type. Safety checks block dangerous patterns and only a safe subset of built-ins is available.
Preview

Usage

Use this node when you need a quick, flexible transformation or computation that isn't covered by existing nodes. Provide input_data (any type) and Python code that reads from input_data and either sets a variable named result or returns a value. The node outputs the computed result, a combined execution log (including any prints), and a success flag.

Inputs

FieldRequiredTypeDescriptionExample
python_codeTrueSTRINGPython code snippet to run. Use the variable 'input_data' to access the incoming value. Either set a variable named 'result' (or 'output') or use a return statement.# Access input data data = input_data # Example: double numbers or repeat strings result = data * 2 if isinstance(data, (int, float)) else str(data) * 2
timeout_secondsTrueFLOATDesired maximum execution time in seconds for the code block.10.0
input_dataFalse*Value passed into your code as 'input_data'. Can be any type (number, string, dict, list, etc.).5

Outputs

FieldTypeDescriptionExample
result*The value produced by your code. If you return a value or assign 'result' (or 'output'), that value is emitted. Otherwise, the last evaluated expression may be used.10
execution_logSTRINGA combined message summarizing completion and any printed output or warnings from your code.Execution completed successfully \| Output: processed=10
successBOOLEANTrue if the code executed without errors; False otherwise.True

Important Notes

  • Code runs in a restricted environment. Dangerous operations (e.g., file I/O, exec/eval, subprocess, direct imports like os/sys, raw input) are blocked.
  • Only a safe subset of built-ins is available (e.g., len, str, int, float, bool, list, dict, tuple, set, min, max, sum, abs, round, sorted, enumerate, zip, map, filter, range, print, type, isinstance, hasattr, getattr, setattr, and modules: json, time, math, random, datetime).
  • To reliably produce an output, either set a variable named 'result' (or 'output') or use a return statement. If neither is found, the node may fall back to the last evaluated expression.
  • The execution_log aggregates printed output and warnings; avoid printing large data to keep logs readable.
  • Ensure the downstream nodes can handle the result type you produce (e.g., string vs. number vs. object).

Troubleshooting

  • Invalid Python code: Fix syntax errors and ensure your snippet compiles. The node will report a syntax error in the execution_log.
  • Blocked operation detected: Remove disallowed patterns like 'import os', 'exec(', 'eval(', file I/O calls, or subprocess usage.
  • Got None as result: Make sure your code returns a value or assigns 'result' (or 'output').
  • Unexpected result type: Confirm your code emits the type expected by downstream nodes, or cast/format the result accordingly.
  • Empty or missing input_data: If your logic assumes a value, validate input_data and provide defaults to avoid exceptions.