By Flavio
Tagged: AI
Google's Three-Live sandboxes an LLM-written Three.js script and compiles it to glTF and USDZ for the web, Android, and iOS.
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:
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:
<!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:
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.
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:
<three-live script-src="https://flaviocopes.com/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:
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:
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
THREEandsceneglobals, and attach everything throughscene.add(). - Skip
GLTF,OBJ,Texture,EffectComposer,ShaderMaterial,RawShaderMaterial, andrequestAnimationFrame. - Don’t instantiate
THREE.WebGLRendereror accesswindowanddocument. - 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 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:
On my Apple Silicon Mac, I downloaded the CLI like this:
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:
./three-live-cli convert planet.js -o planet.glb
If you want a file ready for Apple’s AR Quick Look, pass -f usdz instead:
./three-live-cli convert planet.js -f usdz -o planet.usdz
Once you have a precompiled .glb, you can ship the lighter viewer-only build on your frontend without bundling the script compiler:
<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:
fetch('https://flaviocopes.com')
When I ran the compiler on it, the sandbox blocked fetch immediately:
./three-live-cli convert bad.js -o bad.glb
Next up is loop.js, a classic infinite loop:
while (true) {}
Instead of hanging the process, Boa stops execution once it hits the loop iteration cap:
./three-live-cli convert loop.js -o loop.glb
Finally, let’s try big.js, which attempts to add 100,000 boxes to the scene:
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:
./three-live-cli convert big.js -o big.glb
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:
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. You can edit a script there and watch it compile live in your browser.
Sources #
Want me to talk about your product? You can sponsor this site.