Run Amp threads on instabox sandboxes as Amp orbs

Merged
CA
19h ago
+5919-28

Adds Amp orbs: InstaADE makes the user's instabox workspace an orb provider for Amp, so each Amp thread runs on its own instabox sandbox. Setup is one click on a paid plan. It needs no change to the instabox backend or to Amp. See docs/amp-orbs.md.

How it works

  • Provider sandbox. Setup makes amp-orb-provider (smallest size, auto sleep off, metadata instabox-role=amp-orb-provider). It installs amp-orbs and three systemd units, then runs amp orb provider /usr/local/bin/amp-orbs as a service.
  • Dispatch program (src-tauri/assets/amp-orbs/amp-orbs, bash). Amp calls it with ORB_OPERATION:
    • spawn finds or creates the thread's orb sandbox, named by Amp's orb ID amp-<thread UUID>, from the project's snapshot, else the newest base snapshot. When the thread picked an orb type (ORB_TYPE), the orb gets that type's size: small, medium, large, xlarge/xxlarge (Amp's size names, a1. optional) or <vCPUs>x<GB>. instabox snapshots are size-locked, so a mismatched orb is resized with instabox resize --restart before Amp starts. An unknown type fails before any sandbox; a new orb that cannot get its size is deleted. Without types: 4 vCPU / 8 GB, as before. Then it starts amp orb bootstrap there.
    • pause saves a snapshot when Amp asks for one, then suspends the orb.
    • delete deletes the orb.
    • It only touches sandboxes with instabox-role=amp-orb and the matching amp-orb-id.
    • The app finds the provider and orbs only in sandboxes whose orgId is the workspace's; a sandbox without an orgId is in no workspace.
  • Orb image. instabox snapshot import imports Amp's official orb image as amp-orb-base-<time>. A daily timer imports it again. The import's builder sandbox is amp-orb-builder-<provider id>: the program and removal delete only a builder with that exact name and the import's mark, never an import of the user's.
  • instabox key. Setup makes a workspace key with machine and image scopes for 365 days. It goes to the provider through exec env with noHistory, never in the command text. The install saves it in /etc/amp-orbs/key (root only, read by systemd) and runs the installers in a new process without it. Repair rotates it. The app renews it in its last 30 days, in the workspace the read was for, also when the user switched workspaces meanwhile.
    • Setups that run at once (two admins, two apps) cannot leave an extra key or a revoked one installed. The provider installs one key at a time (flock) and keeps the newest key, ranked by expiry then id (orbs::key_rank). Each setup lists the keys after its install and revokes only keys older than its own, and its own key when the provider kept a newer one.
  • Tools on the provider. instabox CLI 0.8.522, installed only when its npm tarball has the hash InstaADE knows (orbs::INSTABOX_CLI). Amp's CLI from npm, unpinned.
  • Sign-in. A terminal opens on the provider. It runs amp login, amp orb provider create instabox and set-default, so the user copies no token.
  • Removal refuses while orbs are left. It stops dispatch on the provider and checks the orbs again, then deletes the orb snapshots and the import builder with the user's sign-in, revokes every Amp orbs key, and deletes the provider. Each step must succeed, and a second removal finishes what a failed one left.
    • The stop takes the install lock and marks the provider as being removed. For 30 minutes, a setup, repair or renewal in another app changes nothing on it, so none starts dispatch again or installs a key. The keys are listed after the stop.
    • It deletes only snapshots named as amp-orbs names them (amp-orb-base-<time>, amp-orb-snap-<project>-<time>[-<tag>]), never a user's snapshot that only starts alike.
  • Provider token. amp-orbs-connect keeps the token that amp orb provider create instabox saved for the Amp server in use, in /var/lib/amp-orbs/provider-token (0600). The provider runs with that token only.

UI

  • An offer above the list in Amp mode, and Settings → Amp orbs.
  • The Amp orbs page: setup steps, costs, the sign-in terminal, status, Rebuild image, Remove.
  • Provider and orb rows show their role. Orbs have no ADE, power or delete; Open thread opens the thread at ampcode.com. The tray leaves both out.
  • Free plan: the page asks for a paid plan.

API client

  • create_org_api_key, org_api_keys and revoke_org_api_key (POST/GET/DELETE /v1/orgs/{id}/keys).
  • delete_snapshot (DELETE /v1/snapshots/{id}).
  • ExecRequest gains envs and noHistory.

End-to-end run (2026-12-04 PST, Team workspace, real Amp account)

  • Setup, install, key isolation (/etc/amp-orbs/key root 0600, not in the env file), sign-in, token saved under orb-provider-token@https://ampcode.com/, service active: OK.
  • Orb image import: amp-orb-base-1796416451 ready.
  • A thread on an orb (amp -ox … --orb-provider instabox): spawn in 15.9 s, 4 vCPU / 8 GB from the base snapshot, amp orb bootstrap running. Archive → pause in 2.8 s; delete → sandbox deleted in 2.2 s.
  • Found by the run and fixed here: Amp's orb ID is amp-<thread UUID>, not amp-T-<UUID>, so Open thread did not show.
  • Not yet run: a project thread (snapshot on pause), orb types against real Amp, Remove.

Verify

  • bun run typecheck, bun run test (255 passed), bun run build.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings, cargo test: 1040 passed. ade::orca::tests::slow_servers_share_one_deadline_and_one_not_read_hides_no_work fails under full-suite load locally, also on main, and passes alone.
  • The script tests run the dispatch program against a fake instabox, amp and systemctl.
  • Browser preview: ?orbs=setup|signin|connected|free. docs/amp-orbs.md has screenshots of it and an Orb sizes section.

🤖 Generated with Claude Code