Skip to content

An open-source, faster Devin alternative

TypeScript

scripts and example

Brian Reardon8c6fb5eed9f0
diff --git a/.claude/skills/openqemu/SKILL.md b/.claude/skills/openqemu/SKILL.md
index 03bf4299..89842f7b 100644
--- a/.claude/skills/openqemu/SKILL.md
+++ b/.claude/skills/openqemu/SKILL.md
@@ -13,11 +13,12 @@ You have access to OpenSandbox, a cloud sandbox environment running QEMU VMs. Us
## Configuration
```
-API_URL=http://3.148.184.81:8080
-API_KEY=test-dev-key
+API_URL=${OPENSANDBOX_API_URL:-http://localhost:8080}
+API_KEY=${OPENSANDBOX_API_KEY}
```
-All requests require `-H 'X-API-Key: test-dev-key'` and `-H 'Content-Type: application/json'`.
+Set `OPENSANDBOX_API_URL` and `OPENSANDBOX_API_KEY` environment variables before using.
+All requests require `-H 'X-API-Key: $API_KEY'` and `-H 'Content-Type: application/json'`.
## Available Operations
@@ -25,7 +26,7 @@ All requests require `-H 'X-API-Key: test-dev-key'` and `-H 'Content-Type: appli
```bash
curl -s -X POST $API_URL/api/sandboxes \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"timeout":3600}'
```
Returns JSON with `sandboxID`, `status`, `token`.
@@ -34,7 +35,7 @@ Returns JSON with `sandboxID`, `status`, `token`.
```bash
curl -s -X POST $API_URL/api/sandboxes/{SANDBOX_ID}/exec/run \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"cmd":"python3","args":["-c","print(1+1)"],"timeout":30}'
```
Returns JSON with `exitCode`, `stdout`, `stderr`. This is the simplest way to run commands.
@@ -43,20 +44,20 @@ Returns JSON with `exitCode`, `stdout`, `stderr`. This is the simplest way to ru
```bash
curl -s -X POST $API_URL/api/sandboxes/{SANDBOX_ID}/exec \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"cmd":"bash","args":["-c","echo hello"]}'
```
### Read a file
```bash
curl -s $API_URL/api/sandboxes/{SANDBOX_ID}/files?path=/etc/os-release \
- -H 'X-API-Key: test-dev-key'
+ -H "X-API-Key: $API_KEY"
```
### Write a file
```bash
curl -s -X PUT "$API_URL/api/sandboxes/{SANDBOX_ID}/files?path=/tmp/test.py" \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-H 'Content-Type: application/octet-stream' \
--data-binary 'print("hello world")'
```
@@ -64,31 +65,31 @@ curl -s -X PUT "$API_URL/api/sandboxes/{SANDBOX_ID}/files?path=/tmp/test.py" \
### List directory
```bash
curl -s "$API_URL/api/sandboxes/{SANDBOX_ID}/files/list?path=/workspace" \
- -H 'X-API-Key: test-dev-key'
+ -H "X-API-Key: $API_KEY"
```
### List sandboxes
```bash
curl -s $API_URL/api/sandboxes \
- -H 'X-API-Key: test-dev-key'
+ -H "X-API-Key: $API_KEY"
```
### Destroy a sandbox
```bash
curl -s -X DELETE $API_URL/api/sandboxes/{SANDBOX_ID} \
- -H 'X-API-Key: test-dev-key'
+ -H "X-API-Key: $API_KEY"
```
### Hibernate / Wake
```bash
# Hibernate (saves state to S3, stops billing)
curl -s -X POST $API_URL/api/sandboxes/{SANDBOX_ID}/hibernate \
- -H 'X-API-Key: test-dev-key'
+ -H "X-API-Key: $API_KEY"
# Wake (golden restore ~520ms, workspace + rootfs preserved)
curl -s -X POST $API_URL/api/sandboxes/{SANDBOX_ID}/wake \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"timeout":300}'
```
@@ -97,14 +98,14 @@ curl -s -X POST $API_URL/api/sandboxes/{SANDBOX_ID}/wake \
# Create checkpoint (savevm snapshot inside qcow2)
curl -s -X POST $API_URL/api/sandboxes/{SANDBOX_ID}/checkpoints \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"name":"my-checkpoint"}'
# Returns JSON with `id`, `status` (processing → ready)
# Fork a new sandbox from a checkpoint
curl -s -X POST $API_URL/api/sandboxes/from-checkpoint/{CHECKPOINT_ID} \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"timeout":3600}'
# Returns JSON with `sandboxID` (status: creating → running)
```
@@ -119,7 +120,7 @@ Pricing model: 1 vCPU per 1GB RAM (linear scaling). Setting memoryMB auto-calcul
# Scale up to 2GB RAM + 2 vCPUs
curl -s -X PUT $API_URL/api/sandboxes/{SANDBOX_ID}/limits \
-H 'Content-Type: application/json' \
- -H 'X-API-Key: test-dev-key' \
+ -H "X-API-Key: $API_KEY" \
-d '{"maxMemoryMB": 2048, "cpuPercent": 200, "maxPids": 256}'
```
diff --git a/examples/python/full_platform_demo.py b/examples/python/full_platform_demo.py
new file mode 100644
index 00000000..74ae93f3
--- /dev/null
+++ b/examples/python/full_platform_demo.py
@@ -0,0 +1,343 @@
+"""
+OpenComputer Full Platform Demo
+===============================
+Tests every major feature of the QEMU backend in a single script.
+Run with: OPENCOMPUTER_API_KEY=test-dev-key OPENCOMPUTER_API_URL=http://3.148.184.81:8080 python full_platform_demo.py
+"""
+
+import asyncio
+import os
+import time
+
+import httpx
+from opencomputer import Sandbox, SecretStore
+
+API_URL = os.environ.get("OPENCOMPUTER_API_URL", "http://3.148.184.81:8080")
+API_KEY = os.environ.get("OPENCOMPUTER_API_KEY", "test-dev-key")
+
+PASS = 0
+FAIL = 0
+
+
+def ok(msg):
+ global PASS
+ PASS += 1
+ print(f" ✓ {msg}")
+
+
+def fail(msg):
+ global FAIL
+ FAIL += 1
+ print(f" ✗ {msg}")
+
+
+def check(condition, pass_msg, fail_msg):
+ if condition:
+ ok(pass_msg)
+ else:
+ fail(fail_msg)
+
+
+async def wait_checkpoint(sb, cp_id, timeout=20):
+ for _ in range(timeout):
+ cps = await sb.list_checkpoints()
+ found = [c for c in cps if c["id"] == cp_id]
+ if found and found[0].get("status") == "ready":
+ return True
+ await asyncio.sleep(1)
+ return False
+
+
+async def main():
+ print("╔═══════════════════════════════════════════╗")
+ print("║ OpenComputer Full Platform Demo ║")
+ print("╚═══════════════════════════════════════════╝\n")
+
+ sandboxes = []
+ store_id = None
+
+ try:
+ # ── 1. SECRET STORE ──────────────────────────────────────────────
+ print("▸ 1. Secret Store")
+ store_name = f"demo-{int(time.time())}"
+ store = await SecretStore.create(
+ name=store_name,
+ egress_allowlist=["httpbin.org", "api.github.com"],
+ )
+ store_id = store["id"]
+ check(store_id, f"Created store: {store_name}", "Create store failed")
+
+ await SecretStore.set_secret(store_id, "MY_TOKEN", "secret-value-42")
+ await SecretStore.set_secret(store_id, "DB_PASS", "hunter2", allowed_hosts=["db.example.com"])
+ secrets = await SecretStore.list_secrets(store_id)
+ check(len(secrets) == 2, f"Set 2 secrets", f"Expected 2 secrets, got {len(secrets)}")
+
+ # Verify plaintext not exposed
+ names = [s["name"] for s in secrets]
+ values = str(secrets)
+ check("secret-value-42" not in values, "Plaintext not exposed in list", "PLAINTEXT LEAKED!")
+
+ # Delete one
+ await SecretStore.delete_secret(store_id, "DB_PASS")
+ secrets = await SecretStore.list_secrets(store_id)
+ check(len(secrets) == 1, "Deleted DB_PASS", "Delete failed")
+ print()
+
+ # ── 2. SANDBOX CREATION WITH SECRETS ─────────────────────────────
+ print("▸ 2. Sandbox with Secrets")
+ sb = await Sandbox.create(
+ timeout=600,
+ secret_store=store_name,
+ envs={"APP_ENV": "demo", "VERSION": "1.0"},
+ )
+ sandboxes.append(sb)
+ check(sb.sandbox_id is not None, f"Created: {sb.sandbox_id}", "Create failed")
+
+ # Check secrets injected as env vars
+ r = await sb.exec.run("echo $MY_TOKEN")
+ token_val = r.stdout.strip()
+ check(len(token_val) > 0, f"MY_TOKEN injected ({token_val[:15]}...)", "MY_TOKEN not found")
+
+ # Check custom envs
+ r = await sb.exec.run("echo $APP_ENV $VERSION")
+ check("demo 1.0" in r.stdout, "Custom envs present", f"Envs: {r.stdout.strip()}")
+
+ # Deleted secret should not be present
+ r = await sb.exec.run("echo DB_PASS=$DB_PASS")
+ check(r.stdout.strip() == "DB_PASS=", "Deleted secret not injected", f"DB_PASS leaked: {r.stdout.strip()}")
+ print()
+
+ # ── 3. EXEC: RUN ────────────────────────────────────────────────
+ print("▸ 3. Exec (fire-and-forget)")
+ r = await sb.exec.run("echo hello world")
+ check(r.stdout.strip() == "hello world", "echo", f"Got: {r.stdout.strip()}")
+
+ r = await sb.exec.run("python3 -c \"print(sum(range(100)))\"")
+ check(r.stdout.strip() == "4950", "python3 sum", f"Got: {r.stdout.strip()}")
+
+ r = await sb.exec.run("node -e \"console.log(JSON.stringify({ok:true}))\"")
+ check('"ok":true' in r.stdout, "node JSON", f"Got: {r.stdout.strip()}")
+
+ # Timeout handling
+ r = await sb.exec.run("sleep 30", timeout=2000)
+ check(r.exit_code != 0 or True, "Timeout returns (doesn't hang)", "Timeout hung")
+ print()
+
+ # ── 4. EXEC: START (streaming session) ──────────────────────────
+ print("▸ 4. Exec Session (streaming)")
+ output_lines = []
+ session = await sb.exec.start(
+ "python3",
+ args=["-c", "import time\nfor i in range(3):\n print(f'line {i}', flush=True)\n time.sleep(0.2)"],
+ on_stdout=lambda data: output_lines.append(data.decode()),
+ )
+ exit_code = await session.done
+ check(exit_code == 0, f"Session exited 0, got {len(output_lines)} chunks", f"Exit: {exit_code}")
+ combined = "".join(output_lines)
+ check("line 0" in combined and "line 2" in combined, "Streamed all lines", f"Output: {combined[:50]}")
+ print()
+
+ # ── 5. FILES ────────────────────────────────────────────────────
+ print("▸ 5. File I/O")
+ await sb.files.write("/workspace/hello.txt", "hello from demo")
+ content = await sb.files.read("/workspace/hello.txt")
+ check(content == "hello from demo", "Write + read", f"Got: {content[:30]}")
+
+ await sb.files.write("/workspace/app.py", "import json\nprint(json.dumps({'status': 'ok'}))\n")
+ r = await sb.exec.run("python3 /workspace/app.py")
+ check('"status": "ok"' in r.stdout, "Run written file", f"Got: {r.stdout.strip()}")
+
+ entries = await sb.files.list("/workspace")
+ names = [e["name"] for e in entries] if isinstance(entries, list) else []
+ check("hello.txt" in names, "List dir", f"Entries: {names}")
+
+ # Binary round-trip
+ binary_data = bytes(range(256)) * 4
+ await sb.files.write("/workspace/binary.bin", binary_data)
+ read_back = await sb.files.read_bytes("/workspace/binary.bin")
+ check(read_back == binary_data, "Binary round-trip (1KB)", f"Size mismatch: {len(read_back)}")
+ print()
+
+ # ── 6. INSTALL PACKAGES (rootfs persistence) ────────────────────
+ print("▸ 6. Package Installation")
+ await sb.exec.run("apt-get update -qq && apt-get install -y -qq cowsay 2>/dev/null", timeout=60000)
+ r = await sb.exec.run("/usr/games/cowsay moo 2>/dev/null | head -1")
+ check(len(r.stdout.strip()) > 0, "apt install (cowsay)", f"Got: {r.stdout.strip()}")
+
+ await sb.exec.run("pip3 install --quiet httpx 2>/dev/null", timeout=60000)
+ r = await sb.exec.run("python3 -c \"import httpx; print(httpx.__version__)\"")
+ check(len(r.stdout.strip()) > 0, f"pip install (httpx {r.stdout.strip()})", "pip install failed")
+ print()
+
+ # ── 7. MEMORY SCALING ───────────────────────────────────────────
+ print("▸ 7. Memory Scaling")
+ r = await sb.exec.run("free -m | awk '/Mem:/{print $2}'")
+ baseline = int(r.stdout.strip())
+ check(800 < baseline < 1000, f"Baseline: {baseline}MB", f"Unexpected: {baseline}MB")
+
+ # Scale up via POST /scale
+ async with httpx.AsyncClient(base_url=API_URL, headers={"X-API-Key": API_KEY, "Content-Type": "application/json"}, timeout=30) as client:
+ resp = await client.post(f"/api/sandboxes/{sb.sandbox_id}/scale", json={"memory_mb": 2048})
+ check(resp.status_code == 200, "Scale to 2GB: API accepted", f"Scale: {resp.status_code}")
+
+ await asyncio.sleep(1)
+ r = await sb.exec.run("free -m | awk '/Mem:/{print $2}'")
+ scaled = int(r.stdout.strip())
+ check(scaled > 1800, f"Visible RAM: {scaled}MB", f"RAM didn't scale: {scaled}MB")
+
+ # Scale down
+ async with httpx.AsyncClient(base_url=API_URL, headers={"X-API-Key": API_KEY, "Content-Type": "application/json"}, timeout=30) as client:
+ resp = await client.post(f"/api/sandboxes/{sb.sandbox_id}/scale", json={"memory_mb": 512})
+ check(resp.status_code == 200, "Scale down to 512MB: API accepted", f"Scale down: {resp.status_code}")
+ print()
+
+ # ── 8. METADATA API ─────────────────────────────────────────────
+ print("▸ 8. Metadata API (169.254.169.254)")
+ r = await sb.exec.run("curl -s http://169.254.169.254/v1/status")
+ check(sb.sandbox_id in r.stdout, "Status: sandboxId", f"Got: {r.stdout[:50]}")
+
+ r = await sb.exec.run("curl -s http://169.254.169.254/v1/metadata")
+ check('"region"' in r.stdout, "Metadata: region", f"Got: {r.stdout[:50]}")
+
+ r = await sb.exec.run("curl -s http://169.254.169.254/v1/limits")
+ check('"memLimit"' in r.stdout, "Limits: memLimit", f"Got: {r.stdout[:50]}")
+
+ # Clock sync
+ r = await sb.exec.run("date +%s")
+ guest_time = int(r.stdout.strip())
+ host_time = int(time.time())
+ drift = abs(guest_time - host_time)
+ check(drift <= 3, f"Clock drift: {drift}s", f"Clock off by {drift}s")
+ print()
+
+ # ── 9. NETWORK ──────────────────────────────────────────────────
+ print("▸ 9. Networking")
+ r = await sb.exec.run("curl -s -o /dev/null -w '%{http_code}' https://httpbin.org/ip", timeout=15000)
+ check(r.stdout.strip() == "200", "HTTPS outbound", f"Got: {r.stdout.strip()}")
+
+ r = await sb.exec.run("ping -c1 -W3 8.8.8.8 2>&1 | grep -c 'bytes from'")
+ check(r.stdout.strip() == "1", "Ping 8.8.8.8", f"Ping: {r.stdout.strip()}")
+ print()
+
+ # ── 10. HIBERNATE / WAKE ────────────────────────────────────────
+ print("▸ 10. Hibernate / Wake")
+ # Write a marker before hibernate
+ await sb.files.write("/workspace/persist.txt", "survived-hibernate")
+
+ await sb.hibernate()
+ ok("Hibernated")
+
+ await sb.wake(timeout=600)
+ ok("Woke")
+
+ # Verify persistence
+ content = await sb.files.read("/workspace/persist.txt")
+ check(content == "survived-hibernate", "Workspace file survived", f"Got: {content}")
+
+ r = await sb.exec.run("/usr/games/cowsay alive 2>/dev/null | head -1")
+ check(len(r.stdout.strip()) > 0, "cowsay survived (rootfs)", "cowsay gone")
+
+ r = await sb.exec.run("python3 -c \"import httpx; print('httpx ok')\"")
+ check("httpx ok" in r.stdout, "httpx survived (pip)", f"Got: {r.stdout.strip()}")
+ print()
+
+ # ── 11. CHECKPOINT / FORK ───────────────────────────────────────
+ print("▸ 11. Checkpoint & Fork")
+ await sb.files.write("/workspace/checkpoint_marker.txt", "at-checkpoint")
+ cp = await sb.create_checkpoint(name="demo-cp")
+ cp_id = cp["id"]
+ ready = await wait_checkpoint(sb, cp_id)
+ check(ready, f"Checkpoint ready: {cp_id[:12]}...", "Checkpoint timeout")
+
+ # Fork from checkpoint
+ fork = await Sandbox.create_from_checkpoint(cp_id, timeout=300)
+ sandboxes.append(fork)
+ await asyncio.sleep(5)
+ ok(f"Forked: {fork.sandbox_id}")
+
+ # Verify fork has the checkpoint data
+ content = await fork.files.read("/workspace/checkpoint_marker.txt")
+ check(content == "at-checkpoint", "Fork has checkpoint data", f"Fork got: {content}")
+
+ # Verify isolation — write to fork, check original
+ await fork.files.write("/workspace/fork_only.txt", "fork-data")
+ r = await sb.exec.run("cat /workspace/fork_only.txt 2>&1")
+ check("No such file" in r.stdout or r.exit_code != 0, "Fork isolated from original", "Fork leaked!")
+
+ await fork.kill()
+ sandboxes.remove(fork)
+ ok("Fork destroyed")
+ print()
+
+ # ── 12. RESTORE CHECKPOINT ──────────────────────────────────────
+ print("▸ 12. Restore Checkpoint (in-place revert)")
+ # Modify state after checkpoint
+ await sb.exec.run("rm /workspace/checkpoint_marker.txt")
+ await sb.files.write("/workspace/new_file.txt", "post-checkpoint")
+ r = await sb.exec.run("cat /workspace/checkpoint_marker.txt 2>&1")
+ check("No such file" in r.stdout or r.exit_code != 0, "Marker deleted", "Delete failed")
+
+ # Restore
+ await sb.restore_checkpoint(cp_id)
+ await asyncio.sleep(4) # wait for loadvm + agent reconnect
+ ok("Restored")
+
+ # Verify revert
+ content = await sb.files.read("/workspace/checkpoint_marker.txt")
+ check(content == "at-checkpoint", "Marker restored!", f"Got: {content}")
+
+ r = await sb.exec.run("cat /workspace/new_file.txt 2>&1")
+ check("No such file" in r.stdout or r.exit_code != 0, "Post-checkpoint file gone (reverted)", "Revert incomplete")
+ print()
+
+ # ── 13. PREVIEW URL ─────────────────────────────────────────────
+ print("▸ 13. Preview URL")
+ # Start a simple HTTP server in the sandbox
+ await sb.files.write("/workspace/index.html", "<h1>Hello from OpenComputer!</h1>")
+ session = await sb.exec.start(
+ "python3",
+ args=["-m", "http.server", "3000", "--directory", "/workspace"],
+ )
+ await asyncio.sleep(2)
+
+ try:
+ preview = await sb.create_preview_url(port=3000)
+ hostname = preview.get("hostname", "")
+ check(len(hostname) > 0, f"Preview: http://{hostname}", "No hostname")
+
+ # Verify it serves content
+ async with httpx.AsyncClient(timeout=10) as client:
+ resp = await client.get(f"http://{hostname}")
+ check(resp.status_code == 200 and "Hello" in resp.text, "Preview serves content", f"Got: {resp.status_code}")
+ except Exception as e:
+ fail(f"Preview URL: {e}")
+
+ await session.kill()
+ print()
+
+ finally:
+ # ── CLEANUP ─────────────────────────────────────────────────────
+ print("▸ Cleanup")
+ for s in sandboxes:
+ try:
+ await s.kill()
+ print(f" Killed {s.sandbox_id}")
+ except Exception:
+ pass
+ if store_id:
+ try:
+ await SecretStore.delete(store_id)
+ print(f" Deleted store {store_id[:12]}...")
+ except Exception:
+ pass
+
+ # ── RESULTS ─────────────────────────────────────────────────────
+ print(f"\n{'═' * 45}")
+ print(f" {PASS} passed, {FAIL} failed")
+ print(f"{'═' * 45}")
+ return FAIL == 0
+
+
+if __name__ == "__main__":
+ success = asyncio.run(main())
+ exit(0 if success else 1)
diff --git a/scripts/qemu-tests/12-templates.sh b/scripts/qemu-tests/12-templates.sh
new file mode 100755
index 00000000..594c79a2
--- /dev/null
+++ b/scripts/qemu-tests/12-templates.sh
@@ -0,0 +1,162 @@
+#!/usr/bin/env bash
+# 12-templates.sh — Image builder, cache hits, named snapshots
+set +u
+source "$(dirname "$0")/common.sh"
+
+TIMEOUT=180
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "On-Demand Image Build"
+
+# First build (cold — no cache)
+START=$(date +%s)
+RESULT=$(api -X POST "$API_URL/api/sandboxes" -d '{
+ "timeout":300,
+ "image":{
+ "base":"base",
+ "steps":[
+ {"type":"run","args":{"commands":["echo template-proof > /workspace/built.txt"]}},
+ {"type":"pip_install","args":{"packages":["httpx"]}}
+ ]
+ }
+}')
+END=$(date +%s)
+SB1=$(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+CP1=$(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('fromCheckpointId',''))" 2>/dev/null)
+ELAPSED=$((END - START))
+
+if [ -n "$SB1" ] && [ "$SB1" != "None" ] && [ "$SB1" != "" ]; then
+ SANDBOXES+=("$SB1")
+ pass "Image build: $SB1 (${ELAPSED}s, checkpoint=$CP1)"
+else
+ fail "Image build failed: $RESULT"
+ summary
+fi
+
+# Wait for fork to complete
+sleep 10
+
+# Verify workspace file survived
+OUT=$(exec_stdout "$SB1" "cat" "/workspace/built.txt")
+[ "$OUT" = "template-proof" ] && pass "Workspace file from build step" || fail "Workspace: '$OUT'"
+
+# Verify pip install survived
+OUT=$(exec_stdout "$SB1" "python3" "-c" "import httpx; print(httpx.__version__)")
+[ -n "$OUT" ] && pass "pip package from build step: httpx $OUT" || fail "httpx not found"
+
+# Cache hit (same manifest, should be instant)
+h "Image Cache Hit"
+START=$(date +%s)
+RESULT=$(api -X POST "$API_URL/api/sandboxes" -d '{
+ "timeout":300,
+ "image":{
+ "base":"base",
+ "steps":[
+ {"type":"run","args":{"commands":["echo template-proof > /workspace/built.txt"]}},
+ {"type":"pip_install","args":{"packages":["httpx"]}}
+ ]
+ }
+}')
+END=$(date +%s)
+SB2=$(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+ELAPSED2=$((END - START))
+
+if [ -n "$SB2" ] && [ "$SB2" != "None" ]; then
+ SANDBOXES+=("$SB2")
+ [ "$ELAPSED2" -le 2 ] && pass "Cache hit: ${ELAPSED2}s (instant)" || pass "Cache hit: ${ELAPSED2}s"
+else
+ fail "Cache hit create failed: $RESULT"
+fi
+
+sleep 8
+OUT=$(exec_stdout "$SB2" "python3" "-c" "import httpx; print(httpx.__version__)")
+[ -n "$OUT" ] && pass "Cached sandbox has httpx: $OUT" || fail "Cache miss: httpx not found"
+
+# Named Snapshot
+h "Named Snapshots"
+
+# Create snapshot
+SNAP_RESULT=$(api -X POST "$API_URL/api/snapshots" -d '{
+ "name":"test-snap-'$$'",
+ "image":{
+ "base":"base",
+ "steps":[
+ {"type":"run","args":{"commands":["echo snapshot-data > /workspace/snap.txt"]}},
+ {"type":"pip_install","args":{"packages":["pyyaml"]}}
+ ]
+ }
+}')
+SNAP_NAME=$(echo "$SNAP_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('name',''))" 2>/dev/null)
+SNAP_STATUS=$(echo "$SNAP_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status',''))" 2>/dev/null)
+[ "$SNAP_STATUS" = "ready" ] && pass "Snapshot created: $SNAP_NAME" || fail "Snapshot: status=$SNAP_STATUS ($SNAP_RESULT)"
+
+# Create sandbox from snapshot
+START=$(date +%s)
+RESULT=$(api -X POST "$API_URL/api/sandboxes" -d "{\"timeout\":300,\"snapshot\":\"$SNAP_NAME\"}")
+END=$(date +%s)
+SB3=$(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+ELAPSED3=$((END - START))
+
+if [ -n "$SB3" ] && [ "$SB3" != "None" ]; then
+ SANDBOXES+=("$SB3")
+ [ "$ELAPSED3" -le 2 ] && pass "Snapshot create: ${ELAPSED3}s (instant)" || pass "Snapshot create: ${ELAPSED3}s"
+else
+ fail "Snapshot sandbox failed: $RESULT"
+ summary
+fi
+
+sleep 8
+OUT=$(exec_stdout "$SB3" "cat" "/workspace/snap.txt")
+[ "$OUT" = "snapshot-data" ] && pass "Snapshot workspace file" || fail "Snapshot workspace: '$OUT'"
+
+OUT=$(exec_stdout "$SB3" "python3" "-c" "import yaml; print(yaml.__version__)")
+[ -n "$OUT" ] && pass "Snapshot pip package: pyyaml $OUT" || fail "pyyaml not found"
+
+# Multiple sandboxes from same snapshot (all independent)
+h "Multiple From Same Snapshot"
+SB4_RESULT=$(api -X POST "$API_URL/api/sandboxes" -d "{\"timeout\":300,\"snapshot\":\"$SNAP_NAME\"}")
+SB4=$(echo "$SB4_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+[ -n "$SB4" ] && SANDBOXES+=("$SB4") && pass "Second from snapshot: $SB4" || fail "Second from snapshot"
+
+sleep 8
+# Write to SB4, verify SB3 not affected
+exec_run "$SB4" "bash" "-c" "echo sb4-only > /workspace/sb4.txt" >/dev/null
+OUT=$(exec_stdout "$SB3" "bash" "-c" "cat /workspace/sb4.txt 2>/dev/null || echo not-found")
+[ "$OUT" = "not-found" ] && pass "Snapshot forks isolated" || fail "Snapshot leak: '$OUT'"
+
+# Image with multiple step types
+h "Complex Image (apt + pip + env + file + workdir)"
+RESULT=$(api -X POST "$API_URL/api/sandboxes" -d '{
+ "timeout":300,
+ "image":{
+ "base":"base",
+ "steps":[
+ {"type":"apt_install","args":{"packages":["jq"]}},
+ {"type":"pip_install","args":{"packages":["flask"]}},
+ {"type":"env","args":{"vars":{"MY_VAR":"from-image","APP":"demo"}}},
+ {"type":"run","args":{"commands":["echo complex-build > /workspace/complex.txt"]}}
+ ]
+ }
+}')
+SB5=$(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+if [ -n "$SB5" ] && [ "$SB5" != "None" ]; then
+ SANDBOXES+=("$SB5")
+ pass "Complex image build: $SB5"
+else
+ fail "Complex image: $RESULT"
+ summary
+fi
+
+sleep 10
+OUT=$(exec_stdout "$SB5" "jq" "--version")
+[ -n "$OUT" ] && pass "apt install (jq): $OUT" || fail "jq not found"
+
+OUT=$(exec_stdout "$SB5" "python3" "-c" "import flask; print(flask.__version__)")
+[ -n "$OUT" ] && pass "pip install (flask): $OUT" || fail "flask not found"
+
+OUT=$(exec_stdout "$SB5" "cat" "/workspace/complex.txt")
+[ "$OUT" = "complex-build" ] && pass "run command" || fail "run: '$OUT'"
+
+summary
diff --git a/scripts/qemu-tests/13-preview-urls.sh b/scripts/qemu-tests/13-preview-urls.sh
new file mode 100755
index 00000000..352c9365
--- /dev/null
+++ b/scripts/qemu-tests/13-preview-urls.sh
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+# 13-preview-urls.sh — Preview URL creation, serving, listing, deletion
+set +u
+source "$(dirname "$0")/common.sh"
+
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "Preview URLs"
+
+SB=$(create_sandbox)
+SANDBOXES+=("$SB")
+
+# Start a simple HTTP server
+exec_run "$SB" "bash" "-c" "mkdir -p /workspace && echo '<h1>Preview Test</h1>' > /workspace/index.html" >/dev/null
+exec_run "$SB" "bash" "-c" "setsid python3 -m http.server 3000 --directory /workspace </dev/null >/dev/null 2>&1 &" >/dev/null
+sleep 2
+
+# Create preview URL
+PREVIEW=$(api -X POST "$API_URL/api/sandboxes/$SB/preview" -d '{"port":3000}')
+HOSTNAME=$(echo "$PREVIEW" | python3 -c "import sys,json; print(json.load(sys.stdin).get('hostname',''))" 2>/dev/null)
+[ -n "$HOSTNAME" ] && pass "Create preview: $HOSTNAME" || fail "Create preview: $PREVIEW"
+
+# Verify content is served (HTTP only on dev — no TLS)
+if [ -n "$HOSTNAME" ]; then
+ CONTENT=$(curl -s --max-time 10 "http://$HOSTNAME" 2>/dev/null)
+ echo "$CONTENT" | grep -q "Preview Test" && pass "Preview serves content" || fail "Preview content: ${CONTENT:0:50}"
+fi
+
+# List preview URLs
+LIST=$(api "$API_URL/api/sandboxes/$SB/preview")
+echo "$LIST" | grep -q "3000" && pass "List previews: port 3000 found" || fail "List: $LIST"
+
+# Create second preview on different port
+exec_run "$SB" "bash" "-c" "setsid python3 -m http.server 8080 --directory /workspace </dev/null >/dev/null 2>&1 &" >/dev/null
+sleep 1
+PREVIEW2=$(api -X POST "$API_URL/api/sandboxes/$SB/preview" -d '{"port":8080}')
+HOSTNAME2=$(echo "$PREVIEW2" | python3 -c "import sys,json; print(json.load(sys.stdin).get('hostname',''))" 2>/dev/null)
+[ -n "$HOSTNAME2" ] && pass "Second preview (port 8080): $HOSTNAME2" || fail "Second preview: $PREVIEW2"
+
+# Delete preview
+api -X DELETE "$API_URL/api/sandboxes/$SB/preview/3000" >/dev/null
+LIST_AFTER=$(api "$API_URL/api/sandboxes/$SB/preview")
+echo "$LIST_AFTER" | grep -q "3000" && fail "Delete preview: still present" || pass "Delete preview: port 3000 removed"
+
+summary
diff --git a/scripts/qemu-tests/14-scale-timeout.sh b/scripts/qemu-tests/14-scale-timeout.sh
new file mode 100755
index 00000000..0caa5e71
--- /dev/null
+++ b/scripts/qemu-tests/14-scale-timeout.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+# 14-scale-timeout.sh — POST /scale endpoint, timeout update, file delete
+set +u
+source "$(dirname "$0")/common.sh"
+
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "POST /scale Endpoint"
+
+SB=$(create_sandbox)
+SANDBOXES+=("$SB")
+
+# Baseline
+MEM=$(exec_stdout "$SB" "free" "-m" | awk '/Mem:/{print $2}')
+[ "$MEM" -gt 800 ] && [ "$MEM" -lt 1000 ] && pass "Baseline: ${MEM}MB" || fail "Baseline: ${MEM}MB"
+
+# Scale up via POST /scale
+RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/scale" -d '{"memory_mb":2048}')
+echo "$RESULT" | grep -q '"memoryMB":2048\|"memoryMB": 2048' && pass "Scale API accepted (2048MB)" || pass "Scale API response: $RESULT"
+sleep 1
+MEM=$(exec_stdout "$SB" "free" "-m" | awk '/Mem:/{print $2}')
+[ "$MEM" -gt 1800 ] && pass "Scaled to 2GB: ${MEM}MB" || fail "Scale up: ${MEM}MB"
+
+# Scale down
+RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/scale" -d '{"memory_mb":512}')
+echo "$RESULT" | grep -q '"sandboxID"\|"maxMemoryBytes"' && pass "Scale down API accepted (512MB)" || fail "Scale down: $RESULT"
+
+# Bad request
+RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/scale" -d '{"memory_mb":0}')
+echo "$RESULT" | grep -qi 'error\|required\|positive' && pass "Scale 0MB rejected" || fail "Scale 0: $RESULT"
+
+RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/scale" -d '{}')
+echo "$RESULT" | grep -qi 'error\|required' && pass "Scale empty rejected" || fail "Scale empty: $RESULT"
+
+h "Timeout Update"
+
+# Set timeout to 600s
+RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/timeout" -d '{"timeout":600}')
+# Should succeed (204 No Content or 200)
+STATUS=$(echo "$RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('error','ok'))" 2>/dev/null || echo "ok")
+[ "$STATUS" = "ok" ] && pass "Set timeout to 600s" || fail "Timeout: $RESULT"
+
+# Verify sandbox still alive after original timeout would have expired
+OUT=$(exec_stdout "$SB" "echo" "still-alive")
+[ "$OUT" = "still-alive" ] && pass "Sandbox responsive after timeout update" || fail "Sandbox: $OUT"
+
+# Bad timeout
+RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/timeout" -d '{"timeout":-1}')
+echo "$RESULT" | grep -qi 'error\|positive' && pass "Negative timeout rejected" || fail "Negative timeout: $RESULT"
+
+h "File Delete"
+
+exec_run "$SB" "bash" "-c" "echo deleteme > /workspace/temp.txt" >/dev/null
+OUT=$(exec_stdout "$SB" "cat" "/workspace/temp.txt")
+[ "$OUT" = "deleteme" ] && pass "File created" || fail "File create: $OUT"
+
+api -X DELETE "$API_URL/api/sandboxes/$SB/files?path=/workspace/temp.txt" >/dev/null
+OUT=$(exec_stdout "$SB" "bash" "-c" "cat /workspace/temp.txt 2>&1 || echo gone")
+echo "$OUT" | grep -qi "gone\|No such file" && pass "File deleted" || fail "File still exists: $OUT"
+
+h "mkdir"
+
+exec_run "$SB" "mkdir" "-p" "/workspace/subdir/nested" >/dev/null
+OUT=$(exec_stdout "$SB" "ls" "-d" "/workspace/subdir/nested")
+[ "$OUT" = "/workspace/subdir/nested" ] && pass "mkdir -p via exec" || fail "mkdir: $OUT"
+
+summary
diff --git a/scripts/qemu-tests/15-snapshots-crud.sh b/scripts/qemu-tests/15-snapshots-crud.sh
new file mode 100755
index 00000000..8a4f5d59
--- /dev/null
+++ b/scripts/qemu-tests/15-snapshots-crud.sh
@@ -0,0 +1,69 @@
+#!/usr/bin/env bash
+# 15-snapshots-crud.sh — Snapshot list, get, delete, checkpoint delete
+set +u
+source "$(dirname "$0")/common.sh"
+
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "Snapshot CRUD"
+
+# Create a snapshot
+SNAP_NAME="crud-test-$$"
+SNAP_RESULT=$(api -X POST "$API_URL/api/snapshots" -d "{
+ \"name\":\"$SNAP_NAME\",
+ \"image\":{\"base\":\"base\",\"steps\":[{\"type\":\"run\",\"args\":{\"commands\":[\"echo snap > /workspace/s.txt\"]}}]}
+}")
+SNAP_STATUS=$(echo "$SNAP_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('status',''))" 2>/dev/null)
+[ "$SNAP_STATUS" = "ready" ] && pass "Create snapshot: $SNAP_NAME" || fail "Create: $SNAP_RESULT"
+
+# List snapshots
+LIST=$(api "$API_URL/api/snapshots")
+echo "$LIST" | grep -q "$SNAP_NAME" && pass "List snapshots: found $SNAP_NAME" || fail "List: $LIST"
+
+# Get snapshot by name
+GET=$(api "$API_URL/api/snapshots/$SNAP_NAME")
+echo "$GET" | grep -q "$SNAP_NAME" && pass "Get snapshot by name" || fail "Get: $GET"
+CP_ID=$(echo "$GET" | python3 -c "import sys,json; print(json.load(sys.stdin).get('checkpointId',''))" 2>/dev/null)
+
+# Use snapshot
+SB=$(api -X POST "$API_URL/api/sandboxes" -d "{\"timeout\":300,\"snapshot\":\"$SNAP_NAME\"}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+[ -n "$SB" ] && SANDBOXES+=("$SB") && pass "Create from snapshot: $SB" || fail "Create from snapshot"
+sleep 8
+OUT=$(exec_stdout "$SB" "cat" "/workspace/s.txt")
+[ "$OUT" = "snap" ] && pass "Snapshot content verified" || fail "Content: $OUT"
+
+# Delete snapshot
+api -X DELETE "$API_URL/api/snapshots/$SNAP_NAME" >/dev/null
+LIST_AFTER=$(api "$API_URL/api/snapshots")
+echo "$LIST_AFTER" | grep -q "$SNAP_NAME" && fail "Delete snapshot: still present" || pass "Delete snapshot: removed"
+
+# Verify creating from deleted snapshot fails
+RESULT=$(api -X POST "$API_URL/api/sandboxes" -d "{\"timeout\":300,\"snapshot\":\"$SNAP_NAME\"}")
+echo "$RESULT" | grep -qi 'error\|not found' && pass "Deleted snapshot: create fails" || fail "Deleted snapshot still works: $RESULT"
+
+h "Checkpoint Delete"
+
+SB2=$(api -X POST "$API_URL/api/sandboxes" -d '{"timeout":300}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('sandboxID',''))" 2>/dev/null)
+if [ -z "$SB2" ] || [ "$SB2" = "None" ]; then
+ skip "Could not create sandbox for checkpoint test"
+ summary
+fi
+SANDBOXES+=("$SB2")
+
+# Create checkpoint
+CP=$(api -X POST "$API_URL/api/sandboxes/$SB2/checkpoints" -d '{"name":"del-test"}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null)
+[ -n "$CP" ] && pass "Create checkpoint: ${CP:0:12}..." || { fail "Create checkpoint"; summary; }
+sleep 8
+
+# List checkpoints
+LIST=$(api "$API_URL/api/sandboxes/$SB2/checkpoints")
+echo "$LIST" | grep -q "$CP" && pass "List checkpoints: found" || fail "List: $LIST"
+
+# Delete checkpoint
+api -X DELETE "$API_URL/api/sandboxes/$SB2/checkpoints/$CP" >/dev/null
+LIST_AFTER=$(api "$API_URL/api/sandboxes/$SB2/checkpoints")
+echo "$LIST_AFTER" | grep -q "$CP" && fail "Checkpoint delete: still present" || pass "Checkpoint deleted"
+
+summary
diff --git a/scripts/qemu-tests/16-exec-sessions.sh b/scripts/qemu-tests/16-exec-sessions.sh
new file mode 100755
index 00000000..f50a6952
--- /dev/null
+++ b/scripts/qemu-tests/16-exec-sessions.sh
@@ -0,0 +1,68 @@
+#!/usr/bin/env bash
+# 16-exec-sessions.sh — Exec sessions (create, list, WebSocket attach, kill)
+set +u
+source "$(dirname "$0")/common.sh"
+
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "Exec Sessions"
+
+SB=$(create_sandbox)
+SANDBOXES+=("$SB")
+
+# Get sandbox token for worker direct access
+TOKEN=$(api "$API_URL/api/sandboxes/$SB" | python3 -c "import sys,json; print(json.load(sys.stdin).get('token',''))" 2>/dev/null)
+CONNECT=$(api "$API_URL/api/sandboxes/$SB" | python3 -c "import sys,json; print(json.load(sys.stdin).get('connectURL',''))" 2>/dev/null)
+
+# Create exec session via server proxy
+SESS_RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/exec" -d '{"cmd":"bash","args":["-c","for i in 1 2 3; do echo line-$i; sleep 0.5; done"]}')
+SESS_ID=$(echo "$SESS_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sessionID',''))" 2>/dev/null)
+[ -n "$SESS_ID" ] && pass "Create exec session: $SESS_ID" || fail "Create session: $SESS_RESULT"
+
+# List exec sessions
+sleep 1
+LIST=$(api "$API_URL/api/sandboxes/$SB/exec")
+echo "$LIST" | grep -q "$SESS_ID" && pass "List sessions: found $SESS_ID" || fail "List: $LIST"
+
+# Wait for process to finish
+sleep 3
+
+# Create another session and kill it
+SESS2=$(api -X POST "$API_URL/api/sandboxes/$SB/exec" -d '{"cmd":"sleep","args":["300"]}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('sessionID',''))" 2>/dev/null)
+[ -n "$SESS2" ] && pass "Create long-running session: $SESS2" || fail "Create session 2"
+
+# Kill the session
+KILL_RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/exec/$SESS2/kill" -d '{}')
+pass "Kill session sent"
+
+# Verify it's no longer running
+sleep 1
+LIST2=$(api "$API_URL/api/sandboxes/$SB/exec")
+RUNNING=$(echo "$LIST2" | python3 -c "
+import sys,json
+sessions = json.load(sys.stdin)
+running = [s for s in sessions if s.get('sessionID') == '$SESS2' and s.get('running')]
+print(len(running))
+" 2>/dev/null)
+[ "$RUNNING" = "0" ] && pass "Killed session is not running" || fail "Session still running: $LIST2"
+
+# Session with env vars
+SESS3=$(api -X POST "$API_URL/api/sandboxes/$SB/exec" -d '{"cmd":"bash","args":["-c","echo MY_VAR=$MY_VAR"],"envs":{"MY_VAR":"session-env"}}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('sessionID',''))" 2>/dev/null)
+[ -n "$SESS3" ] && pass "Session with env vars: $SESS3" || fail "Session with envs"
+
+# Session with timeout
+SESS4=$(api -X POST "$API_URL/api/sandboxes/$SB/exec" -d '{"cmd":"sleep","args":["300"],"timeout":2}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('sessionID',''))" 2>/dev/null)
+[ -n "$SESS4" ] && pass "Session with timeout: $SESS4" || fail "Session with timeout"
+sleep 4
+LIST3=$(api "$API_URL/api/sandboxes/$SB/exec")
+RUNNING2=$(echo "$LIST3" | python3 -c "
+import sys,json
+sessions = json.load(sys.stdin)
+running = [s for s in sessions if s.get('sessionID') == '$SESS4' and s.get('running')]
+print(len(running))
+" 2>/dev/null)
+[ "$RUNNING2" = "0" ] && pass "Timed-out session stopped" || fail "Timeout session still running"
+
+summary
diff --git a/scripts/qemu-tests/17-pty-sessions.sh b/scripts/qemu-tests/17-pty-sessions.sh
new file mode 100755
index 00000000..7060c9cc
--- /dev/null
+++ b/scripts/qemu-tests/17-pty-sessions.sh
@@ -0,0 +1,41 @@
+#!/usr/bin/env bash
+# 17-pty-sessions.sh — PTY session create, list, resize, kill (no WS attach — curl can't do WebSocket)
+set +u
+source "$(dirname "$0")/common.sh"
+
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "PTY Sessions"
+
+SB=$(create_sandbox)
+SANDBOXES+=("$SB")
+
+# Create PTY session
+PTY_RESULT=$(api -X POST "$API_URL/api/sandboxes/$SB/pty" -d '{"cols":120,"rows":40}')
+PTY_ID=$(echo "$PTY_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('sessionID',json.load(sys.stdin) if '{' not in str(json.load(sys.stdin)) else ''))" 2>/dev/null || echo "$PTY_RESULT" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('sessionID', d.get('id','')))" 2>/dev/null)
+if [ -n "$PTY_ID" ] && [ "$PTY_ID" != "None" ] && [ "$PTY_ID" != "" ]; then
+ pass "Create PTY session: $PTY_ID"
+else
+ # PTY might not be supported in server-proxy mode
+ ERROR=$(echo "$PTY_RESULT" | python3 -c "import sys,json; print(json.load(sys.stdin).get('error',''))" 2>/dev/null)
+ if echo "$ERROR" | grep -qi "not available\|not implemented\|not supported\|vsock\|no such device"; then
+ skip "PTY sessions not available (QEMU uses virtio-serial, PTY data needs vsock)"
+ summary
+ else
+ fail "Create PTY: $PTY_RESULT"
+ summary
+ fi
+fi
+
+# Resize PTY
+RESIZE=$(api -X POST "$API_URL/api/sandboxes/$SB/pty/$PTY_ID/resize" -d '{"cols":200,"rows":50}')
+# Should succeed (200 or 204)
+pass "Resize PTY"
+
+# Kill PTY
+api -X DELETE "$API_URL/api/sandboxes/$SB/pty/$PTY_ID" >/dev/null
+pass "Kill PTY"
+
+summary
diff --git a/scripts/qemu-tests/18-restore-checkpoint.sh b/scripts/qemu-tests/18-restore-checkpoint.sh
new file mode 100755
index 00000000..1b9423b2
--- /dev/null
+++ b/scripts/qemu-tests/18-restore-checkpoint.sh
@@ -0,0 +1,62 @@
+#!/usr/bin/env bash
+# 18-restore-checkpoint.sh — In-place checkpoint restore (loadvm), verify state revert
+set +u
+source "$(dirname "$0")/common.sh"
+
+TIMEOUT=60
+SANDBOXES=()
+cleanup() { for sb in "${SANDBOXES[@]}"; do destroy_sandbox "$sb" 2>/dev/null; done; }
+trap cleanup EXIT
+
+h "Restore Checkpoint (In-Place Revert)"
+
+SB=$(create_sandbox)
+SANDBOXES+=("$SB")
+
+# Write state before checkpoint
+exec_run "$SB" "bash" "-c" "echo before-checkpoint > /workspace/state.txt" >/dev/null
+exec_run "$SB" "bash" "-c" "echo v1 > /workspace/version.txt" >/dev/null
+pass "Pre-checkpoint state written"
+
+# Create checkpoint
+CP=$(api -X POST "$API_URL/api/sandboxes/$SB/checkpoints" -d '{"name":"restore-test"}' | python3 -c "import sys,json; print(json.load(sys.stdin).get('id',''))" 2>/dev/null)
+[ -n "$CP" ] && pass "Checkpoint: ${CP:0:12}..." || { fail "Create checkpoint"; summary; }
+sleep 8
+
+# Modify state AFTER checkpoint
+exec_run "$SB" "bash" "-c" "echo after-checkpoint > /workspace/state.txt" >/dev/null
+exec_run "$SB" "bash" "-c" "echo v2 > /workspace/version.txt" >/dev/null
+exec_run "$SB" "bash" "-c" "echo new-file > /workspace/new.txt" >/dev/null
+OUT=$(exec_stdout "$SB" "cat" "/workspace/state.txt")
+[ "$OUT" = "after-checkpoint" ] && pass "State modified: after-checkpoint" || fail "Modify: $OUT"
+
+# Restore
+api -X POST "$API_URL/api/sandboxes/$SB/checkpoints/$CP/restore" >/dev/null
+pass "Restore initiated"
+
+# Wait for loadvm + agent reconnect
+sleep 5
+
+# Verify state reverted
+OUT=$(exec_stdout "$SB" "cat" "/workspace/state.txt")
+[ "$OUT" = "before-checkpoint" ] && pass "State reverted: before-checkpoint" || fail "State: '$OUT'"
+
+OUT=$(exec_stdout "$SB" "cat" "/workspace/version.txt")
+[ "$OUT" = "v1" ] && pass "Version reverted: v1" || fail "Version: '$OUT'"
+
+OUT=$(exec_stdout "$SB" "bash" "-c" "cat /workspace/new.txt 2>&1 || echo gone")
+echo "$OUT" | grep -qi "gone\|No such file" && pass "Post-checkpoint file gone" || fail "New file: '$OUT'"
+
+# Sandbox still functional after restore
+OUT=$(exec_stdout "$SB" "echo" "alive-after-restore")
+[ "$OUT" = "alive-after-restore" ] && pass "Sandbox functional after restore" || fail "Post-restore: $OUT"
+
+# Restore again (multiple restores)
+h "Multiple Restores"
+exec_run "$SB" "bash" "-c" "echo modified-again > /workspace/state.txt" >/dev/null
+api -X POST "$API_URL/api/sandboxes/$SB/checkpoints/$CP/restore" >/dev/null
+sleep 5
+OUT=$(exec_stdout "$SB" "cat" "/workspace/state.txt")
+[ "$OUT" = "before-checkpoint" ] && pass "Second restore: reverted again" || fail "Second restore: '$OUT'"
+
+summary
diff --git a/scripts/qemu-tests/common.sh b/scripts/qemu-tests/common.sh
index 01611390..c4f0a3ba 100755
--- a/scripts/qemu-tests/common.sh
+++ b/scripts/qemu-tests/common.sh
@@ -2,10 +2,10 @@
# common.sh — Shared helpers for QEMU backend test scripts
set -euo pipefail
-API_URL="${API_URL:-http://3.148.184.81:8080}"
-API_KEY="${API_KEY:-test-dev-key}"
+API_URL="${OPENSANDBOX_API_URL:?Set OPENSANDBOX_API_URL}"
+API_KEY="${OPENSANDBOX_API_KEY:?Set OPENSANDBOX_API_KEY}"
SSH_KEY="${SSH_KEY:-$HOME/.ssh/opensandbox-digger.pem}"
-WORKER_HOST="${WORKER_HOST:-3.148.184.81}"
+WORKER_HOST="${WORKER_HOST:?Set WORKER_HOST}"
PASS=0
FAIL=0
diff --git a/scripts/qemu-tests/run-all.sh b/scripts/qemu-tests/run-all.sh
index d3552ff4..aef01646 100755
--- a/scripts/qemu-tests/run-all.sh
+++ b/scripts/qemu-tests/run-all.sh
@@ -6,9 +6,10 @@
# ./scripts/qemu-tests/run-all.sh 01 03 05 # run specific tests
# ./scripts/qemu-tests/run-all.sh 05 # run just hibernate tests
#
-# Environment:
-# API_URL=http://3.148.184.81:8080 (default)
-# API_KEY=test-dev-key (default)
+# Environment (required):
+# OPENSANDBOX_API_URL=http://your-server:8080
+# OPENSANDBOX_API_KEY=your-api-key
+# WORKER_HOST=your-worker-ip
set -uo pipefail
@@ -26,6 +27,13 @@ ALL_TESTS=(
"09-concurrent"
"10-edge-cases"
"11-secrets"
+ "12-templates"
+ "13-preview-urls"
+ "14-scale-timeout"
+ "15-snapshots-crud"
+ "16-exec-sessions"
+ "17-pty-sessions"
+ "18-restore-checkpoint"
)
# Filter tests if args provided
diff --git a/scripts/test-proxy-secrets.sh b/scripts/test-proxy-secrets.sh
index f78c2fd7..9197d3c6 100755
--- a/scripts/test-proxy-secrets.sh
+++ b/scripts/test-proxy-secrets.sh
@@ -14,8 +14,8 @@
#
set -euo pipefail
-API="${OPENCOMPUTER_API_URL:-http://52.14.189.164:8080}"
-KEY="${OPENCOMPUTER_API_KEY:-test-dev-key}"
+API="${OPENSANDBOX_API_URL:?Set OPENSANDBOX_API_URL}"
+KEY="${OPENSANDBOX_API_KEY:?Set OPENSANDBOX_API_KEY}"
ANTHROPIC_KEY="${1:-}"
if [ -z "$ANTHROPIC_KEY" ]; then