Decoding How Next-Generation LLMs Generate Animations Through Code Execution

    A technical breakdown of how large language models can autonomously write and execute code to produce visual content, including synthesized audio, and programmatic rendering. It covers core principles, differences from direct video generation, engineering considerations, and current limitations.

    1. From Community Demos to a Technical Paradigm

    Recently, a set of eye-catching demonstrations has been circulating in overseas developer communities. According to these unverified reports, a next-generation flagship model, without calling any image or video generation tools, autonomously wrote and ran code for about 2 hours and 40 minutes. The result was a roughly 66-second animation that included visuals, background music, and sound effects, ultimately packaged as a single HTML file that opens directly in a browser. Related demos also show interactive 3D scenes generated by models—featuring sailboats, ocean waves, sports cars, and other objects—built on frontend graphics frameworks like Three.js.

    One clarification is essential up front: these demos were published by developers themselves and have not been officially validated. Neither the identity of the model nor whether the process was fully free of human intervention has been independently confirmed. So rather than asking “which model was it,” the more useful question for engineering teams to explore is this: how can large language models leverage code execution environments to produce visual content end to end? That is the general-purpose capability worth studying.

    2. Breaking Down the Core Technical Principles

    2.1 From Generating Pixels to Generating Programs

    Traditional content generation paradigms aim to produce pixels or samples directly: video generation models output sequences of frames, and image models output bitmaps. The “code-generates-animation” paradigm, by contrast, aims to produce an executable program, which then computes and renders frames at runtime. The input/output boundaries of the two approaches are fundamentally different:

    Dimension Direct Generation Code-Based Construction
    Output Pixels / audio-video streams Executable code + assets
    Controllability Prompt-dependent; hard to make local edits Parameterized; precise adjustment possible
    Editability Low; requires regeneration High; edit the code
    External assets Usually not needed Can be built with none
    Rendering determinism Contains randomness Same code produces same result

    2.2 Synthesizing Sound: Composing Music in Code

    A notable detail in the demos is that both the background music and sound effects were synthesized by Python code written by the model, rather than pulled from any asset library. This is entirely feasible technically: digital audio is essentially a sequence of samples, and any waveform can be produced by combining, modulating, and enveloping mathematical functions. Example code:

    1. import numpy as np
    2. import wave
    3. sr = 44100 # sample rate
    4. duration = 3.0 # duration of a single note
    5. t = np.linspace(0, duration, int(sr * duration), endpoint=False)
    6. def envelope(signal, attack=0.01, release=0.3):
    7. """Simple linear envelope to avoid clipping artifacts"""
    8. a = int(sr * attack); r = int(sr * release)
    9. env = np.ones_like(signal)
    10. env[:a] = np.linspace(0, 1, a)
    11. env[-r:] = np.linspace(1, 0, r)
    12. return signal * env
    13. def tone(freq, amp=0.3):
    14. """Sine wave plus overtones to approximate a basic tone"""
    15. sig = np.sin(2 * np.pi * freq * t)
    16. sig += 0.3 * np.sin(2 * np.pi * 2 * freq * t) # 2nd harmonic
    17. sig += 0.1 * np.sin(2 * np.pi * 3 * freq * t) # 3rd harmonic
    18. return envelope(sig * amp)
    19. # Simple chord: root + third + fifth
    20. chord = tone(261.63) + tone(329.63) + tone(392.00)
    21. # Write out as a WAV file
    22. pcm = (chord * 32767).astype(np.int16)
    23. with wave.open("bgm.wav", "wb") as f:
    24. f.setnchannels(1); f.setsampwidth(2); f.setframerate(sr)
    25. f.writeframes(pcm.tobytes())

    This code illustrates the point: background music does not require “sampling”—only “synthesis.” The same applies to sound effects (wind, water, explosions), which can be approximated through noise shaping combined with filters.

    2.3 Building the Visuals: Two Mainstream Approaches to Programmatic Rendering

    On the visual side, the standard industry practice is to call browser-native Canvas 2D or WebGL APIs, using graphics abstraction layers such as Three.js to assemble scenes. The core idea is to describe geometry, materials, lighting, and cameras in code, then let the rendering pipeline draw frame by frame:

    1. // Pseudocode: minimal runnable Three.js scene skeleton
    2. const scene = new THREE.Scene();
    3. const camera = new THREE.PerspectiveCamera(45, w / h, 0.1, 1000);
    4. const renderer = new THREE.WebGLRenderer({ antialias: true });
    5. // Lighting: ambient + directional, determines overall brightness and shadows
    6. scene.add(new THREE.AmbientLight(0xffffff, 0.5));
    7. const sun = new THREE.DirectionalLight(0xffffff, 1.0);
    8. sun.position.set(5, 10, 7);
    9. scene.add(sun);
    10. // Object: using a sports car as an example, can be built from basic primitives or procedural modeling
    11. const car = buildCarFromPrimitives(); // assembled from cubes and cylinders
    12. scene.add(car);
    13. // Animation loop: achieve motion by modifying properties
    14. function animate(t) {
    15. car.position.x = Math.sin(t * 0.5) * 10; // back-and-forth movement
    16. renderer.render(scene, camera);
    17. requestAnimationFrame(animate);
    18. }
    19. animate(0);

    The key here is that the model must understand fundamental graphics concepts such as coordinate systems, lighting models, material properties, and time interpolation to generate scenes that are semantically correct and visually coherent. This also explains why claims of “generating scenes from just a simple prompt” are not exaggerated—when the underlying capabilities have been abstracted into mature APIs, the difficulty of mapping natural language to code drops substantially.

    2.4 Engineering Significance of Long-Duration Autonomous Execution

    Running autonomously for 2 hours and 40 minutes is, in essence, a long-horizon agent loop: the model needs to “write code → execute → observe errors or rendered output → correct → execute again,” iterating repeatedly until the output meets requirements. This is fundamentally different from traditional single-pass inference:

    • State management: intermediate artifacts (files, variables, completed scene nodes) must be tracked;
    • Error recovery: when runtime exceptions occur or rendered output does not match expectations, the model must diagnose and fix issues on its own;
    • Goal decomposition: breaking “make a 66-second animation” into subtasks such as storyboarding, modeling, music, sound effects, and compositing;
    • Context pressure: long-running tasks require the context window to hold a large volume of intermediate information, making long-context capability (million-token level) a hard requirement for this kind of work.

    3. Fundamental Differences from Mainstream Video Generation Paradigms

    Discussions in the community often compare this approach with methods that generate video frames directly. The difference is not about which is “better” but about fundamentally different use cases:

    • Direct generation excels at “filming” photorealistic shots—live-action-style people, landscapes, special effects—with strengths in visual realism and generation speed;
    • Code-based construction excels at “computing” precise, parameterizable, and interactive content, with strengths in full controllability, editability, and programmatic extensibility, and no dependency on external asset libraries.

    For example, if you need a shot of “waves crashing against an ancient sailboat,” direct generation may produce it faster. But if you need a fully interactive 3D scene where users can rotate the viewpoint, adjust time, or swap models, only the code-based approach can deliver. The two are more complementary than competing.

    4. Key Engineering Considerations for Practical Adoption

    For technical teams looking to reproduce or apply similar capabilities, the following engineering areas deserve close attention:

    4.1 Execution Sandboxes and Security

    Allowing a model to autonomously write and run code means code will execute in a real environment, with risks involving file read/write, network access, and resource consumption. Production deployments must introduce sandbox isolation (containerized execution, resource limits, network whitelists) to prevent both accidental damage and malicious code from causing harm.

    4.2 Long-Context Requirements and Cost Structure

    Long-horizon tasks place heavy demands on both context window and token consumption. Under standard industry billing models, model APIs typically charge separately for input tokens and output tokens, and the cost of long-running, multi-iteration tasks can accumulate significantly. Teams must balance task complexity against token budget, potentially adopting strategies such as task segmentation, intermediate result caching, and on-demand invocation.

    4.3 Artifact Packaging and Distribution

    The practice of packaging the final output as a single HTML file is worth emulating: self-contained, zero-dependency, cross-platform. All scripts, styles, and assets are inlined or bundled, so the recipient only needs a browser to open it, greatly reducing distribution and collaboration costs.

    4.4 Observability and Debugging

    Long-running autonomous execution is effectively a “black box.” Teams need robust logging and intermediate artifact retention mechanisms so that when results fall short of expectations, the problematic step can be traced back. General-purpose cloud capabilities such as logging services and monitoring alerts can add value here.

    5. Application Boundaries and Realistic Expectations

    It is important to recognize clearly that the current “code-generates-animation” capability remains in the demo and exploration stage, with meaningful distance to go before production-grade stable output:

    1. Unstable quality: the same prompt may yield significantly different results across generations, and the visual coherence of complex scenes still requires human review;
    2. Time and cost: a multi-hour generation cycle is too long for most business scenarios, making this approach better suited to “offline production with iterative refinement” than “real-time interaction”;
    3. Controllability as a double-edged sword: while code-based approaches enable editability, they also require users to have a certain level of technical understanding, meaning the barrier to entry for non-technical users remains;
    4. Ecosystem dependencies: rendering quality depends heavily on browser graphics capabilities and the maturity of the frontend technology stack.

    6. Conclusion

    What deserves developers’ attention in these community demos is not the “spec competition” of any particular model, but the technical trend they reflect: large language models are evolving from “content generators” to “program authors,” using code as a universal medium to transform natural-language intent into runnable, editable, and distributable visual artifacts. This path holds unique value in scenarios such as interactive content, procedural animation, and rapid prototyping. Yet it also faces real constraints around long-horizon execution, cost structure, and quality stability. For technical teams, the right way to embrace this trend is to assess its capabilities rationally and validate it in suitable scenarios through pilot projects.