Code Executor¶
Executes user-provided Python code against a single input value and returns the result. It runs in a constrained environment with a curated set of safe built-ins, captures stdout/stderr to an execution log, and provides a success flag for easy branching.

Usage¶
Use this node to quickly transform or validate data with simple Python expressions. Typical workflows include lightweight preprocessing, mapping an input to another type, formatting values, or prototyping logic between nodes. Provide the input via the 'input_data' port (any type) and a short Python snippet that reads from 'input_data' and sets a result.
Inputs¶
| Field | Required | Type | Description | Example |
|---|---|---|---|---|
| python_code | True | STRING | Python code to execute. Read the incoming value from 'input_data' and produce a result by either assigning to 'result' or using a return statement. | result = input_data if input_data is not None else 'empty' |
| timeout_seconds | True | FLOAT | Maximum time allocated for the code execution in seconds. Keep your code short-running. | 10.0 |
| input_data | False | * | The value to be processed by your Python code. Can be any type (string, number, boolean, list, dict, etc.). | 42 |
Outputs¶
| Field | Type | Description | Example |
|---|---|---|---|
| result | * | The computed value from the executed code. Type depends on your code (can be any type). | 84 |
| execution_log | STRING | Collected stdout/stderr messages and a short status line indicating whether the execution completed successfully. | Execution completed successfully \| Output: processed |
| success | BOOLEAN | True if code executed without errors; False otherwise. | true |
Important Notes¶
- Your code should reference the input via 'input_data' and set an output by assigning to 'result' or by using a return statement.
- A restricted set of safe built-ins is available (common types, math/random/datetime modules, basic functions). Access to OS/file/network/process execution and dynamic evaluation is blocked.
- Potentially dangerous patterns are disallowed (e.g., import os/sys/subprocess/shutil, exec, eval, import, open, input, compile). Such code will be rejected as invalid.
- Keep code short-running and deterministic. Avoid infinite loops or heavy computations to prevent timeouts.
- The node captures print output and warnings; these appear in 'execution_log' for debugging.
Troubleshooting¶
- Invalid Python code: If 'success' is false and the log mentions 'Invalid Python code', check syntax and remove any disallowed functions/imports.
- No result returned: Ensure your code assigns to 'result' or uses a 'return' statement. If neither is present, the output may not be what you expect.
- Type errors at runtime: Verify that 'input_data' is the type your code expects. Add type checks (e.g., isinstance) to handle mixed inputs.
- Empty or None output: Confirm your logic path sets a value for all conditions. Initialize 'result' to a sensible default.
- Timeouts or long runs: Simplify the code, avoid large loops, and lower data sizes to keep execution within the specified time.