VRGDG_PythonCodeRunner
A safe Python sandbox inside ComfyUI, with the sharp edges off
- result_text
- result_json
- has_error
Every ComfyUI power user eventually hits the wall where the node graph can't express the transform they need - a JSON reshape, some string surgery, a math step - and wishes they could just write a few lines of Python. VRGDG_PythonCodeRunner is VRGameDevGirl's answer: a sandboxed Python node that runs your code on the inputs and hands the result back as a node output.
The key word is sandboxed, and the default code shows it. The comment block at the top of the editor spells out the deal: "Safety mode: imports, filesystem/process/network APIs are blocked." You get a curated set of built-ins - json, math, re, plus your two inputs input_text and input_json - and you set a variable named result. That's the whole API surface.
How it works
One required input:
python_code- your script. The available vars are listed in the default template:input_text,input_json,json,math,re. Setresultto any value before the script ends.
Two optional inputs:
input_text- a plain string you can feed in.input_json- a JSON string, typically a prompt map or scene list from upstream.
Outputs:
result_text- your result coerced to a string.result_json- your result serialized as JSON text.has_error- a boolean that flips true if your code raised, so downstream logic can branch on failure.
The default code is a working example: parse input_json, re-serialize it with indentation. Run it once to confirm the plumbing, then replace it.
What it's actually good for
The pack's prompt-map workflow is full of small transforms that are miserable in pure nodes - reordering fields, stripping keys, merging scene lists, regex-cleansing LLM output. Instead of a chain of five string-manipulation nodes, you write one five-line function. It's also handy for debugging: dump json.dumps(input_json, indent=2) to result_text and see exactly what an upstream node produced.
The safety caveat
The sandbox blocks file/process/network access - that's the point, and it's the responsible default given how many compromised custom nodes have shipped in this ecosystem. The trade-off: you can't read a file, write state, or call out to an API from inside it. If you need that, you need a real Python executor, not this node. Read the sandbox block before you trust it with anything sensitive, same as you would any custom node.
Installing it
Part of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/vrgamegirl19/comfyui-vrgamedevgirl
restart, or ComfyUI Manager → search vrgamedev. No models.
Gotchas
result is the only thing that matters - return statements are ignored. If your output stays empty, check you assigned result. And remember input_json arrives as a string; parse it with json.loads() before treating it as data, exactly like the default template does.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| python_code | STRING | # Available vars: input_text, input_json, json, math, re # Safety mode: imports, filesystem/process/network APIs are blocked. # Set `result` to any value. data = json.loads(input_json) if input_json.strip() else {} result = json.dumps(data, indent=2) | — |
| input_textopt | STRING | — | |
| input_jsonopt | STRING | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| result_text | STRING | — |
| result_json | STRING | — |
| has_error | BOOLEAN | — |