Nodes/ComfyUI-Teeth/Teeth Run Python Code
ComfyUI Node

Teeth Run Python Code

Run Real Python Inside a ComfyUI Graph (No Training Needed)

By steelan9199·Created 2 years ago·Updated about a year ago· 10
Teeth Run Python Code
  • value1
  • value2
  • value3
  • value4
  • value5
  • value6
  • result
coderesult = value1 + value2

The shortest path from "I wish this node did the one thing differently" to "it does now" is usually a Python node. Teeth Run Python Code is exactly that: an exec() box in the middle of your graph. Wire in up to six values, write a few lines of Python, read the answer back out. No separate pack to install, no model to download, no training run - just code.

It comes from ComfyUI-Teeth, a small Chinese-origin utility pack (ten nodes, one author, GPL-3.0). It has no heavy community footprint - search the subreddits and you'll find almost nothing about it - but this node is the pack's most-searched page for a reason: it's the general-purpose escape hatch that the other nine are specialized versions of.

How it works

Under the hood it's a raw Python exec(). Your code input (the required one, multiline, default result = value1 + value2) is run with value1 through value6 available as variables, plus np (numpy), torch, PIL, and re pre-loaded in the global namespace. Anything your code computes has to land in a variable named result - that single variable becomes the node's output.

So a practical example, picking the red channel mean of an incoming image:

result = float(torch.mean(value1[0, :, :, 0]))

That's it. value1 is an image tensor, you compute a number, the node hands it out the result output, and you wire it into a text display or a comparison node.

Inputs and outputs that matter

  • code (required, multiline) - the Python to execute.
  • value1–value6 (optional, any type) - tensors, strings, numbers, lists, whatever you've got in the graph.
  • result (output, any type) - whatever your code put in the result variable.

There are only two things a beginner actually sets: the code, and whichever value inputs you care about. The rest of the ports can stay empty.

Where people get burned

Forgetting result. If your code never assigns result, the node prints a warning and returns None. You'll see a disconnected-looking output and no error dialog - check the terminal.

Caching. The author left the IS_CHANGED override commented out, which means ComfyUI caches this node by its input values. Run the graph twice with the same code and same inputs and the second run pulls the cached answer - your code doesn't re-execute. That's great for speed and infuriating when your code has side effects (writing a file, drawing randomness). Change any input to force a re-run.

It's arbitrary code execution. Same trust level as any workflow you load - a malicious JSON can run anything in ComfyUI anyway - but don't paste in code you don't understand. Errors print to the console, not the UI, so when a run silently returns None, the terminal is the first place to look.

Install

ComfyUI Manager works: search for ComfyUI-Teeth and hit install. Or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/steelan9199/ComfyUI-Teeth

Restart ComfyUI. The pack's requirements.txt lists opencv-python, torch, numpy, Pillow, and google-genai - the README notes you almost certainly already have all but google-genai from other packs, so install rarely needs anything. When this node errors with a ModuleNotFoundError, check the console, because it's usually an upstream dependency, not this node.

The one honest caveat: this is a small single-author pack. When it breaks, the issue tracker and the source in custom_nodes/ComfyUI-Teeth are your documentation - and for a node this simple, that's usually enough.

CategoryTeeth

Inputs (7)

NameTypeDefaultDescription
codeSTRINGresult = value1 + value2
value1opt*
value2opt*
value3opt*
value4opt*
value5opt*
value6opt*

Outputs (1)

NameTypeDescription
result*