A custom ComfyUI node that allows users to execute arbitrary Python code with a single input (value) and output (result), enabling flexible processing of the input value using any Python code before assigning the final result to result. It also captures print() output and exceptions for debugging.
- Dynamic Input/Output Type: The node accepts any type (ANY_TYPE) as input (value) and ensures the output (result) matches the upstream/downstream type.
- Python Code Execution: Write and execute Python code in a multiline text box (code).
- Debug Output: Captures print() statements and exceptions, outputting them to debug_output as a string.
- Menu Integration: Appears in the right-click "Add Node" menu under the python_node category as "Execute Python Code".
- Type Safety: Enforces that result must be explicitly assigned in the code to maintain type consistency.

Clone or Download: Place the ComfyUI-PythonNode folder into your ComfyUI custom_nodes directory:
ComfyUI/custom_nodes/ComfyUI-PythonNode/
value: Any type (ANY_TYPE) input, connected from upstream nodes. code: A multiline string field where you write Python code. Default value:
# Write Python code here
# 'value' is ANY_TYPE, assign 'result' (must match upstream/downstream type)
print("value=", value)
result = valueresult: The result of the executed code, matching the type of value. Must be assigned in the code.
debug_output: A string containing print() output or error messages from exceptions.
The node uses exec() to run user-provided code, which can execute arbitrary Python statements. Use with caution in untrusted environments.
This project is released under the MIT License.