Skip to Content
Running a shared simulator

Guides

Running a shared simulator

For one simulator that many clients or agents call: a shared dev box, a CI service or a simulator behind your own proxy. The clients get the vendor API. You keep the control plane (reset, seed, clock, inspect) and a log of every change.

Set it up

export RYSTIC_ADMIN_TOKEN=$(openssl rand -hex 16)   # keep this; clients never need it
export RYSTIC_ACTION_LOG=$PWD/actions.jsonl
PORT=$(rystic run stripe-twin -d --name shared --port 0 --bind 0.0.0.0 --scenario design_studio --json | jq -r .data.port)

--port 0 picks a free port and PORT keeps it. --bind 0.0.0.0 listens on every interface, so other machines reach it; without it, only this machine does. Clients get http://<this host>:$PORT and a key of their own. For a port your clients know in advance, pass that port to --port. The native runner, rystic run’s default, hands RYSTIC_ADMIN_TOKEN and RYSTIC_ACTION_LOG to the simulator.

The admin token

With RYSTIC_ADMIN_TOKEN set, every control route but /_rystic/version and signed file and upload URLs needs it in an X-Rystic-Admin-Token header, or, on the evaluator’s three routes, the worker token below. The vendor API does not.

curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:$PORT/_rystic/reset
# -> 401
curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:$PORT/_rystic/reset -H 'X-Rystic-Admin-Token: wrong'
# -> 403
curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:$PORT/_rystic/reset -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN"
# -> 204
curl -s localhost:$PORT/v1/customers -u sk_test_agent: | jq .object
# -> "list"
RouteWith the token set
/_rystic/*: every route in the control plane reference, the state UI includedneeds the token
a simulator’s own control routes: Kalshi’s /_replay/*, /_settle and /_account/snapshot, Stripe’s /_dispute, Resend’s /_bounce, Lob’s /_tracking_eventneeds the token
/_rystic/eval/claim, eval/complete, eval/snapshotthe token, or X-Rystic-Worker-Token carrying the simulator’s RYSTIC_EVAL_WORKER_TOKEN, which reaches nothing else; rystic evaluator sends its own RYSTIC_EVAL_WORKER_TOKEN
GET /_rystic/versionopen: the readiness check
/_rystic/files/…open: the signature is the credential (File URLs)
/_rystic/staged-uploads/…open: the signed upload target is the credential
GET /_feedopen: a UI reads a timeline’s messages there
the vendor APIopen
  1. No token returns 401 with the body Unauthorized; a wrong one returns 403.
  2. A browser sends the token as a rystic_admin_token cookie, for the state UI at /_rystic/ui/.
  3. With the token unset, every control route is open.

From the CLI

rystic reads RYSTIC_ADMIN_TOKEN from its own environment:

  1. rystic run hands it to the simulator it starts.
  2. The CLI adds the header to its own calls to the simulator, such as rystic tail and run --seed-rng, on localhost and loopback addresses.
  3. For a simulator on another host, list that host in RYSTIC_ADMIN_TOKEN_HOSTS, comma-separated host or host:port. The CLI sends the token to no other host.
export RYSTIC_ADMIN_TOKEN=…  RYSTIC_ADMIN_TOKEN_HOSTS=sims.internal:8080
rystic tail --addr http://sims.internal:8080
# -> 00:00:00.000 CTL reset

Without the host in the list, or without the token:

rystic: cannot reach twin at http://sims.internal:8080: 401 Unauthorized from http://sims.internal:8080/_rystic/events

Export the token. rystic run --env RYSTIC_ADMIN_TOKEN=… hands it to the simulator only, so the CLI’s own calls, such as --seed-rng, are refused.

The action log

RYSTIC_ACTION_LOG=<path> appends one JSON line per state change to that file. After the setup, the three resets above and one write:

curl -s localhost:$PORT/v1/customers -u sk_test_agent: -d email=ada@example.com > /dev/null
jq -c '{seq, kind, op: .data.op, path: .data.path, status: .data.status}' actions.jsonl
# -> {"seq":1,"kind":"control","op":"reset","path":null,"status":null}
# -> {"seq":2,"kind":"control","op":"scenario","path":null,"status":null}
# -> {"seq":3,"kind":"request","op":null,"path":"/_rystic/reset","status":401}
# -> {"seq":4,"kind":"request","op":null,"path":"/_rystic/reset","status":403}
# -> {"seq":5,"kind":"control","op":"reset","path":null,"status":null}
# -> {"seq":6,"kind":"request","op":null,"path":"/_rystic/reset","status":204}
# -> {"seq":7,"kind":"request","op":null,"path":"/v1/customers","status":200}

What it logs:

  1. Every request but GET, HEAD and OPTIONS, on the vendor API and the control plane, refused ones included.
  2. Every control operation, the boot’s reset and scenario included, as a control line. On Kalshi, a playing tape adds a control line with op replay per step.
  3. Every webhook delivery attempt, as a delivery line naming the receiver’s origin (never its path or query) and the address dialed or refused: Which receivers a simulator may reach shows one.
  4. No reads.

A request line:

{"seq":7,"kind":"request","wall":"2026-10-13T16:29:49.720243Z","received":"2026-10-13T16:29:49.719984Z","sim_clock":"2026-01-01T00:00:00Z",
 "data":{"method":"POST","path":"/v1/customers","template":"/v1/customers","actor":"member","status":200,
         "request":{"email":["ada@example.com"]},"response":{"id":"cus_…","object":"customer",…}}}
FieldWhat it is
seq1, 2, 3… for this process
kindrequest, control or delivery; on Kalshi, also fill, one per fill of an order a caller placed
wallwall time the line was written, UTC
receivedrequest lines: wall time the request arrived
sim_clockthe simulator’s clock
data.method, data.path, data.query, data.statusthe request and the status it got
data.template, data.actorvendor routes: the route it matched and the actor that sent it
data.request, data.responsethe bodies: a form as its fields, JSON as JSON, anything else as text; past 64 KiB, cut and marked …[truncated]
data.op, data.detailcontrol lines: the operation and its arguments
data.destination, data.address, data.refuseddelivery lines: the receiver’s origin and the address dialed or refused; data.refused is true for a refusal. An event’s delivery adds data.seq, data.attempt, data.endpoint, data.http_status and data.reason, as on the egress log
  1. Headers are never copied, so neither the admin token nor Authorization reaches the file.
  2. The caller’s API key is replaced by [redacted] wherever it appears in a body or query. On Stripe, that is a key sent as Authorization: Bearer; a key sent with curl -u is not redacted.
  3. A /_rystic/* request body (a seed, a schedule, credential bindings) is logged as {"omitted_bytes":N,"sha256":"…"}, not copied.
  4. The file is created readable by you only. A restart appends to it, with seq starting again at 1.
  5. A path the simulator can’t open stops it at boot with panic: rystic: RYSTIC_ACTION_LOG: open …: no such file or directory; rystic run -d exits 7.

Read it over HTTP

GET /_rystic/actions serves this process’s lines as application/x-ndjson, a page at a time. It needs the admin token when one is set.

curl -s -D headers.txt "localhost:$PORT/_rystic/actions?since=1&limit=1" -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN" | jq -c '{seq, kind, op: .data.op, detail: .data.detail}'
# -> {"seq":2,"kind":"control","op":"scenario","detail":{"frames":0,"name":"design_studio"}}
grep -i '^x-rystic' headers.txt
# -> X-Rystic-More: true
# -> X-Rystic-Next-Since: 2

Pass X-Rystic-Next-Since as the next since while X-Rystic-More is true. The route’s entry has its parameters and responses, including the 404 it returns when the action log is off.

Behind your own proxy

RYSTIC_GATEWAY_TOKEN makes every request carry X-Rystic-Gateway-Token; Boot configuration has what it does to rystic run and the image’s health check. With both tokens set, the proxy adds the gateway header to everything, and you add the admin header on top:

Request carries/_rystic/versionvendor APIcontrol routes
nothing403403403
the gateway token200served401
the admin token only403403403
both200servedserved
RYSTIC_GATEWAY_TOKEN=… RYSTIC_ADMIN_TOKEN=… \
  ~/.rystic/twins/stripe-twin/0.0.36/stripe-twin --addr 127.0.0.1:8080

The binary needs its API key (RYSTIC_TOKEN) or license (RYSTIC_LICENSE): Environment variables.

The URLs a simulator returns that lead back to it, such as links on the vendor’s hosts and file URLs, name the host the client sent in Host, and https when the request carries X-Forwarded-Proto: https. A proxy in front must pass the original Host through. RYSTIC_PRESERVE_SERVICE_URLS=1 keeps the vendor’s own hosts, for a simulator behind a transparent proxy; --intercept sets it. With it set, a request that arrives on a vendor host gets file URLs on the host the vendor serves files from, where that differs from its API host, as the vendor does: GitHub’s release-assets.githubusercontent.com.

Listen address

Started withListens on
rystic run --port 8080127.0.0.1:8080, this machine only
rystic run --port 8080 --bind 0.0.0.0, or RYSTIC_BIND=0.0.0.0every interface, *:8080
rystic run in the Rystic imageevery interface in the container; the ports it publishes decide who reaches it
the binary, with no --addr or RYSTIC_ADDR127.0.0.1:8080, this machine only
the binary, --addr 0.0.0.0:8080every interface
the binary, RYSTIC_ADDR=<host:port>that address; --addr wins over it
  1. rystic run sets the address from --bind and --port, even with --env RYSTIC_ADDR=…. --bind takes an IP address: 127.0.0.1 (the default), 0.0.0.0 or one interface’s address. RYSTIC_BIND sets the bind when --bind is absent:

    RYSTIC_BIND=0.0.0.0 rystic run stripe-twin -d --name reach --port 0 2>&1 >/dev/null | grep '^rystic: listen:'
    # -> rystic: listen: 0.0.0.0:..., every interface
    rystic stop reach >/dev/null
    RYSTIC_BIND=0.0.0.0 rystic run stripe-twin -d --name reach --port 0 --bind 127.0.0.1 2>&1 >/dev/null | grep '^rystic: listen:'
    # -> rystic: listen: 127.0.0.1:..., this machine only (--bind 0.0.0.0 listens on every interface)
    rystic stop reach >/dev/null
    
  2. Anyone who can reach the port reaches the control plane unless the admin token is set. Set it before you widen the address (Who can reach it).

  3. The log names the address and whether the control plane is locked, and rystic run -d says the same on stderr. The binary given no address listens on 127.0.0.1:8080, locked here by the token Set it up exported:

    RYSTIC_TOKEN=rys_… ~/.rystic/twins/stripe-twin/0.0.36/stripe-twin 2> twin.log & TWIN=$!
    until grep -q 'control plane' twin.log; do sleep 1; done
    grep -oE 'rystic: .*(listening on|control plane).*' twin.log
    # -> rystic: stripe-twin 0.0.36 listening on 127.0.0.1:8080 (model …)
    # -> rystic: control plane locked: its routes need RYSTIC_ADMIN_TOKEN
    kill $TWIN
    

Many clients, one simulator

Every caller acts as member until you say otherwise. Two ways to give each client its own actor:

  1. X-Rystic-Actor: <label> on the request. It wins over everything else.
  2. A credential binding: the client changes nothing but its key.
curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:$PORT/_rystic/credentials \
  -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN" -H 'Content-Type: application/json' \
  -d '{"bindings":{"sk_test_agent_a":"agent_a","sk_test_agent_b":"agent_b"}}'
# -> 204
curl -s localhost:$PORT/v1/customers -H 'Authorization: Bearer sk_test_agent_a' > /dev/null
curl -s localhost:$PORT/v1/customers -H 'Authorization: Bearer sk_test_agent_b' > /dev/null
curl -s localhost:$PORT/_rystic/calls -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN" \
  | jq -c '.calls[-2:][] | {actor, method, path, status}'
# -> {"actor":"agent_a","method":"GET","path":"/v1/customers","status":200}
# -> {"actor":"agent_b","method":"GET","path":"/v1/customers","status":200}
  1. A posted set of bindings replaces the last one. With "keep": true it adds only the credentials no binding holds yet, and a bound credential keeps its actor and grants. A key with no binding acts as member, and a reset clears every binding.
  2. A binding may be {"actor": "<label>", "grants": [...]}: the access the credential holds, from the grants the simulator declares. A simulator that declares none refuses any grant with 400.
  3. On Stripe, a binding matches a key sent as Authorization: Bearer, the way Stripe’s libraries send it. curl -u sk_test_agent_a: acts as member.
  4. GET /_rystic/calls lists every request since the last reset, reads included, with its actor and principal: the scenario user the actor maps to in the loaded scenario, or empty when there is none. The action log’s data.actor names the same actor.
  5. What an actor sees is each simulator’s own rule: Slack identities, Kalshi’s multiple bots, which also reads KALSHI-ACCESS-KEY.

A client that joins later can add its own key with "keep": true, and the bindings already made stay as they were:

curl -s -o /dev/null -w '%{http_code}\n' -X POST localhost:$PORT/_rystic/credentials \
  -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN" -H 'Content-Type: application/json' \
  -d '{"keep":true,"bindings":{"sk_test_agent_a":"intruder","sk_test_agent_c":"agent_c"}}'
# -> 204
curl -s localhost:$PORT/v1/customers -H 'Authorization: Bearer sk_test_agent_a' > /dev/null
curl -s localhost:$PORT/v1/customers -H 'Authorization: Bearer sk_test_agent_c' > /dev/null
curl -s localhost:$PORT/_rystic/calls -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN" \
  | jq -c '.calls[-2:][] | {actor, path}'
# -> {"actor":"agent_a","path":"/v1/customers"}
# -> {"actor":"agent_c","path":"/v1/customers"}
rystic stop shared

One simulator per client

Simulators share nothing, so a client or agent that must not see another’s writes gets a simulator of its own. Start one per client, each with its own --name and port:

A=$(rystic run stripe-twin -d --name agent-a --project agent-a --port 0 --json | jq -r .data.port)
B=$(rystic run stripe-twin -d --name agent-b --project agent-b --port 0 --json | jq -r .data.port)
curl -s localhost:$A/v1/customers -u sk_test_x: -d name=Ada | jq -r .object
# -> customer
curl -s localhost:$B/v1/customers -u sk_test_x: | jq '.data | length'
# -> 0
rystic down --project agent-a
# -> stopped agent-a
rystic stop agent-b
  1. --project labels a client’s simulators, so rystic ps --project, rystic clock --project and rystic down --project act on them together. It defaults to default.
  2. With --intercept, each project gets its own gateway, so two clients can each call api.stripe.com and reach their own simulator: Intercept vendor calls.
  3. rystic grid <product> -worlds <scenarios> -- <command> runs your command once per scenario, each against a fresh simulator, and reads its address from RYSTIC_ADDR. Grade agent runs runs an agent once per eval the same way, and grades each run.
rystic grid stripe-twin -worlds design_studio -out cells -- sh -c 'curl -s -o /dev/null "$RYSTIC_ADDR/v1/customers" -u sk_test_x:'
# -> grid: 1 bots × 1 ... through stripe-twin ...
# -> ...GRID GREEN — 1 cells, every bot held in every ...

File URLs

A simulator that stores files, such as Notion’s uploads and Jira’s attachments, serves them from itself under a signed /_rystic/files/ URL:

{"type":"file","file":{"url":"http://localhost:8080/_rystic/files/notes.txt?expires=1769907600003&key=…&resource=state_file_upload&signature=…","expiry_time":"2026-02-01T01:00:00.003Z"}}
  1. It expires after a lifetime the simulator sets, measured on the simulator’s clock. Every read returns a fresh one; on Notion, expiry_time says when it expires.
  2. It needs no admin token. Anyone holding the URL can fetch the file until it expires.
  3. Moving the clock past its expiry with POST /_rystic/clock expires it at once.

On a GitHub simulator booted with --intercept, a release asset download redirects to GitHub’s storage host instead of the host the client sent. Boot one in a project of its own, downloads, seed a release asset in tb-owner/tb-repo, and download it from api.github.com:

URL=$(rystic run github-pulls-twin -d --port 0 --intercept --name downloads --project downloads --scenario github-pulls_open_queue --json | jq -r .data.url)
curl -s -X POST "$URL/_rystic/seed" -H "X-Rystic-Admin-Token: $RYSTIC_ADMIN_TOKEN" -d '{"state_release_asset":{"tb-owner/tb-repo#7001":{"id":7001,"release_id":1,"repository":"tb-owner/tb-repo","name":"notes.txt","body_b64":"aGVsbG8K"}}}' -o /dev/null -w '%{http_code}\n'
# -> 204
rystic exec --project downloads -- curl -s -o /dev/null -w '%{redirect_url}\n' -H 'Accept: application/octet-stream' -H 'Authorization: Bearer ghp_anything' https://api.github.com/repos/tb-owner/tb-repo/releases/assets/7001
# -> https://release-assets.githubusercontent.com/...
rystic stop downloads >/dev/null
rystic gateway --stop --project downloads >/dev/null

/_rystic/files/{path} lists the URL’s methods, parameters and responses, including the 403 for an expired or edited URL. Notion → file uploads and Jira → attachments have the calls that store a file.

Last updated on