ComfyUI Node

PyCode Max

Run Python Inside Your ComfyUI Graph (Carefully)

By orion4d·Created 5 months ago·Updated 5 months ago· 5
PyCode Max
  • img_in_1
  • img_in_2
  • mask_in
  • latent_in
  • positive
  • negative
  • model
  • clip
  • vae
  • audio_in
  • video_in
  • custom_in_1
  • custom_in_2
  • trigger
  • txt_out_1
  • txt_out_2
  • txt_out_3
  • txt_out_4
  • int_out_1
  • int_out_2
  • float_out_1
  • float_out_2
  • img_out_1
  • img_out_2
  • mask_out
  • latent_out
  • positive
  • negative
  • model
  • clip
  • vae
  • audio_out
  • video_out
  • custom_out_1
  • custom_out_2
  • Console
source
code# Your Python code is here, important: enable developer mode in config.json and set it to "true"
script_file
timeout_sec120
clear_statefalse
txt_in_1
txt_in_2
txt_in_3
txt_in_4
int_in_10
int_in_20
float_in_10.00
float_in_20.00

PyCode Max is the reason the whole Orion4D_MetaNode pack exists. Every other node in the suite is a convenience; this one is the engine. It drops a Python interpreter into the middle of your workflow - you write code, it runs against the actual tensors, strings, models, and latents flowing through your graph, and the result feeds right back into the pipeline.

Concretely: any connected input lands in an IN dict, your script reads it, writes results to OUT, and those become the node's outputs. IN["img_in_1"] is a PIL image of whatever you plugged in; IN["model"] is the actual model object. OUT["txt_out_1"] = "hello" and it appears on the wire. You also get STATE, a per-node dict that persists between runs (so you can keep a counter or a cache alive), and torch, np, Image, json, math, os, time are all pre-imported for you.

The inputs. source picks between text_input (type code in the box) and file (run a .py from the pack's pyscripts/ folder - examples like Ollama_vision.py and read_png_metadata.py ship with it). Universal inputs cover txt, int, float, image, mask, latent, conditioning, model, clip, vae, audio, video, plus two wildcard custom_in slots and a trigger. timeout_sec (5–600, default 120) guards against infinite loops, and clear_state wipes the persistent STATE.

The helpers are the hidden value. The execution scope injects llm and gpu dictionaries. llm["generate"](prompt, model="qwen2.5-vl:7b", images=IN["img_in_1"]) talks to a local Ollama server - vision included, so you can describe an image mid-workflow and pipe the caption into a prompt. gpu["torch_vram"]() and gpu["vram"]() read VRAM from inside your script (the latter needs pip install nvidia-ml-py). This is the local-LLM-in-the-graph pattern the community has been converging on, minus the boilerplate.

Now the honest part. This node executes arbitrary Python with full user-level access. The author got real pushback on Reddit about exactly that, and the design response is sound: text_input mode is locked by default. You must edit config.json in the pack folder and set "developer_mode": true before typed code will run. That's deliberate - loading a shared workflow with a PyCodeMax node is, with dev mode on, equivalent to running a script from the internet. Keep it off unless you wrote the code, and if you must run untrusted workflows, run ComfyUI in a container. This is the same class of risk that produced the LLMVISION incident, and it's worth taking seriously.

Install. ComfyUI Manager → search "Orion4D_MetaNode", or git clone https://github.com/orion4d/Orion4D_MetaNode into custom_nodes/, then restart. No heavy deps for the core; nvidia-ml-py is optional and only powers the gpu["vram"]() helper.

Troubleshooting. Getting the "text_input is blocked" error is expected behavior, not a bug - flip developer_mode if you mean it. A file-source script that wasn't in pyscripts/ when ComfyUI started is refused until you restart (or enable dev mode). Console output, timing, and script doc-comments all show up in the node's built-in Console output. And if a run hangs, your timeout_sec is the fuse.

It's the most powerful node in the pack, and the most dangerous. Use it like a loaded tool.

CategoryOrion4D_MetaNode/Brain

Inputs (27)

NameTypeDefaultDescription
sourceCOMBO2 options: text_input, file
codeSTRING# Your Python code is here, important: enable developer mode in config.json and set it to "true"
script_fileCOMBO6 options: None, clipping_BiRefNet.py, Ollama_vision.py, read_png_metadata.py, Ollama_txt-v1.py, Latent_Megapixel_Builder.py
timeout_secINT1205–600
clear_stateBOOLEANfalse
txt_in_1optSTRING
txt_in_2optSTRING
txt_in_3optSTRING
txt_in_4optSTRING
int_in_1optINT0
int_in_2optINT0
float_in_1optFLOAT0.00
float_in_2optFLOAT0.00
img_in_1optIMAGE
img_in_2optIMAGE
mask_inoptMASK
latent_inoptLATENT
positiveoptCONDITIONING
negativeoptCONDITIONING
modeloptMODEL
clipoptCLIP
vaeoptVAE
audio_inopt*
video_inopt*
custom_in_1opt*
custom_in_2opt*
triggeropt*

Outputs (22)

NameTypeDescription
txt_out_1STRING
txt_out_2STRING
txt_out_3STRING
txt_out_4STRING
int_out_1INT
int_out_2INT
float_out_1FLOAT
float_out_2FLOAT
img_out_1IMAGE
img_out_2IMAGE
mask_outMASK
latent_outLATENT
positiveCONDITIONING
negativeCONDITIONING
modelMODEL
clipCLIP
vaeVAE
audio_out*
video_out*
custom_out_1*
custom_out_2*
ConsoleSTRING