# Turn AI-generated Three.js into 3D and AR with Google's Three-Live

> Google's Three-Live sandboxes an LLM-written Three.js script and compiles it to glTF and USDZ for the web, Android, and iOS.

Author: [Flavio Copes](https://flaviocopes.com/about/) | Published: 2026-12-03 | Topics: [AI](https://flaviocopes.com/tags/ai/) | Canonical: https://flaviocopes.com/three-live-ai-generated-3d/

Google released **Three-Live** on November 3, 2026. It's an open source library (Apache 2.0, Developer Preview) that takes Three.js code, usually written by an LLM, and runs it safely on the web, Android, and iOS.

The problem it solves is easy to see. LLMs are already pretty good at writing Three.js scenes.

But code generated at runtime is untrusted, and you don't want to `eval` it inside your page. On top of that, phones have native 3D and AR engines that a regular WebView can't touch.

So Three-Live treats a subset of the Three.js API as a scene description language. It runs the script inside a sandbox and compiles the output into standard `.glb` (binary glTF 2.0) and `.usdz` files.

From there, each platform renders the scene with its own engine: a small WebGL2 renderer on the web, Google Filament on Android, and RealityKit on iOS. Here is how that pipeline flows:

```mermaid
flowchart TD
  accTitle: How Three-Live turns a script into 3D
  accDescr: An LLM-written Three.js script runs in a Web Worker or the Boa VM, compiles to glb and usdz, then WebGL2, Filament, and RealityKit render it.
  script[Three.js script] --> sandbox[Sandbox]
  sandbox --> worker[Web Worker]
  sandbox --> boa[Boa VM in Rust]
  worker --> files[".glb / .usdz"]
  boa --> files
  files --> web[WebGL2 on web]
  files --> android[Filament on Android]
  files --> ios[RealityKit on iOS]
```

> Three-Live is still alpha and not an officially supported Google product. On November 4, 2026, the npm package was at `1.2.1` and the latest CLI release was `v1.2.0`.

## The sandbox

How does Three-Live keep untrusted JavaScript from doing damage?

On the web, it runs your script in a Web Worker or an optional opaque-origin `<iframe sandbox="allow-scripts">`, which isolates it from your site's storage and cookies. Before your code executes, it strips out network primitives like `fetch`, `XMLHttpRequest`, `WebSocket`, and dynamic `import()`.

On Android, iOS, macOS, and the command line, there is no browser at all. Instead, Three-Live compiles scripts inside an embedded Rust compiler powered by the Boa JavaScript engine.

Both runtimes enforce strict execution time limits and geometry quotas. According to the LLM guide, a single scene caps out at 1,000 meshes, 100,000 vertices, 300,000 indices, and 16 textures.

## Your first scene in HTML

Inside a Three-Live script, we only get two globals: `THREE` and `scene`. You build objects and pass them to `scene.add()`, without ever creating a renderer or calling `requestAnimationFrame`.

Here is a minimal HTML page that renders a rotating torus knot with orbit controls and an AR button:

```html
<!doctype html>
<html>
  <body>
    <script src="https://cdn.jsdelivr.net/npm/three-live@1.2.1/dist/three-live.min.js"></script>

    <three-live
      allow-client-scripts
      camera-controls
      ar
      shadow-intensity="1"
      environment-image="studio"
      style="width: 100%; height: 480px; display: block;">
      <script type="text/three">
        const knot = new THREE.Mesh(
          new THREE.TorusKnotGeometry(0.6, 0.2, 128, 32),
          new THREE.MeshStandardMaterial({ color: 0x4285f4, metalness: 0.85, roughness: 0.15 })
        )
        scene.add(knot)

        scene.userData.animate = (t) => {
          knot.rotation.y = t * (Math.PI / 2)
        }
      </script>
    </three-live>
  </body>
</html>
```

Take a close look at `scene.userData.animate`. Instead of running that callback every frame in your browser, Three-Live bakes it into a looping glTF animation (4 seconds by default).

I really like that design choice, because the motion survives the jump into AR Quick Look on iOS or Scene Viewer on Android.

After adding ambient and directional light, I loaded this scene in Chrome. Here is the torus knot running inside `<three-live>`, complete with the built-in **View in AR** button in the corner:

![Blue metallic torus knot rendered inside Three-Live in Chrome with the View in AR button in the bottom-right corner](https://images.flaviocopes.com/three-live-ai-generated-3d/torus-knot.webp?v=39cecc7e)

One detail can trip you up at first: inline scripts require the `allow-client-scripts` attribute. If you leave it out, the element refuses to compile and renders nothing.

Because anyone can edit an inline script right in the browser, Three-Live makes you opt in explicitly. For the script tag type, you can use either `text/three` (shown in the README) or `text/three-live` (shown in the announcement post), since the element accepts both.

## Loading AI-generated scripts from your server

In a real app, the scene usually comes from an LLM on your backend rather than an inline tag. You point the `<three-live>` element to a URL with `script-src`:

```html
<three-live script-src="/scenes/planet.js" camera-controls ar></three-live>
```

Server-generated scripts don't need `allow-client-scripts`, and they still run in the sandbox.

To test this flow, I put together `planet.js`, a small scene with a planet, a tilted ring, two lights, and a slow rotation:

```js
const planet = new THREE.Mesh(
  new THREE.SphereGeometry(0.5, 48, 32),
  new THREE.MeshStandardMaterial({ color: 0xf59e0b, roughness: 0.6 })
)

const ring = new THREE.Mesh(
  new THREE.TorusGeometry(0.8, 0.04, 16, 96),
  new THREE.MeshStandardMaterial({ color: 0xe5e7eb, metalness: 0.3, roughness: 0.4 })
)
ring.rotation.x = Math.PI / 2.4

const system = new THREE.Group()
system.add(planet)
system.add(ring)
scene.add(system)

scene.add(new THREE.AmbientLight(0xffffff, 0.4))
const sun = new THREE.DirectionalLight(0xffffff, 1.2)
sun.position.set(2, 3, 2)
scene.add(sun)

scene.userData.animate = (t) => {
  system.rotation.y = t * (Math.PI / 2)
}
```

When we serve that file over `script-src="https://flaviocopes.com/planet.js"`, Chrome renders the orange planet and metallic ring right in WebGL2:

![Orange 3D sphere with a tilted silver ring rendered by Three-Live from planet.js in Chrome](https://images.flaviocopes.com/three-live-ai-generated-3d/planet.webp?v=994d400c)

## Getting good scripts out of an LLM

LLMs know far more Three.js than Three-Live supports, so you need to set boundaries in your system prompt. The repository already includes a copy-paste guide in `docs/llm-guide.md`, along with `llms.txt` and `llms-full.txt` feeds you can drop straight into a context window.

If you write your own prompt, include these core rules from the guide:

- Only use the `THREE` and `scene` globals, and attach everything through `scene.add()`.
- Skip `GLTFLoader`, `OBJLoader`, `TextureLoader`, `EffectComposer`, `ShaderMaterial`, `RawShaderMaterial`, and `requestAnimationFrame`.
- Don't instantiate `THREE.WebGLRenderer` or access `window` and `document`.
- Limit objects to the allowed constructors.

Here is the full list of constructors Three-Live supports:

| Kind | Constructors |
| :--- | :--- |
| Geometries | `BoxGeometry`, `PlaneGeometry`, `SphereGeometry`, `CylinderGeometry`, `ConeGeometry`, `TorusGeometry`, `TorusKnotGeometry`, `BufferGeometry`, `BufferAttribute` |
| Materials | `MeshStandardMaterial`, `MeshBasicMaterial`, `MeshLambertMaterial`, `MeshPhongMaterial`, `MeshPhysicalMaterial` |
| Scene graph | `Scene`, `Group`, `Mesh`, `Object3D` |
| Lights and cameras | `AmbientLight`, `DirectionalLight`, `PointLight`, `Camera`, `PerspectiveCamera` |
| Math | `Vector2`, `Vector3`, `Vector4`, `Euler`, `Quaternion`, `Matrix3`, `Matrix4`, `Color`, `MathUtils`, `Clock` |

What if the model slips up anyway? The compiler ships with fallback shims, so something like a `ShaderMaterial` gets downgraded to a `MeshStandardMaterial` instead of crashing the whole scene.

## Compile scenes from the command line

You don't need a browser to compile a scene. That makes Three-Live handy in a backend or CI job, where an LLM generates the script, your server compiles it, and you store the resulting `.glb`.

You can grab the `three-live-cli` binary from the [GitHub releases](https://github.com/google/three-live/releases) page, with builds for Linux (x86_64 and aarch64), macOS (arm64 and x86_64), and Windows. Here is a quick look at the repo layout on GitHub:

![The google/three-live repository on GitHub showing the compiler, examples, mobile, and skills folders](https://images.flaviocopes.com/three-live-ai-generated-3d/three-live-repo.webp?v=34ac13d8)

On my Apple Silicon Mac, I downloaded the CLI like this:

```bash
curl -L -o three-live-cli https://github.com/google/three-live/releases/download/v1.2.0/three-live-cli-macos-arm64
chmod +x three-live-cli
```

Then I compiled `planet.js` into a binary `.glb` file:

```bash
./three-live-cli convert planet.js -o planet.glb
# Successfully compiled "planet.js" -> "planet.glb" (179316 bytes)
```

If you want a file ready for Apple's AR Quick Look, pass `-f usdz` instead:

```bash
./three-live-cli convert planet.js -f usdz -o planet.usdz
# Successfully compiled "planet.js" -> "planet.usdz" (374790 bytes)
```

Once you have a precompiled `.glb`, you can ship the lighter viewer-only build on your frontend without bundling the script compiler:

```html
<script src="https://cdn.jsdelivr.net/npm/three-live@1.2.1/dist/three-live-viewer.min.js"></script>

<three-live src="planet.glb" camera-controls auto-rotate></three-live>
```

## Watching the sandbox say no

I wanted to see how well the sandbox holds up, so let's feed the CLI a few hostile scripts.

First, we save `bad.js`, which tries to make a network call:

```js
fetch('https://flaviocopes.com')
```

When I ran the compiler on it, the sandbox blocked `fetch` immediately:

```bash
./three-live-cli convert bad.js -o bad.glb
# Transcoding error: Three.js script error: ReferenceError: fetch is not defined
```

Next up is `loop.js`, a classic infinite loop:

```js
while (true) {}
```

Instead of hanging the process, Boa stops execution once it hits the loop iteration cap:

```bash
./three-live-cli convert loop.js -o loop.glb
# Transcoding error: Three.js script error: RuntimeLimit: Maximum loop iteration limit 250000 exceeded
```

Finally, let's try `big.js`, which attempts to add 100,000 boxes to the scene:

```js
for (let i = 0; i < 100000; i++) {
  scene.add(new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1), new THREE.MeshStandardMaterial()))
}
```

The compiler kills that one too as soon as it crosses the 250 ms execution ceiling:

```bash
./three-live-cli convert big.js -o big.glb
# Transcoding error: 3D execution time (255.2 ms) exceeded SECURITY_3D_EXECUTION_CEILING_MS (250 ms)
```

Every single one of these tests exits with code 1, never hangs, and writes no output file. In a real app, your backend can catch that failure and ask the LLM to try again.

## Native apps

You can also compile those scripts right on the device inside native apps.

On Android, Google provides a Kotlin SDK (`com.google.threelive:compiler`) that renders through Google Filament. On iOS and macOS, we get a Swift package (`ThreeLiveCompiler`) built for RealityKit, which you can add in Xcode using `https://github.com/google/three-live.git`.

Here is how the Swift integration looks, straight from the README:

```swift
import ThreeLiveCompiler
import RealityKit

let glb = try ThreeCompiler.compileToGLB(script: script)
let entity = try await RealityKitHelper.loadEntity(fromGLB: glb)
```

There is also a companion `<xr-live>` element for WebXR headsets with hand tracking, spatial HTML cards, and plugins. That's a big enough topic that I'll save it for another post.

If you want to try Three-Live right now without installing anything, open the [Three-Live Studio playground](https://google.github.io/three-live/three/). You can edit a script there and watch it compile live in your browser.

## Sources

- [Introducing Three-Live (Google Open Source Blog)](https://opensource.googleblog.com/2026/11/introducing-three-live-ai-generated-3d-ar-webxr.html)
- [google/three-live on GitHub](https://github.com/google/three-live)
- [LLM and agent authoring guide](https://github.com/google/three-live/blob/main/docs/llm-guide.md)
- [three-live on npm](https://www.npmjs.com/package/three-live)
- [Three-Live releases](https://github.com/google/three-live/releases)
