Code as Pixels: a coding agent writes Python to fix images mid-denoising, frozen FLUX renders the rest
Code as Pixels is a research project in which a coding agent looks at an image while it is still being generated, repaints the pixels directly with Python, and then lets an unmodified, frozen image model finish the render. It needs no extra training and works with FLUX.1-dev, Qwen-Image and LongCat-Image, and the team reports that it beats Nano-Banana on an image-editing benchmark. The code is on GitHub under the MIT license, and the announcement post passed 70K views and 900 bookmarks.
![]()
Pause mid-generation, fix it in code, then let the model continue
Code as Pixels does not change the image model at all. It splits the work in two: a coding agent rewrites pixels in Python to decide content and layout, and a frozen, pretrained flow model denoises the edited area into realistic detail. Supported models are FLUX.1-dev, Qwen-Image and LongCat-Image.
For text-to-image, it first runs one normal generation and pulls out the predicted final image at steps 15, 25, 34 and 42. If it spots a problem such as a wrong count, odd layout, or wrong color or object, the agent writes a Python function called edit_image(img) to fix the pixels and sends only that region back to a middle step to be re-rendered. It retries up to two times.
In the announcement video, with the prompt "four sheeps and a trumpet," one extra sheep is removed with code and the image keeps rendering into a natural photo.
For editing, it chooses how much of the original to keep, per edit
Editing does not use a model fine-tuned for editing. The agent looks at the source image and the instruction, picks a mask for what to change, such as only the person, only the background or the area around the head, and can sketch a draft with PIL or OpenCV. The frozen model then blends the draft in so it looks like a natural photo. The video shows a bear-shaped lamp being turned into glass.
How much of the original photo to keep is set by a value λ between 0 and 1, chosen by the agent for each edit. At 0 it redraws shapes and materials from the prompt alone; closer to 1 it keeps the source's fine texture. For edits that would blur if passed through the model, like text and charts, there is a mode that outputs the code-drawn pixels as they are. Results are reviewed up to three times, deciding whether to accept, tune the value or rewrite the code.
Benchmarks, and a studio you can run yourself
In the team's published results, compared with FLUX.1-dev alone, GenEval rises from 67.79 to 80.87, GenEval 2 from 22.72 to 68.05 and WISE from 44.90 to 74.50. On the GEditBench v2 arena Elo for editing (average of 1,000), the LongCat-Image version scores 1095.0, above Nano-Banana's 1090.1, with the Qwen-Image version at 1079.7 and the FLUX.1-dev version at 1076.7.
The code is public on GitHub under the MIT license, the dataset is on Hugging Face, and the paper is listed as coming soon. The included "code-as-pixels studio" is an interactive tool that shows generation and editing branches as a tree and lets you rewrite the prompt or the Python code at any step to fork a new branch. It has a demo mode that runs without a GPU, and results can be exported as HTML you can view offline.




