molecule-core/docs/blog/2026-04-17-deploy-anywhere/index.md
devops-engineer 55689e0b10
Some checks failed
Block internal-flavored paths / Block forbidden paths (pull_request) Successful in 16s
Check merge_group trigger on required workflows / Required workflows have merge_group trigger (pull_request) Successful in 22s
CI / Detect changes (pull_request) Successful in 24s
E2E API Smoke Test / detect-changes (pull_request) Successful in 20s
E2E Staging Canvas (Playwright) / detect-changes (pull_request) Successful in 21s
pr-guards / disable-auto-merge-on-push (pull_request) Failing after 9s
Handlers Postgres Integration / detect-changes (pull_request) Successful in 44s
Lint curl status-code capture / Scan workflows for curl status-capture pollution (pull_request) Successful in 38s
Runtime PR-Built Compatibility / detect-changes (pull_request) Successful in 35s
Harness Replays / detect-changes (pull_request) Successful in 44s
Secret scan / Scan diff for credential-shaped strings (pull_request) Successful in 27s
Ops Scripts Tests / Ops scripts (unittest) (pull_request) Successful in 56s
CodeQL / Analyze (${{ matrix.language }}) (go) (pull_request) Failing after 2m1s
CodeQL / Analyze (${{ matrix.language }}) (javascript-typescript) (pull_request) Failing after 2m34s
CodeQL / Analyze (${{ matrix.language }}) (python) (pull_request) Failing after 2m34s
CI / Shellcheck (E2E scripts) (pull_request) Successful in 23s
Harness Replays / Harness Replays (pull_request) Failing after 1m12s
Runtime PR-Built Compatibility / PR-built wheel + import smoke (pull_request) Successful in 2m51s
E2E API Smoke Test / E2E API Smoke Test (pull_request) Failing after 5m37s
Handlers Postgres Integration / Handlers Postgres Integration (pull_request) Successful in 6m15s
E2E Staging Canvas (Playwright) / Canvas tabs E2E (pull_request) Successful in 6m34s
CI / Python Lint & Test (pull_request) Successful in 8m20s
CI / Canvas (Next.js) (pull_request) Successful in 9m46s
CI / Canvas Deploy Reminder (pull_request) Has been skipped
CI / Platform (Go) (pull_request) Failing after 13m23s
fix(post-suspension): migrate github.com/Molecule-AI refs to git.moleculesai.app (Class G #168)
The GitHub org Molecule-AI was suspended on 2026-05-06; canonical SCM
is now Gitea at https://git.moleculesai.app/molecule-ai/. Stale
github.com/Molecule-AI/... URLs return 404 and break tooling that
clones / pip-installs / curls them.

This bundles all non-Go-module URL fixes for this repo into a single PR.
Go module path references (in *.go, go.mod, go.sum) are out of scope
here -- tracked separately under Task #140.

Token-auth clone URLs also flip ${GITHUB_TOKEN} -> ${GITEA_TOKEN} since
the GitHub token does not auth against Gitea.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 13:08:15 -07:00

6.7 KiB

title date slug description tags
Deploy AI Agents on Fly.io — or Any Cloud — with One Config Change 2026-04-17 deploy-anywhere Molecule AI supports fly.io agent deployment and control-plane provisioning. Switch backends with one env var — no agent code changes required.
platform
fly.io
deployment
infrastructure

Deploy AI Agents on Fly.io — or Any Cloud — with One Config Change

Your infrastructure choice just got decoupled from your agent platform choice. Molecule AI now ships three production-ready workspace backends — docker, flyio, and controlplane — and switching between them takes a single environment variable. Your agent code, model choices, and workspace topology stay exactly the same.

This post covers what shipped in PR #501 (Fly Machines provisioner) and PR #503 (control plane provisioner), and which backend fits your situation.

Before: One Deployment Model for Every Use Case

Until this week, Molecule AI workspaces ran on one backend: Docker. That was the right default for self-hosters — no external dependencies, full control, works anywhere a Docker daemon runs. But it left two groups making a compromise they shouldn't have to:

  • Indie developers and small teams wanted Fly.io's economics: pay-per-use compute, fast cold starts, scale to zero when nobody's working.
  • SaaS builders needed structural credential isolation. A Fly API token sitting in the tenant layer is one misconfiguration away from a security incident — not a policy problem, an architecture problem.

Both groups were choosing between "use the platform" and "get the deployment model I need." That trade-off is gone.

Run AI Agents on Fly: The Indie Dev Path

You're already on Fly. You have an account, a Fly app, and you're comfortable with Machines. You want Molecule AI workspaces to provision as Fly Machines — no separate Docker host, no idle infrastructure, just workspaces that appear when needed and disappear when they don't.

Set three environment variables on your tenant platform instance:

CONTAINER_BACKEND=flyio
FLY_API_TOKEN=<your-fly-deploy-token>
FLY_WORKSPACE_APP=<your-fly-app-name>

# Optional — defaults to ord
FLY_REGION=ord

When a workspace is created, the Fly provisioner:

  1. Spins up a Fly Machine inside your FLY_WORKSPACE_APP
  2. Injects workspace secrets and the platform registration URL as machine env vars
  3. Selects the right GHCR image for the runtime (hermesghcr.io/molecule-ai/workspace-hermes:latest, and so on)
  4. Applies tier-based resource limits — T2 at 512 MB / 1 vCPU, T3 at 2 GB / 2 vCPU, T4 at 4 GB / 4 vCPU
  5. Issues a boot-time auth token so the workspace agent can register with the platform immediately

Your workspaces run as first-class Fly Machines. When they're idle, Fly handles the scale-down. Your bill reflects actual usage, not reserved capacity.

Multi-Tenant Agent Provisioning Without Credential Sprawl

You're building a SaaS product on top of Molecule AI. Each customer gets a Molecule workspace. The problem: if every tenant platform instance carries a FLY_API_TOKEN, you've distributed cloud credentials across your tenants — structurally. Policy controls help, but they don't remove the credential from the attack surface.

CONTAINER_BACKEND=controlplane removes it entirely.

Canvas → Tenant Platform → Control Plane API → Fly Machines API

The tenant platform never holds a Fly token. It calls the Molecule control plane at https://api.moleculesai.app (overridable via CP_PROVISION_URL for staging environments), which holds Fly credentials and orchestrates workspace provisioning centrally.

For standard SaaS deployments, you don't configure this manually — the platform auto-detects the right backend:

  • MOLECULE_ORG_ID set → SaaS tenant → control plane provisioner activates automatically
  • MOLECULE_ORG_ID empty → self-hosted → Docker provisioner, no change needed

The right backend is the default for your context. For most SaaS builders: set MOLECULE_ORG_ID at tenant launch, and credential isolation is structural from day one.

Self-Hosted vs Cloud AI Agents: Backend Comparison

Backend CONTAINER_BACKEND Best for Who holds cloud credentials
Docker (empty / default) Self-hosted, local dev No external credentials needed
Fly Machines flyio Indie devs / small teams on Fly FLY_API_TOKEN lives on the tenant
Control Plane controlplane SaaS builders, multi-tenant products Fly token held by control plane only — never on tenant

Fly backend env vars (for CONTAINER_BACKEND=flyio):

Variable Required Default What it does
CONTAINER_BACKEND Yes Activates the Fly provisioner
FLY_API_TOKEN Yes Fly deploy token
FLY_WORKSPACE_APP Yes Fly app that hosts workspace machines
FLY_REGION No ord Region for new machines

Agent Orchestration in the Cloud: What Doesn't Change

Switching backends changes where workspaces run, not how they work. From any agent runtime's perspective — Hermes, Letta, or whatever you're orchestrating — the workspace is the workspace. Unchanged across all three backends:

  • Agent registration and boot sequence
  • Model routing and provider dispatch
  • Workspace secrets injection
  • The full platform API surface

No changes to agent code, tool definitions, or orchestration logic. Swap CONTAINER_BACKEND, redeploy, done.

Multi-Agent Cloud Deployment: Choose Your Path

  • Self-hosting? Leave CONTAINER_BACKEND unset. Docker is the default — nothing to configure.
  • On Fly, small team? Set CONTAINER_BACKEND=flyio with FLY_API_TOKEN and FLY_WORKSPACE_APP. Workspaces become Fly Machines in your own Fly account.
  • Building a SaaS product on Molecule AI? Set MOLECULE_ORG_ID at tenant launch. The control plane provisioner activates automatically. No Fly credentials on the tenant, ever.

Pick your backend. Deploy your agents.

Quickstart: choose your deployment backend

See also: Give Your AI Agent a Real Browser: MCP + Chrome DevTools — wire Chrome DevTools Protocol into your Molecule AI workspace via MCP for production-grade browser automation.


PR #501 (Fly Machines provisioner) and PR #503 (control plane provisioner) are both merged to main. Molecule AI is open source — contributions welcome.