A walkthrough of using OpenAI Codex to generate, validate, and visually verify LEGO set files by building its own toolchain around the Studio software format.
Adapted from @dkundel# Building LEGO sets with Codex Once you understand Codex is great at building tools and verifying its own work, the world becomes your oyster. To test this I thought it would be fun to explore if Codex can build LEGO sets on its own. Not using image generation, HTML or SVGs but actual LEGO sets. Typically people build these using Studio from Bricklink, a software that is essentially a 3D modeling software for LEGO that also allows you to generate instructions and similar LEGO specific features. (https://www.bricklink.com/v3/studio/download.page) ## The idea What if we can have Codex build itself tools and a skill with the necessary information to: 1. Generate new LEGO sets by writing the necessary files 1. Verify that the files are valid 1. Use the Studio software to create renderings to verify it looks right (using Codex's image input capabilities) ## Building a LEGO skill But what are the "necessary files"? They are called .io files but I had no idea what they actually looked like on the inside. Instead I used one of the example models from the Studio software and gave it to Codex as a reference to figure everything out. Here's my initial prompt: From here I fired off Codex in "Plan mode" first, answered some of its questions and then asked it to implement the plan but let's have Codex summarize what it did: > I started by using a sample Studio model to figure out what a `.io` file actually is, instead of guessing. I found it’s a ZIP bundle with `model.ldr` as the core geometry, plus metadata and optional assets. From there, I built a dedicated `lego-studio-builder` skill with scripts to unpack/pack models, apply explicit brick operations, and validate structure (submodel links, transforms, part counts, bounds, and metadata consistency). So the output wasn’t just a one-off model, it became a repeatable toolchain. Then I wired everything into a strict loop: make a small edit batch, validate it, repack, generate a visual checkpoint, compare to a reference image, and repeat. It also handled environment issues like sandboxed screenshot failures by supporting elevated capture and safe fallbacks with warnings. Finally, I added a real modeling playbook (scale rules, phased building strategy, submodel conventions, and quality gates) and moved the skill into `.agents/skills` so I can reuse it directly in this project. ## Testing the skill After creating the skill it was time to test it. I like testing my skills by giving it as little context as possible the same way that I want to use them later. So in my case I asked it recreate the Codex logo with an image reference attached. Let's say the result had room for improvement. But it had one clear indication: Codex did create an image rendering and reported the output. That means there is room for improvements. Instead of iterating on the skill I decided to just ask Codex to keep tweaking it fixing some of the most glaring issues. And the improvement was already night and day. This time Codex worked longer, did checks in between and got into a much better state. Not perfect but more usable. After iterating a bit more Codex learned to use Python code to calculate and estimate locations, deal with symmetry and more. Eventually we got to a state where we had a result I was happy with but admittedly a very large model with 12,679 pieces. Now that Codex had a good grasp at things I could solve those problems easily though. I asked Codex to decrease the model size to fit on my desk and it went off and did so. In the process it decreased the model piece count from 12,679 to 4,081 pieces while keeping the overall look of the model. ## Improving the skill The beauty of skills is that they are not set in stone and are easy to improve over time. In this case I ended up forking the conversation that led to this state of the model and asked Codex to review the conversation and update the skill with learnings. Tip: If you are using the Codex app you can also do this automatically on a regular basis by using Automations. ## Conclusion This has been a really fun experiment and as a LEGO fan I'll continue to play around with this but more importantly it highlights a concept that can be applied to Codex in general. Codex works best when it has tools to verify its work and because it runs on your device it can learn about the tools you are already using and improve them. In front-end development this might be using Playwright to control your browser. For iOS development Codex can use the iOS simulator and accessibility tools. But it doesn't have to stop at traditional developer tools. You simply have to ask. If you want another example of this, check out @heccbrent use case of having Codex control and edit videos in Premiere. (https://x.com/heccbrent/status/2026430769464308040?s=20) What else have you tried to have Codex work with?