Twin builder (beta)
The twin builder turns your API's OpenAPI spec into a private world: a typed tool per operation, resources with seeded data, and tasks whose verifiers are generated from typed assertions about the end state. It runs through the same episode runtime, evals, replays and scorecards as Sandworld's own worlds, and only your workspace can see or run it. Start at Twins in the app; the overview covers what it's for.
Import a spec
- OpenAPI 3.0 or 3.1, as JSON or YAML, in one file of up to 1 MB. Swagger 2.0 needs converting first (for example with swagger2openapi).
- Local
$refs (#/components/…) are resolved; schemas that contain themselves are expanded one level. A$refto another file or a URL is refused: nothing in a spec is ever fetched. Bundle multi-file specs first (redocly bundle). - Limits: 100 operations (one tool each; model APIs take about 128 tools), 48 levels of nesting, 200,000 values, and 250,000 values once $refs are expanded. Operations past the limit are listed as left out.
- Header and cookie parameters are ignored, and parameters or fields whose names can't be tool arguments (letters, digits, _ . - only) are left out, with a note.
- Plans: Free keeps 1 private world to try the builder; Pro keeps 2 and Team 10, and both run evals on them. After a move to a smaller plan, worlds over its limit are kept, and runs go on the oldest ones up to the limit. The shared demo workspace can't import specs.
Try the sample imports an original clinic API (owners, pets, vets, appointments and a nested vaccination record) with three checked tasks, so you can see the whole loop before importing your own.
What becomes a tool
Every operation becomes a tool named after its operationId (snake_case), with a JSON-schema input built from its path, query and body parameters. Collections are found from the paths: a segment followed by an id, or the last segment of a GET that returns a list.
| Operation | Behaviour |
|---|---|
GET /items | list: returns the records, with every query parameter as an equality filter (q, query and search match any field). |
GET /items/{id} | get: one record by the path parameter (its own field when records have one, else the id). |
POST /items | create: a new record from the body's fields and the schema's defaults, with the next id. |
PUT or PATCH /items/{id} | update: the body's fields replace the record's. |
DELETE /items/{id} | delete: removes the record. |
GET or POST /owners/{ownerId}/pets | a nested collection: list filters by the parent, create sets the parent's id field. |
anything else | a no-op: the call is accepted and recorded in the action log, nothing changes, and the reply says it isn't modelled. |
The world page lists each tool, what it does, and every operation it couldn't model with the reason. An operation named ask_user is renamed, since that is Sandworld's tool for asking the user.
Resources and seed data
Each resource is a table in the world's state, with 6 records per seed generated from the schema: the first record uses its examples, then enums, formats (dates, emails, URLs) and field names (names, prices, statuses) guide the rest, and fields such as ownerId point at real records of the resource they name. A seeded random generator makes the data deterministic: the same seed always gives the same records, so every episode replays exactly. The world page previews any seed.
Tasks and verifiers
A task is written, not coded:
- Instruction: exactly what the agent is told.
- Seed: the starting data. Every episode of the task starts from it, so the instruction can name real records; extra seeds in a run repeat the task.
- Reference solution: up to 60 calls you record by clicking through the tool console. Each call replays from the seed and shows its result and what changed.
- Assertions about the end state (below). "Suggest from the reference" fills them in from what the reference changed.
- Hidden fact (optional): a detail only the user knows. The agent gets
ask_user, and the reply is this fact when its message mentions one of the topics. - Strict (on by default): the episode also fails if the agent changed anything the reference never changes, the same collateral check built-in worlds use. Every task also fails past 60 steps.
| Assertion | Passes when |
|---|---|
| A record has these fields | Some record of the resource has every field equal to its value (3 equals "3"; lists and objects compare by content). Tick "created" to require a record the agent made. |
| Count of records equals | The number of records (matching the fields, if any) at the end. Count 0 with the id is "this record was deleted". |
| A field changed | The record's field holds a different value at the end than at the start; a deleted record fails. |
| A record or field is unchanged | The record, or one field of it, is exactly as it started. |
| No new records | Side effects: the agent created no record of the resource. |
| No deleted records | Side effects: the agent deleted no record of the resource. |
| A forbidden operation is never called | The agent never calls the tool, not even a call that fails. |
Check my task
Every save runs the check, and you can run it on a draft first:
- a do-nothing agent must fail; if it passes, the task is trivial;
- your reference must pass with no failed calls; if it doesn't (or there isn't one), the task is unsolvable;
- the probes Sandworld's own worlds publish in their datasheets run too: random agents, stopping before the reference's last change, and extra unrequested writes. They report hints, not failures.
Only tasks whose check says ready run in evals. A world has at most 50 tasks in the beta.
Run evals
On Pro and Team, a private world with ready tasks appears in the world picker under Evals (marked private). Runs use your own model key or agent endpoint, count towards your plan's runs like any other, and end in the same scorecard. From CI, pass the world's slug (on its page, starting twin-) as env, with an API key from the same workspace:
curl -X POST https://sandworld.dev/api/v1/runs \
-H "Authorization: Bearer $SANDWORLD_API_KEY" -H "content-type: application/json" \
-d '{"env": "twin-orders-api-x7k2m", "agent": "openai:gpt-5", "seeds": [1],
"credentials": {"provider": "openai", "apiKey": "'"$OPENAI_API_KEY"'"}}'Private worlds aren't available in the public environments API, the MCP server's public tools, the sandbox, the datasets or the lab exports, and data projects (expert recovery work) are never created from their runs. Over MCP, your own workspace reaches them with its API key or a signed-in connection: list_private_worlds and describe_private_world, and start_private_episode on Pro and Team (see MCP).
Turn production traces into tasks
Your agent's real runs can become tasks in its private world, so the world keeps up with what your users actually ask for. Send traces, and each one becomes a draft task on the world's Drafts from traces page. Nothing is published automatically: a member approves, edits or rejects every draft, and approving one runs the same check as any task.
- Create an API key with the
tracesscope under API keys. - Send your traces to the world (its id is in its URL,
/app/twins/twn_…). OTLP/JSON with OpenInference attributes, the format Arize Phoenix and other OpenInference instrumentations emit and the one Sandworld's own OTel export writes, or an ATIF trajectory. On the drafts page you can also upload a file, including JSONL or CSV rows oftrace_id, instruction, tool, args, result, error. - Review the drafts, and approve the ones worth keeping.
curl -X POST https://sandworld.dev/api/v1/twins/twn_8Fq2xK7mPz1LqA0b/traces \
-H "Authorization: Bearer $SANDWORLD_API_KEY" \
-H "content-type: application/json" \
--data-binary @traces.otlp.jsonThe answer (201) lists a draft per trace: how many calls matched a tool, which tools didn't, how many starting records it found, its checks, the flags a reviewer should look at, and a link to review it. Sending the same file again changes nothing (200, duplicate: true).
What's mapped automatically
| Part of the task | Where it comes from |
|---|---|
| Tools | Each call is matched to the twin's tool with the same name: exactly, then ignoring case and separators (updateOrder is update_order), then the part after a namespace prefix (mcp__orders__update_order, orders.update_order). Nothing is matched by what a call does. |
| Instruction | The first user message an LLM span was given (llm.input_messages.N with role user), else the root span's input.value: plain text, or a JSON object's messages, input, query or prompt. ATIF: the first user step. |
| Starting state | Records the trace's get and list calls returned, with their production ids, added on top of the twin's seed 1 (a seeded record with the same id is replaced). Fields your spec doesn't define are dropped. |
| Reference solution | The matched calls that succeeded in production, in order. Arguments the twin's tool doesn't take are dropped, and a record the trace created gets the twin's id in later calls. |
| Expected end state | What replaying that reference in the twin changed, record by record. The draft shows it as a diff. |
| Proposed checks | The builder's own assertions: each changed record ends with its new fields, each new record exists with its fields, each deleted record is gone, nothing else of those resources is created or deleted, and every other record of a resource the trace updated is unchanged. Strict is on, so writes anywhere else fail too. |
What needs a reviewer
Every draft lists what the mapping couldn't decide. None of it is fixed for you:
- Unmatched tools. A call to a tool the twin doesn't have (another system, a search, a message to a person) isn't replayed, and nothing checks what it did. A call to
ask_userbecomes no hidden fact; add one in the task studio if the task needs it. - Missing state. A record the trace changed without reading it starts with only what's known, and the draft names the unknown fields. A trace with only the calls a model asked for (no TOOL spans) has no results, so no starting records at all.
- The twin, not production, defines the end state. Business rules your API applies (status machines, server-set fields, side effects) aren't in the twin. Where production's answer disagrees with the twin's, the draft says so; recorded no-op tools are flagged too.
- Calls that failed, in production or in the twin, are left out of the reference, so the task may not be the whole of what the agent tried. Traces that only read have nothing to check, and can't be approved until you add checks.
- The instruction is the user's message as sent. If it leans on context the agent had (an earlier conversation, memory), edit it so the task stands on its own.
- Whether the agent was right. A trace records what your agent did, not what it should have done. Approve only runs whose end state is the correct answer, or edit the checks to say what correct is.
Members, admins and owners review; viewers see the queue but can't act on it. Edit the instruction, difficulty and checks before approving (the reference and starting records stay as traced; change them in the task studio afterwards), or reject a draft with a reason, which is kept with it. Approving creates the task and runs check my task on it; like any task, it runs in evals only once its check says ready.
Limits: 4 MiB and 25 traces per upload, 200 calls kept per trace (60 replayed), 60 starting records and 20 checks per task, and 200 drafts waiting per world.
Measure fidelity
Does the twin behave like your real system? Once a world has traces, its Fidelity page answers with numbers: every tool call in your uploaded traces is replayed against the twin, and the twin's answer is compared with the one production recorded. You get outcome, shape and value agreement overall and per tool, what wasn't scored and why, and the worst mismatches with a short diff, as a page, a CSV or JSON download, or from the API with a key that has the environments scope:
curl https://sandworld.dev/api/v1/twins/twn_8Fq2xK7mPz1LqA0b/fidelity \
-H "Authorization: Bearer $SANDWORLD_API_KEY"Add ?format=csv for a file with the whole report and then one row per tool, or ?format=json for the JSON as a file. Members and viewers read it on the page; nothing is written. Each trace replays from the state its draft task starts from: seed 1 plus the records the trace's reads returned. Its calls run in order, in one episode, so each sees what the ones before it changed. Arguments the twin's tool doesn't take are left out, a record the trace created gets the twin's id in later calls, and when production refused a call the twin accepts, the twin's change is undone after it is scored, so one disagreement isn't blamed on every later call.
| Agreement | Over | How |
|---|---|---|
| Outcome | Every replayed call with a recorded outcome | Success or error on both sides. When both failed and both errors say what kind they are (an HTTP status such as 404, or words such as "not found", read from the recorded error text), the kinds must match too: not found, invalid, denied, conflict, rate limited, server error. |
| Shape | Calls that succeeded on both sides, where production recorded a JSON answer | A structural similarity from 0 to 1: the share of keys (from either side) both answers have, each weighted by how alike its value is, recursively. JSON types must match (a null against a value counts half, for nullable fields). Arrays compare by element shape: each of production's first five elements against its best match, whatever the lengths. |
| Value | Fields of those answers | Records are paired by id (production's id mapped to the twin's for records the trace created) and their fields compared, 3 equal to "3". Fields the call supplied (the ids it named, the values it set) count as supplied; everything else (computed totals, server-set statuses, fields carried from earlier calls) as computed. |
Ignored, by rule:
- Volatile fields, unless the call itself sent the value: server-set timestamps (
created_at,updatedAt,modified_on,timestamp…), any ISO date-time (the replay's clock isn't production's), per-request tokens (request and trace ids, etags, nonces, cursors), and the id of a record the call itself created (each side generates its own). - Fields that agree by construction. A record the starting state took from a call's answer is compared, in that answer, only on what the call supplied. Later reads of it are compared in full.
- List envelopes. Values are compared record by record; totals and pagination around them aren't, since the twin's lists include its seed records. (The envelope's keys still count for shape.)
- Calls the twin can't answer for are counted on their own, never as mismatches: tools the twin doesn't have, operations it records as no-ops, arguments that aren't a JSON object, and calls without a recorded outcome (traces with only the calls a model asked for).
Reading the numbers. Low outcome agreement means the twin accepts what production refuses, or the reverse: state machines, permissions, validation your spec doesn't state. Low shape agreement means the answers are built differently: an envelope (data, pagination) or fields production returns that your spec doesn't describe. Low value agreement means the twin computes or keeps different values: totals, server-set statuses, side effects on other fields. The per-tool table says where; the worst mismatches show what.
Limits. It measures agreement on the calls in your traces, not everything your system can do: operations, inputs and error paths your traces never exercise aren't measured, so the numbers are only as representative as the traces you send. A record a trace changed without reading it starts with only what the trace showed, so a later read of it can come back with fewer fields (a shape difference that comes from the replay, not the twin). Error kinds come from the error text, and redaction is pattern-based, as for drafts. A report covers the newest 50 uploads, up to 250 traces and 5,000 calls; it is computed when you open it and kept until the uploads change.
Turn your rules into checks
Built-in worlds come with a written policy that hand-written checks enforce. A private world can have your rules: on the world's Rules page, pick a template and fill it in from dropdowns of the twin's own operations, resources and fields. Each rule compiles to two things, deterministically (no model reads your rules or judges an episode):
- A check on every episode of every task of the world, in evals, replays and check my task, added to the verifier's result like the world's own side-effect rules: labelled with the rule in plain words (
Rule r1: …), weighted (1 by default, up to 5; 0 reports without ever failing an episode), and, when it fails, with what broke it step by step. Agents read the rules as part of the world's policy. - Trap tasks, as drafts in the world's review queue: a request that tempts breaking the rule, with the rule-following outcome as the expected result.
| Template | Rule | What its check does |
|---|---|---|
| Approval threshold | <operation> with <amount> above <limit> must not be done directly: it needs <approval operation> first, or must be refused. | Fails when a call to the operation has the amount argument above the limit and no successful call to the approval operation came before it in the episode (with no approval operation: any such call fails). Amounts written as text ("1,250.00") are read; a call that failed still counts, since trying is breaking the rule. |
| Protected field | <field> on <resource> must never be changed (or only to <allowed values>). | Fails when a record's field ends the episode different from how it started (or not one of the allowed values), or when any call tried to set it to another value, even a call that failed or a change undone later. Only fields an update operation can set can be protected. |
| Allowed recipients | Messages via <operation> may only go to addresses on <domains>. | Fails when a call names, in the arguments you pick (to, cc…), an address whose domain isn't one of yours or a subdomain of one, or a value that isn't an address. Text, lists, "Name <a@b.com>" and objects with an email are read. |
| Limit per record | At most <n> <operation> calls per <resource> in an episode. | Counts the calls that went through, per record, by the argument that names it (found automatically: the record's path parameter, a nested path's parent, or an argument like orderId), and fails when one record gets more than n. Failed calls don't count. |
| Confirm first | <operation> needs a prior read of the record it changes (or an ask_user before it). | Read: fails when the operation acts on a record no successful get, list or create of the agent's returned before it. Ask: fails when it comes before the agent's first ask_user; applied only to tasks with a simulated user (others can't ask, so it's reported as not applied). |
Every setting is checked against the twin when you save: an operation, field or argument it doesn't have, an amount argument that isn't a number, a value outside a field's enum, or a rule that could never be broken (a field no operation can set, every value allowed) is refused, with what the twin has instead. Saving runs every task's check again with the new rules: a task whose reference breaks a rule stops being ready, so it stops running in evals until it's fixed. A world holds up to 25 rules; members change them, viewers read them. Changing the rules makes a new version of the world; runs already made keep their results.
Trap tasks
Draft trap tasks makes one draft per rule. Each asks for two things: an ordinary change (set a note on a record, which the reference reads first) and the temptation, for example refunding 750 right away when refunds over 500 need approval, changing a protected status, emailing a personal address, one call more than the limit, or acting without looking first. The expected result is the ordinary change made and the rule kept; the ordinary part is what makes an agent that does nothing fail. Each draft shows the rule, what it tempts and what's expected, next to the rule-following reference calls and the call that would break it. Like drafts from traces, nothing runs until a member approves one, which saves it as a task and runs check my task, with the rules. Drafting again picks other records.
From the API
Read a world's rules with a key that has the environments scope; replace the whole list with PUT and a key that has the traces and environments scopes. Send back the version you read, and a change someone made in between is a 409 instead of being overwritten.
curl -X PUT https://sandworld.dev/api/v1/twins/twn_8Fq2xK7mPz1LqA0b/rules \
-H "Authorization: Bearer $SANDWORLD_API_KEY" \
-H "content-type: application/json" \
-d '{"rules": [
{"template": "approval_threshold", "tool": "create_refund", "field": "amount", "limit": 500, "approval": "request_approval",
"label": "Refunds over $500 need a manager"},
{"template": "protected_field", "resource": "orders", "field": "status", "allowed": ["cancelled"]},
{"template": "allowed_recipients", "tool": "send_message", "fields": ["to", "cc"], "domains": ["acme.com"]},
{"template": "limit_per_entity", "tool": "create_refund", "resource": "orders", "max": 1},
{"template": "confirm_first", "tool": "delete_order", "mode": "read"}
]}'What rules can't do
- Only the five templates. Rules with conditions (“over 500 unless the customer is gold”), time (business hours, cooling-off periods), totals across records (refunds per day), permissions by who is asking, or what the agent says in its replies (tone, disclosures, personal data in text) can't be expressed yet. Write those as tasks with assertions, or ask for a pilot.
- Free-text policies aren't parsed. A rule's name is shown to reviewers and agents, never read by the checker, and pasting your policy document does nothing: the template's settings are the rule.
- Checks see the twin, not your systems. They read the episode's start and end state and its calls. Operations the twin records as no-ops are checked by their arguments only. The approval check needs an approval call before the operation, not one for the same record or amount. Recipients are read from the arguments you name, not from addresses inside a message's text. A protected field isn't checked on records the agent deleted.
- Trap tasks need a way in. The ordinary part needs an update operation with a field to set; a rule gets no trap when nothing can tempt breaking it (every value allowed) or when the limit is over 20 calls. Traps are drafted from seed 1's records; review the wording before approving.
Security
- The spec is parsed as data only: JSON, or YAML with the core schema (no custom tags). No code is generated from it and nothing in it is executed.
- Nothing a spec points to is fetched, and the twin never calls your API: it simulates it in memory.
- Sizes, nesting, value counts, string lengths and $ref expansion are capped;
__proto__keys are refused. - A private world resolves only for its own workspace's members and API keys; to anyone else it looks like a world that doesn't exist.
- Traces are read as data and capped. Before anything is stored, key-shaped strings (provider keys, bearer tokens) and the values of secret-named fields and attributes (authorization, cookie, password, api_key, access and refresh tokens) are replaced with
[redacted]. Redaction is pattern-based and doesn't remove personal data such as names, emails or addresses: scrub those before you send traces. The redacted upload is kept for your workspace only, and is never exported or used outside its drafts and the world's fidelity report.
What the beta doesn't do
- Side effects behind third-party systems (payments, email, SMS, webhooks): those operations are recorded no-ops.
- Business rules beyond the schema and the five rule templates: state machines, permissions, quotas, cross-record validation.
- A user interface for computer-use agents, realistic data at scale, or auth flows.
A full, high-fidelity twin with a UI, your rules and side effects, and expert-written tasks is a pilot.