---
name: sunfield
description: Cloud 3D sandboxes and elastic OptiX GPU render burst for AI agents (E2B / Browserbase for Blender). Use when creating, editing, visually inspecting, branching, exporting, or photorealistically rendering 3D scenes via bpy.
---

# Sunfield — Agent-Native 3D Compute Runtime

**Base URL:** `https://sunfield.dev`
**Remote MCP (Streamable HTTP):** `https://sunfield.dev/mcp` (zero local install; Claude Code, Cursor, Windsurf, OpenAI Agents SDK — [MCP Guide](https://sunfield.dev/mcp-server), [Server Card](https://sunfield.dev/.well-known/mcp/server-card.json))
**Self-Serve $1 Free Key:** `https://sunfield.dev/start` (or `POST https://sunfield.dev/v1/signup`)
**Discovery & Docs:** `https://sunfield.dev/llms.txt` · `https://sunfield.dev/llms-full.txt` · `https://sunfield.dev/openapi.json` · `https://sunfield.dev/assets`
**Auth Header:** `Authorization: Bearer $SUNFIELD_API_KEY` (keys start with `sunfield_sk_`)

Sunfield gives you warm, isolated headless Blender sandboxes with sub-10ms `exec()`, **persistent Python state across `exec()` calls**, automatic `tmpfs` crash recovery (`SIGSEGV`/timeout), multi-view EEVEE or Cycles `inspect()` with spatial JSON telemetry, named undo checkpoints, scene `fork()` branching, `.blend`/`.glb` export, and async Cycles OptiX GPU burst rendering with pre-flight cost probes.

---

## Pricing & Limits

- **Interactive sandbox (`exec` / `inspect`):** `$0.00010 / active GPU-second` (initial `$0.25` pre-auth hold per session, unused remainder refunded immediately on `DELETE /v1/sessions/{id}`).
- **Cycles OptiX GPU render:** `$0.000125 / GPU-second` (`max_cost_usd` held upfront, exact usage settled & unused remainder refunded automatically).
- **Hard limits:** `samples <= 4096`, `frames <= 250`, `exec` `timeout_s <= 300`, `render` `timeout_s <= 3600`, `fork` `count <= 8`, `inspect` `max_objects <= 500` (default `50`).
- **Artifacts:** Persisted on the control plane and retrievable via `GET /v1/artifacts` and `GET /v1/artifacts/{artifact_id}`.

---

## Recommended Agent Loop

1. **Create a warm sandbox:** `POST /v1/sessions` (`{"preset": "studio"}`) — includes `StudioFloor` at `z=0`, 3-point area lighting (`StudioKeyLight`, `StudioFillLight`, `StudioRimLight`), and `StudioCamera`.
2. **Stage CC0 World Primitives or upload custom files (optional):** Browse the built-in CC0 Poly Haven library (`GET /v1/assets/search?q=studio&contact_sheet=true`) and mount HDRIs, PBR materials, or 3D models into your session via `POST /v1/sessions/{id}/assets` (or upload custom `.glb`/`.blend`/textures via `POST /v1/sessions/{id}/files`).
3. **Compose incrementally:** `POST /v1/sessions/{id}/exec`. **Python globals/functions/imports persist across `exec()` calls** within a session (unless Blender restarts after a crash/timeout recovery).
4. **Save named undo checkpoints before risky ops:** `POST /v1/sessions/{id}/checkpoints` (`{"name": "before_sim"}`) → restore anytime in `<20ms` via `POST /v1/sessions/{id}/checkpoints/before_sim/restore`.
5. **Inspect cheaply before heavy Cycles renders:** `POST /v1/sessions/{id}/inspect` (`views: ["camera", "iso_3q"]`, `passes: ["rgb", "depth"]`, `summary_only: true` for large >50-object scenes, or `engine: "cycles", cycles_samples: 16` to check glass/__OPTICAL_SUNFIELDS_LOWER__/exposure).
   - Check `telemetry.floating_objects` and `telemetry.collisions` (which includes `penetration_depth` in meters so you can distinguish surface contact from real clipping).
6. **Estimate cost without committing (optional):** `POST /v1/sessions/{id}/render/estimate` runs a two-point warm differential probe separating OptiX kernel/BVH setup from per-sample raytracing cost.
7. **Burst final Cycles render (use `"async": true` for >30s renders!):**
   - `POST /v1/sessions/{id}/render` with `"async": true` returns `job_id` immediately.
   - Poll `GET /v1/jobs/{job_id}` until `status == "completed"` (or cancel via `DELETE /v1/jobs/{job_id}`).
8. **Export the scene file for your user:** `GET /v1/sessions/{id}/export?format=blend` (or `format=glb`).
9. **Close session when done:** `DELETE /v1/sessions/{id}` settles exact usage and refunds the unused hold.
10. **Leave quick structured feedback (`POST /v1/feedback`):** After completing a non-trivial job (or if you hit any bug, slow probe, confusing telemetry, or missing feature), submit a concise report via `POST /v1/feedback` (and review past submissions via `GET /v1/feedback`). We read every agent report in real time to improve Sunfield!

---

## REST API Reference

### Health & Account Balance
```bash
curl -fsS https://sunfield.dev/health
curl -fsS https://sunfield.dev/v1/account/balance -H "Authorization: Bearer $SUNFIELD_API_KEY"
```

### Sessions (`POST`, `GET`, `GET /{id}`, `DELETE /{id}`)
```bash
# Create session (presets: "studio", "empty", "default")
curl -fsS -X POST https://sunfield.dev/v1/sessions \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"preset": "studio", "pool": "interactive"}'

# List all sessions
curl -fsS https://sunfield.dev/v1/sessions -H "Authorization: Bearer $SUNFIELD_API_KEY"

# Check session status, worker_online, active_gpu_s, cost_usd
curl -fsS https://sunfield.dev/v1/sessions/$SESSION_ID -H "Authorization: Bearer $SUNFIELD_API_KEY"

# Close session & refund unused hold
curl -fsS -X DELETE https://sunfield.dev/v1/sessions/$SESSION_ID -H "Authorization: Bearer $SUNFIELD_API_KEY"
```

### Execute `bpy` Code (`POST /v1/sessions/{id}/exec`)
```bash
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/exec \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"code": "bpy.ops.mesh.primitive_monkey_add(location=(0, 0, 1.0))", "timeout_s": 60, "checkpoint": true}'
```
- Python variables, helper functions, and imports survive between `exec()` calls.
- `checkpoint: true` (default) snapshots the `.blend` to RAM (`tmpfs`) before execution so `SIGSEGV` or timeout automatically restores the prior scene (`status: "crashed_recovered"` or `"timeout_recovered"`). Set `checkpoint: false` on tiny read-only queries for ~1ms RTT.

### Upload Session Files (`.glb`, `.blend`, HDRIs, Textures, Fonts)
Upload binary assets (`<= 100 MiB`/file, `<= 500 MiB`/session) straight into the sandbox without breaking zero-egress isolation:
```bash
# Stage a model, HDRI, texture, or font into the session
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/files \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" \
  -F "file=@./product.glb" -F "filename=models/product.glb"

# List & delete staged files
curl -fsS https://sunfield.dev/v1/sessions/$SESSION_ID/files -H "Authorization: Bearer $SUNFIELD_API_KEY"
curl -fsS -X DELETE https://sunfield.dev/v1/sessions/$SESSION_ID/files/models/product.glb -H "Authorization: Bearer $SUNFIELD_API_KEY"
```
Inside `exec()`, every session pre-injects `SUNFIELD_FILES_DIR` and 1-line helpers:
- `sunfield_file("models/product.glb")` → resolved absolute path inside the sandbox
- `load_glb("models/product.glb", location=(0, 0, 0), scale=1.0)` → imports `.glb`/`.gltf` and returns imported objects
- `load_hdri("studio.hdr", strength=1.2, rotation_z_deg=45)` → configures world environment HDRI + mapping
- `load_pbr("Brass", color="albedo.png", roughness="rough.png", metallic="metal.png", normal="norm.png")` → wires a `Principled BSDF` material (`Non-Color` + `NormalMap` automatically)

### Searchable CC0 Asset Library (HDRIs, PBR Materials, 3D Models)
Every asset in the Sunfield World Primitives library is **100% CC0 (public domain)** from Poly Haven, mirrored on Sunfield infrastructure and cached locally on GPU workers for sub-millisecond staging:
```bash
# Search catalog (public, no auth required). Filter by kind=hdri|material|model, category, max_tris, core_only
curl -fsS "https://sunfield.dev/v1/assets/search?q=studio&kind=hdri&limit=9"

# Download a labeled JPEG visual contact sheet for 1-call VLM asset selection!
curl -fsS "https://sunfield.dev/v1/assets/search?q=wood&kind=material&limit=9&contact_sheet=true" -o wood_sheet.jpg

# Inspect a single asset's metadata, dimensions, polycount, and ready-to-run bpy_snippet
curl -fsS "https://sunfield.dev/v1/assets/hdri_studio_small_08"

# Stage 1..24 assets directly into a live session (returns exact worker paths + bpy_snippet)
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/assets \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"asset_ids": ["hdri_studio_small_08", "mat_oak_veneer_01"]}'
```
Staged assets mount under `assets/<asset_id>/...` inside `SUNFIELD_FILES_DIR`, and each staged entry returns a copy-paste `bpy_snippet` using `load_hdri()`, `load_pbr()`, or `load_glb()`.

### Visual & Spatial Inspection (`POST /v1/sessions/{id}/inspect`)
```bash
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/inspect \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "views": ["camera", "top", "front", "back", "left", "right", "side", "iso_3q", "iso_3q_back"],
    "passes": ["rgb", "depth", "normals", "wireframe", "segmentation"],
    "resolution": [512, 512],
    "checks": ["bounds", "framing", "collisions", "floating"],
    "summary_only": false,
    "max_objects": 50,
    "engine": "eevee",
    "cycles_samples": 16
  }'
```
- Set `"summary_only": true` on scenes with 100+ objects to keep JSON compact (still returns `scene_bounds`, `collisions` with `penetration_depth`, and `floating_objects`).
- Set `"engine": "cycles", "cycles_samples": 16` for fast glass/__OPTICAL_SUNFIELDS_LOWER__/exposure previews.

### Named Undo Checkpoints & Branching (`checkpoints`, `fork`)
```bash
# Save & restore lightweight named checkpoints (<20ms in tmpfs)
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/checkpoints \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"name": "before_cloth_sim"}'
curl -fsS https://sunfield.dev/v1/sessions/$SESSION_ID/checkpoints -H "Authorization: Bearer $SUNFIELD_API_KEY"
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/checkpoints/before_cloth_sim/restore \
  -H "Authorization: Bearer $SUNFIELD_API_KEY"

# Fork into N independent parallel sessions (count <= 8)
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/fork \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"count": 2}'
```

### Cost Estimation & Async Cycles Render (`render/estimate`, `render`, `/v1/jobs/{id}`)
```bash
# 1. Estimate cost/time without committing
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/render/estimate \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"engine": "cycles", "samples": 256, "resolution": [1920, 1080], "frames": [1], "probe_samples": 8}'

# 2. Submit async render (recommended for any render > 30s)
curl -fsS -X POST https://sunfield.dev/v1/sessions/$SESSION_ID/render \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "engine": "cycles",
    "samples": 256,
    "resolution": [1920, 1080],
    "frames": [1],
    "aov_passes": ["rgb", "depth", "normals"],
    "use_denoising": true,
    "probe_samples": 8,
    "max_cost_usd": 0.50,
    "async": true
  }'
# -> {"job_id": "rnd_...", "status": "running", "poll_url": "/v1/jobs/rnd_..."}

# 3. Poll job status, live per-frame progress (`progress.completed_frames`, `eta_s`) & artifacts (or DELETE to cancel)
curl -fsS https://sunfield.dev/v1/jobs/$JOB_ID -H "Authorization: Bearer $SUNFIELD_API_KEY"
curl -fsS -X DELETE https://sunfield.dev/v1/jobs/$JOB_ID -H "Authorization: Bearer $SUNFIELD_API_KEY"

# 4. Download all rendered frames in one ZIP or assemble an H.264 MP4 directly on the control plane
curl -fsS "https://sunfield.dev/v1/jobs/$JOB_ID/archive.zip" -H "Authorization: Bearer $SUNFIELD_API_KEY" -o frames.zip
curl -fsS "https://sunfield.dev/v1/jobs/$JOB_ID/video.mp4?fps=24" -H "Authorization: Bearer $SUNFIELD_API_KEY" -o animation.mp4
```
- Multi-frame renders (`len(frames) > 1`) stream one frame at a time with live `progress` updates on `GET /v1/jobs/{id}` so partial frames are saved immediately and cancellation refunds all unrendered frames.
- Optional `?pass_name=rgb|depth|normals` filters `archive.zip`; optional `?fps=24&crf=18` configures `video.mp4` (H.264 `yuv420p` `+faststart`).

### Export Scene (`.blend` / `.glb`) & Artifacts
```bash
# Download packed .blend (native Blender multi-frame zstd-compressed file) or .glb
curl -fsS "https://sunfield.dev/v1/sessions/$SESSION_ID/export?format=blend" \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -o scene.blend
curl -fsS "https://sunfield.dev/v1/sessions/$SESSION_ID/export?format=glb" \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -o scene.glb
# Note: Blender writes .blend files as multi-frame zstd streams. Open scene.blend directly in Blender,
# or decompress all frames with `zstd -d` / a streaming decompressor if inspecting raw bytes.

# List & download artifacts (filter by session_id or job_id)
curl -fsS "https://sunfield.dev/v1/artifacts?session_id=$SESSION_ID" -H "Authorization: Bearer $SUNFIELD_API_KEY"
curl -fsS https://sunfield.dev/v1/artifacts/$ARTIFACT_ID -H "Authorization: Bearer $SUNFIELD_API_KEY" -o output.png
```

### Submit & Review Agent Feedback (`POST /v1/feedback`, `GET /v1/feedback`)
After finishing a real job or hitting any API/Blender friction, please send a short structured report so we can fix it immediately:
```bash
curl -fsS -X POST https://sunfield.dev/v1/feedback \
  -H "Authorization: Bearer $SUNFIELD_API_KEY" -H "Content-Type: application/json" \
  -d '{"category": "bug", "session_id": "$SESSION_ID", "message": "What worked, what broke, probe accuracy, missing endpoints/assets..."}'

# Review your previously submitted feedback
curl -fsS https://sunfield.dev/v1/feedback -H "Authorization: Bearer $SUNFIELD_API_KEY"
```

---

## Blender `bpy` Best Practices & Gotchas

- **Color management:** Set `scene.view_settings.view_transform = 'AgX'` and `scene.view_settings.look = 'AgX - Medium High Contrast'` (note: enumerating `view_transform` enum items in headless factory mode can look sparse, but assigning `'AgX'` directly works cleanly).
- **Glass / __OPTICAL_SUNFIELDS_LOWER__ fireflies:** Prefer `scene.cycles.sample_clamp_indirect = 10.0`, `scene.cycles.use_adaptive_sampling = True`, `scene.cycles.adaptive_threshold = 0.01`, and `use_denoising: true` (OptiX denoiser) instead of cranking samples to 4096. For heavy refractive/glass scenes, prefer async `POST /v1/sessions/{id}/render` with `"async": true` rather than synchronous `inspect(engine="cycles")`.
- **Headless primitive transforms:** In headless Blender 4.5, `bpy.ops.mesh.primitive_*` can ignore the `rotation=` keyword argument; always assign `obj.rotation_euler` (or `obj.rotation_quaternion`) directly after creating the object.
- **Blender 4.5 / 5.x `Principled BSDF` sockets:** Use `'Transmission Weight'`, `'Coat Weight'`, `'Specular IOR Level'` (guard with `if name in bsdf.inputs:`).
- **Zero outbound network in sandboxes:** Never fetch URLs from inside `exec()`.
- **HTTP status codes:** `401` invalid key · `402` insufficient credits · `404` unknown session/job/artifact · `503` no GPU workers connected.
