# Twins

> A twin is a disposable copy of production for one task, with its own database branch, its own preview address, its own machine.

> **Not available yet as one call:** Twins come with [projects](https://docs.rytiv.com/concepts/projects.md). Your agent will create one per task with a single tool call. Every piece of a twin exists today and can be assembled by hand, see below; an agent token of class `twin` is the key for it.

## What a twin is

For every task, your agent gets a twin of production:

- a **branch of the production database**, with an expiry, so the data is real but the original is never touched,
- a **preview app** that only people with a signed link can open,
- a **sandbox or computer** whose `DATABASE_URL` points at the branch.

The agent can do anything inside a twin. When the task is done, the result goes to production with a promote step, and the twin goes away.

## Building one by hand today

Every piece of a twin exists already, so you or your agent can assemble one today:

1. Branch the database with an expiry: [`create_branch`](https://docs.rytiv.com/reference/mcp-tools.md#create_branch), or `ry postgres branch` with `--expires-in`.
2. Deploy the change to an app of its own, and protect it with `ry protect signed <app>`.
3. Attach the branch to that app with `ry attach <branch> --to <app>`. The app gets the branch's connection URL as its `DATABASE_URL`.

Rytiv's MCP tools never return a database password, and the connection URL of a branch is handed out only once, to whoever asks for it first. See [Postgres](https://docs.rytiv.com/postgres.md#connection-url-of-a-copy).
