Skip to main content
Sprites are Fly.io’s Linux computers for agents: a Sprite starts in under a second, keeps its disk, and sleeps when idle. This guide runs your agent’s code in a Sprite and gives it an Anchor cloud browser. The Sprite never holds your Anchor API key, and it can be locked so that it reaches Anchor and nothing else. Tested with fly 0.5.26, sprites-py 0.7.2, @fly/sprites 0.2.5, the Anchor Python SDK 1.0.1 and the Anchor TypeScript SDK 1.0.0.

What you’re integrating

  • The Sprite runs your code. It is an Ubuntu machine with Python, Node.js, Claude Code and Codex already installed.
  • Anchor runs the browser. Your code creates a session over the API and drives it with a task or with Playwright over CDP. No browser runs in the Sprite.
  • A Sprites Connector holds the Anchor API key. Code in the Sprite calls a gateway URL, and Sprites adds the key outside the Sprite. A leaked environment or a prompt-injected agent has no key to give away.
  • A network policy limits what the Sprite can reach. With the policy on this page, the only path to Anchor’s API is the connector.

Before you start

You need an Anchor API key and a Fly.io account. Install the Fly CLI (instructions), version 0.5.20 or later, and sign in:
The scripts on this page that use the Sprites SDKs also need a Sprites token. Create one in the Fly.io dashboard under your organization, Sprites, Tokens, and keep it in your shell:
Install the Sprites SDK for your language on your own machine:

Save your Anchor key as a Connector

Create a custom API connector that points at Anchor’s API and sends the key in the anchor-api-key header. Only Sprites with the label anchor may use it:
It prints the connection ID. Keep it and build the gateway URL from it:
jq reads the key from your environment and the request body goes over standard input, so the key does not appear in your shell history. The connector shows up in the dashboard under Connectors:
Fly.io dashboard listing a custom connector named anchorbrowser for api.anchorbrowser.io, limited to Sprites with the label anchor
A connector with no access policy refuses every Sprite. The sprite_labels rule above is what lets a Sprite in. Running the command again with the same name updates the connector in place, which is how you rotate the key.

Create a Sprite and install the SDK

Create a Sprite with the anchor label and make it the default for this folder:
Install the Anchor SDK and the Playwright client in it:
Fly.io dashboard page for the Sprite anchor-demo, shown as Running with the label anchor
What to expect:
  • The Sprite is ready at once. In testing the create call took 0.5 seconds. The Python install took 9 seconds and the Node.js install 4.
  • The install is small. playwright (Python) and playwright-core (Node.js) are only the client library that speaks CDP. You do not run playwright install, because the browser lives on Anchor.
  • The install stays. A Sprite keeps its disk when it sleeps, so you install once.
  • Run commands through bash -c. A Sprite has two Pythons. Through bash, python3 is the Sprite’s managed Python 3.13, where pip installed the SDK. Started directly, python3 is the system Python 3.14, and the import fails.

Run a web task

The script in the Sprite uses the Anchor SDK as usual, with two environment variables: ANCHORBROWSER_BASE_URL points the SDK at the gateway, and ANCHORBROWSER_API_KEY is a placeholder, because the SDK wants a value. The connector replaces it with the real key. Each host script below writes the task script into the Sprite and runs it.
Run it with python run_task.py or npx tsx run_task.ts. Both print:
The Python script ran end to end in 15 seconds.
Use perform_web_task (Python) and Tools.performWebTask (TypeScript) with a connector, not agent.task and agentTask. Those two helpers build their own CDP address from the SDK’s base URL. With the gateway as the base URL they try to reach connect.sprites.dev, which does not exist, and fail with getaddrinfo ENOTFOUND connect.sprites.dev.

Drive the browser yourself with Playwright

For step-by-step control, create an Anchor session and connect Playwright to it over CDP from inside the Sprite. The session is created through the connector. The CDP connection goes straight to connect.anchorbrowser.io with the session’s own token, so it needs no API key.
Save the file on your machine. fly sprites exec uploads it and runs it in one command:
Both print:
session.data.cdp_url and the live view URL carry a session token (rt). Anyone who has one of them can reach that browser until the session ends. Do not write them to logs you share.

Watch the browser

Open the live view URL in your own browser while the script runs, or open the session in the Anchor dashboard. This is the Anchor session streaming directly, so the Sprite needs no desktop, tunnel or public URL for it.
Anchor dashboard showing a running session with the live browser on Books to Scrape and its network requests

Lock the Sprite to Anchor

By default a Sprite can reach any public address. When the code inside is untrusted, set a network policy that allows two hosts only. Install the packages first, because the policy also blocks PyPI and npm.
Wait a few seconds after every policy change before you start work. A policy applies at once, but in testing a request that started within about a second of the change, and took longer than a second to answer, was cut off and hung until its timeout. After a 3 second wait the same request passed every time. Session creation takes about 2 seconds, so it is exactly the kind of request this hits.
The task and Playwright scripts still pass in the locked Sprite. Everything else is refused at the DNS level, so it fails fast:
api.anchorbrowser.io is blocked too. The Sprite cannot call Anchor’s API directly, even if someone gave it a key. Its only route is the connector, which you can restrict and revoke. The code can still browse any site, because the page loads happen in Anchor’s browser, not in the Sprite. live.anchorbrowser.io is opened by the person watching, so it does not need to be on the list. fly sprites exec and the Sprites SDKs keep working under any policy. To open the Sprite again, for example to install another package, post an empty rule list and wait before the next request:

Limit what the connector may call

The connector’s access policy can also list the Anchor paths a Sprite may use. This one allows the session and tool endpoints and the MCP server, and nothing else:
A call to a path that is not on the list gets 403 with endpoint is not in allowed list. The * matches the rest of the path, so /v1/sessions/* also covers the /v1/sessions/all/status check in the cleanup section.

Give the coding agents in the Sprite Anchor’s MCP server

Every Sprite has Claude Code and Codex installed. Register Anchor’s hosted MCP server through the connector, and the agent can run web tasks without ever holding the key:
The registration in /home/sprite/.claude.json holds only the placeholder. This also works in the locked Sprite, because the MCP calls go through api.sprites.dev. A locked Sprite also blocks the agent’s own model provider. If you run a coding agent inside a locked Sprite, add the hosts that agent needs to the policy. For Claude Code that includes api.anthropic.com. See the MCP server page for the tools Anchor’s server offers.

Clean up two lifecycles

There are two things to end, and ending one does not end the other.
  • The Anchor session. End it in a finally block inside the script that runs in the Sprite. A Sprite that goes to sleep or is destroyed does not end a cloud browser; it keeps running and billing until its own timeout.
  • The Sprite. It sleeps by itself when idle and bills no compute while asleep, so you can keep it. Destroy it with fly sprites destroy --yes -s anchor-demo when you no longer need it.
  • Set Anchor’s timeout.max_duration and timeout.idle_timeout, in minutes, as a safety net for a script that stops mid-run. See Session Timeout.
  • Reuse one Anchor session for a whole agent run instead of creating one per page.
To confirm no browser is left running, ask Anchor from the Sprite:
To remove the key from Fly.io, delete the connector. Every Sprite loses access at once:

API key

Create and manage Anchor API keys in the Anchor dashboard. To rotate the key, run the connector command again with the new key and the same name.

Troubleshooting