Skip to content

Operate a desk · How-to

Releasing the enclave

A release puts a new image of the desk into the one Phala Cloud CVM that runs every agent. The image is pinned by its digest, the compose file that names it is measured by dstack and approved on chain before the CVM may receive its keys, and every agent then records fresh evidence for the new code.

This page also covers the one-time setup, the image and compose file themselves, the secrets, rollback, key and wallet rotation, and backups, and says who signs what at each step. No release has been made, and the image has not been booted on a real confidential VM (Status): what follows is the procedure for the first release and every one after it.

Terms are defined in The enclave. Two more:

  • Release file: deploy/releases/<release>/release.json, the image digest and every non-secret setting for one release. ops/release-compose.ts turns it and deploy/docker-compose.template.yml into that release’s docker-compose.yml.
  • Safe: a multisig contract wallet. Here, a Safe on Base that owns the app’s DstackApp contract.

The operator is whoever runs the deployment: the Phala Cloud workspace, the image registry and the DNS zone. The Safe owns the app’s DstackApp contract on Base, so its signers decide which code may receive the app’s keys.

Step Who What
One-time setup operator, Safe the Safe on Base; the DstackApp deployment (one transaction); the Phala account and the CVM; DNS for the desk’s domain; a scoped Cloudflare token
Each release operator, Safe the image push, by digest (operator); addComposeHash(<hash>) on DstackApp (Safe); phala deploy --commit (operator)
After a release Safe optionally removeComposeHash(<old hash>), which ends rollback to it
Key epoch rotation Safe, operator addComposeHashAtEpoch(N+1, <hash>), then advanceAppEpoch(N) (Safe); a CVM restart (operator)
Wallet rotation operator ops rotate, and the gas it spends: up to five transactions from the agent’s wallets and one from the desk
Backup operator ops backup, and where the sealed archive is kept
Restore onto a replacement CVM operator, Safe a release with SA_RESTORE=1 (operator); addComposeHash(<hash>) for it (Safe); ops restore (operator)
Secrets operator, Safe the encrypted variables (operator); changing their names changes the compose hash and needs the Safe’s approval

Nothing in this procedure moves funds except a wallet rotation, which moves an agent’s own balances to its new key.

The Dockerfile builds the image in three stages:

Stage Base What it does
web node:24.14.0-bookworm-slim, pinned by digest installs every dependency from the lockfile with install scripts off, and builds the web app
build the same image installs the production dependencies only, without optional ones and with install scripts off, and copies src/, skills/ and the web build
runtime gcr.io/distroless/nodejs24-debian12:nonroot, pinned by digest the result: no shell and no package manager, running as user 65532, /data writable by that user, port 8080, src/bin/desk.ts as the command

.dockerignore lets only the package files, src/, skills/, catalog/, web/ and ops/build-web.ts into the build, and keeps a local web/dist out, so the web app in the image is always the one built inside it.

deploy/docker-compose.template.yml describes the CVM’s two services. It is a template: only the compose file ops/release-compose.ts writes from it is ever deployed.

  • shipped-agents, the desk: the image by digest; a read-only root filesystem; every Linux capability dropped and no privilege escalation; a 64 MB /tmp; dstack’s socket; the shipped-agents-data volume at /data; a 30-second stop grace; a health check on /health every 30 seconds after a 120-second start period; and Docker’s log files, up to five of 10 MB. Its environment holds every setting from the release file as a literal value, and the secrets as ${NAME}, filled from encrypted variables.
  • dstack-ingress, pinned by digest: it answers on port 443 for the release’s domain, obtains the TLS certificate inside the CVM through a Cloudflare DNS challenge, sets a CAA record for it, and forwards to the desk on port 8080.

Each client’s address travels in a PROXY protocol header from the gateway to the ingress and on to the desk, which reads it only from the network the two services share, so rate limits count each client rather than the ingress. The template writes the settings that go with this, SA_PROXY_PROTOCOL and SA_TRUSTED_PROXIES, itself.

These values reach the CVM as encrypted variables rather than in the measured compose, because they are secret:

Variable What it is
SA_ANTHROPIC_API_KEY the model key the agents and the brief screen use
SA_RPC_URL Robinhood Chain RPC endpoints, which can carry an API key
SA_RPC_URL_<chainId> RPC endpoints for each other chain agents pay on, such as SA_RPC_URL_8453 for Base
SA_EMAIL_API_KEY, SA_EMAIL_WEBHOOK_SECRET the mail provider’s key and webhook secret; empty when the desk has no mail
SA_ALERT_WEBHOOK_SECRET the secret, at least 32 characters, that signs each event sent to SA_ALERT_WEBHOOK_URL; empty when no alert webhook is set (Alerts)
SA_BLOCKED_PAYEES the payees agents may never pay
CLOUDFLARE_API_TOKEN dstack-ingress’s token for the DNS challenge

Every deployment sets SA_BLOCKED_PAYEES, a comma-separated list of addresses agents may never pay, or empty to block none. An agent’s payment to one of them is refused before anything is signed (payee_not_allowed), a skill that names one as a payee is not loaded or installed, and the catalog refuses a product that names one. Outside development mode the setting is required: the release compose stops the whole app when the encrypted variable is not set at all, and the desk refuses to start without it. The list is never written to the compose file, the logs or any public output.

No other encrypted variable may be added. The measured compose admits the secrets in this table and nothing else, each only on the line of its own name, and the desk refuses to boot on a compose that admits more (The enclave).

None of these is in the compose hash, so whoever deploys can change them without the Safe. What that allows is in The enclave. At boot the desk refuses to start if any other setting arrives as an environment variable instead of in the measured compose.

These steps set up the on-chain key service on Base, where new code gets keys only after the app’s Safe approves its compose hash; The enclave compares it with Phala Cloud’s default key service.

  1. Safe on Base. The app contract lives on Base, whatever chain the agents work on, so the Safe that owns it is on Base too. Do not transfer the app contract to an address nobody controls: the CVM would be frozen on its current code.

  2. CVM on the on-chain KMS. Deploy the first release (below) with:

    phala deploy -c deploy/releases/<release>/docker-compose.yml -n shipped-agents \
    --kms base --image dstack-0.6.5 -t tdx.medium --node <node> \
    --no-public-logs --no-public-sysinfo --no-pre-launch-script \
    -e SA_ANTHROPIC_API_KEY=... -e SA_RPC_URL=... -e SA_RPC_URL_8453=... -e SA_EMAIL_API_KEY= -e SA_EMAIL_WEBHOOK_SECRET= \
    -e SA_ALERT_WEBHOOK_SECRET= -e SA_BLOCKED_PAYEES=... -e CLOUDFLARE_API_TOKEN=... --prepare-only

    The mail secrets and SA_ALERT_WEBHOOK_SECRET are passed empty when the desk has no mail or no alert webhook.

    • --kms base: key release is governed by the app’s own DstackApp on Base, not by Phala’s backend.
    • --image dstack-0.6.5: the code needs dstack’s v1 guest API (0.6.0 or later), and 0.6.5 is the image both on-chain KMS contracts allow. Never let the image be chosen automatically, and never move to a 0.5.x image: v1 keys do not exist there and the sealed wallets would not open.
    • --no-pre-launch-script: Phala’s default script logs in to registries, runs docker compose pull and prunes images and volumes on every boot. The desk pulls public images by digest and needs none of it.
    • --no-public-logs, --no-public-sysinfo: the CVM’s container logs and system information are not published. public_tcbinfo stays on so Phala’s Trust Center and outside verifiers can read the attestation.
    • Turn on PROXY protocol for port 443: "port_policy": {"ports": [{"port": 443, "pp": true}]} in the app compose, which is Phala Cloud’s “Proxy protocol (pp)” switch on that port (dstack-gateway and guest 0.5.9 or later, which dstack-0.6.5 is). It is part of the app compose, so the compose hash covers it. The ingress takes each client’s address from it and refuses a connection without it.
    • Keep --fs at its default (zfs) and never use --ephemeral-data-disk, which wipes the data disk on every boot.
    • Exactly one instance: the desk keeps state in sqlite on the data disk and the gateway has no session affinity.

    --prepare-only prints the compose hash and a commit token. The Safe executes KmsAuth.deployAndRegisterApp(...) with that hash (Phala’s “Multisig and Governance” page has the exact calldata), then phala deploy --commit --token <token> --transaction-hash <tx>. The app id is the new contract’s address.

  3. DNS for the desk’s domain (the release file’s domain, desk.shippedagents.com here), in Cloudflare with the proxy off:

    • CNAME desk.shippedagents.com -> gateway.<gateway domain>
    • TXT _dstack-app-address.desk.shippedagents.com -> <app_id>:443

    dstack-ingress sets a CAA record that only its own Let’s Encrypt account (created inside the CVM) may issue for the name. The Cloudflare token needs Zone:Read and DNS:Edit on that zone only.

  4. Guest agent port 8090 (Phala dashboard, Domains): open it if outside verifiers and Phala’s Trust Center should read the attestation directly. The evidence documents carry everything without it.

  5. Pins to publish once the CVM runs: the app id, the Base KMS’s id, the OS image hash, and the MRTD and RTMR0-2 the first agent’s quote shows, checked against dstack-mr measure -c 2 -m 4G for dstack 0.6.5’s metadata.json. Readers pass them to npm run cli -- verify agent <agentId> --pins <file> or verifyAgent({ pins }); Runtime evidence, field by field says where each value comes from.

git status --short # clean tree; build from a fresh worktree of the release commit
export SOURCE_DATE_EPOCH=$(git log -1 --format=%ct)
docker buildx build --platform linux/amd64 --build-arg SOURCE_DATE_EPOCH --provenance=false --sbom=false \
--output type=image,name=<registry>/shipped-agents:<release>,rewrite-timestamp=true,push=true .
docker buildx imagetools inspect <registry>/shipped-agents:<release> # the digest to pin

--provenance=false and --sbom=false keep Docker from attaching attestations to the pushed image, so the digest names the image alone. Build twice from the same commit and compare the digests; if they differ, compare the two images with diffoci before trusting either. CI makes the same check on every change: it builds the image twice from scratch with these flags, SOURCE_DATE_EPOCH and rewrite-timestamp, and fails when the two image manifests differ. Check the runtime before pinning it:

docker run --rm --read-only --entrypoint /nodejs/bin/node <image>@sha256:<digest> --version # v24
docker run --rm --read-only --tmpfs /tmp -e SA_DEV=1 -e SA_HOST=0.0.0.0 -e SA_DATA_DIR=/tmp/data -e SA_ENGAGEMENT_REGISTRY=<registry> -p 8080:8080 <image>@sha256:<digest> &
curl -s localhost:8080/health # {"ok":true}

In development mode the desk listens on 127.0.0.1 only, so a desk in a container reached through a published port needs SA_HOST=0.0.0.0.

Continuous integration builds the image for linux/amd64 on every push to main and every pull request. It checks that the image runs Node and holds the web build, boots the desk from it read-only in development mode against a local chain (the health, readiness, record and web routes have to answer, and the desk has to stop cleanly), and builds it a second time to compare. It does not push the image.

mkdir -p deploy/releases/<release>
cp deploy/release.example.json deploy/releases/<release>/release.json # fill in the digest and settings
node ops/release-compose.ts deploy/releases/<release>/release.json

It prints the path of the compose file it wrote and the file’s sha256.

The release file names the release, the image by digest, the desk’s domain, the gateway’s domain and the settings: SA_PUBLIC_URL, SA_CHAIN_ID, SA_ENGAGEMENT_REGISTRY, SA_REGISTRY_FROM_BLOCK, SA_REVENUE_WALLET, SA_TREASURY and SA_DATA_DIR are required, and so are the four prices, because a release never runs in development mode. The script writes every setting into the compose as a literal value, adds an SA_RPC_URL_<chainId> secret for each chain the desk knows besides its own (Base, unless SA_CHAINS adds more), and refuses:

  • an image not pinned by digest, in the release file or anywhere in the template;
  • a secret in the release file (it says to pass it as an encrypted variable);
  • SA_DEV, and an SA_PUBLIC_URL that is not https;
  • a missing required setting, and any value the desk’s own configuration loader rejects;
  • a setting the desk does not read (“NAME is not a setting the desk reads.”);
  • caps, a dollar total, dollar assets or chains the desk’s spending policy would refuse at boot, with the policy’s own message;
  • an SA_DATA_DIR outside the volume mounted at /data, where the sealed keys and the store would not survive a restart, and an SA_PORT other than 8080, the port the template routes to and checks;
  • a setting the template writes itself, such as SA_TRUSTED_PROXIES;
  • SA_HOST: a release leaves it out, so the desk listens on every interface and the ingress reaches it;
  • a value with a single quote, a dollar sign, a backslash or a character outside printable ASCII, and any setting the compose would read from the environment.

Spaces and double quotes are allowed, so JSON settings such as SA_CAPS and SA_LIMITS can be released; a value that holds a double quote is written single-quoted. Commit the release file and the generated compose.

phala deploy --cvm-id <id> -c deploy/releases/<release>/docker-compose.yml --prepare-only

It prints the compose hash (sha256 of the app-compose.json Phala will boot) and a commit token valid for 14 days. Save the hash as deploy/releases/<release>/compose-hash.txt and commit it. The Safe then calls addComposeHash(0x<hash>) on the app’s DstackApp (on Base, address = app id). Until it does, the KMS gives the new code no keys.

phala deploy --cvm-id <id> --commit --token <token> --transaction-hash <safe tx>

The CVM restarts on the new compose with the same app id, data disk and keys. At boot the desk checks that the compose hash dstack reports is the sha256 of the app compose it serves, refuses to start if any setting differs from the measured compose or arrives from the environment instead, and re-seals anything sealed under older key epochs.

Each agent’s evidence names the compose hash it was produced under, so after an upgrade every agent needs fresh evidence and a new runtime record from the desk (gas only, paid by the desk). The agent pool does this on its own: on every pass of its loop it renews evidence that names another compose hash than the one running, that is older than 20 days, or whose hash the Engagement Registry does not hold because recording it did not go through. One agent’s failure does not hold up the others; it is logged as pool: agent not attested and retried on the next pass, and ten minutes of it raise the attestation_failing alert. npm run cli -- ops attest <agentId> renews one agent’s evidence at once (Operate a desk). Then check each agent:

npm run -s cli -- verify agent <agentId> --pins pins.json # Measurement shows the new compose hash

Once every agent verifies, the Safe may call removeComposeHash(0x<old hash>). That blocks a rollback to the old code and stops it from ever receiving keys again. Keep it allowed for as long as a rollback should stay possible.

While the old hash is still allowed: phala deploy --cvm-id <id> -c deploy/releases/<old>/docker-compose.yml, then re-attest every agent. If the old hash was removed, the Safe adds it again first. Sealed files keep their format across releases, so the old code opens what the new one sealed, unless the new one also moved the keys to a newer epoch: the old code then asks for the new epoch’s key, which works as long as the old hash is allowed at that epoch.

Rotate the app’s key epoch after a suspected leak of a derived key, or on a schedule. Rotation protects what is sealed afterwards; anything an attacker already copied stays readable with the old key, so a suspected leak of wallet keys also needs a wallet rotation.

  1. The Safe allows the running compose hash at the next epoch: addComposeHashAtEpoch(N + 1, 0x<hash>). It stays allowed at epoch N, which the desk needs once to open what was sealed there.
  2. The Safe calls advanceAppEpoch(N) (the argument is the current epoch, so a repeated transaction cannot advance twice).
  3. Restart the CVM (phala cvms restart <id>). At boot the desk asks for the new epoch’s key and re-seals every file sealed under an older epoch.
  4. Optionally the Safe removes the hash from epoch N: removeComposeHashAtEpoch(N, 0x<hash>).

Phala rotates the KMS root epoch itself (it did on 20 November 2026). The desk handles a root rotation the same way at its next boot, as long as the KMS still serves the old root epoch for this app.

Rotate an agent’s wallet when its key may have leaked, or when its sealing key was rotated after a leak:

npm run -s cli -- ops rotate <agentId> <reason>

The desk refuses while the agent has tasks in flight or a delivered job waiting for its reviewer, because those are bound to the old wallet (409 busy), and for a retired agent (409 retired). Otherwise it records the new key’s name first, so a rotation cut short finishes with the same key, and then, reading the chain before each step:

  1. creates the new key, sealed, inside the CVM;
  2. transfers the agent’s ERC-8004 identity from the old key to the new one (the transfer clears the agent wallet);
  3. moves the old key’s USDG to the new key;
  4. moves its gas, less the fee for that transfer, when the balance is more than twice that fee;
  5. sets the new key as the agent wallet with setAgentWallet, signed by the new key itself (EIP-712, domain ERC8004IdentityRegistry version 1 on chain 4663, valid until 240 seconds after the latest block’s time);
  6. names the desk as provider again, with the desk’s signature, sent from the new key (an owner change clears it);
  7. records fresh evidence for the new wallet, which the desk sends;
  8. retires the old key, which stays sealed under keys/retired/ in case funds arrive later.

That is up to five transactions from the agent’s wallets and one from the desk. The answer lists the steps taken; Operate a desk shows one.

If a step fails, the desk answers 502 rotation_incomplete with the reason; run the same command again and it carries on from the step it reached. Rotation was rehearsed against the live Identity Registry on a fork of Robinhood Chain (SA_FORK_TEST=1 npm test) and run from ops rotate on a development desk on a fork.

The data volume holds the sealed keys and notes and the sqlite store. dstack’s disk encryption is bound to the instance, so a copy of the raw disk is useless elsewhere; Phala does not document what happens to the disk if the node fails. Take a backup before and after every release:

npm run cli -- ops backup --out desk-backup.sealed
Wrote a sealed backup of 571195 bytes to desk-backup.sealed.

The desk stages the backup on the data volume itself: a .backup-<random> folder of hard links to its files, and a copy of the store from a sqlite read snapshot taken in the same step, so the store and the ledgers are from one moment. It streams the archive as it seals it under the app’s key (format shipped-agents/backup/v2: a start frame, the files in sealed chunks of at most 1 MiB, an end frame) and removes the staging folder when the stream ends. Sealed files go in as they are; the store and the ledgers are encrypted by the archive itself. The CLI writes the stream to <file>.part with mode 0600 and keeps the file only once the end frame has arrived. The archive opens in any CVM of the same app whose compose hash the KMS allows at the archive’s epochs, so it can be kept anywhere, including off Phala. Backups has the details and the log lines.

A backup is restored into a CVM of the same app: a replacement instance under the same DstackApp, never a new app, whose keys differ. The desk restores only when it starts with SA_RESTORE=1 on an empty data volume, and it then waits for the backup before it creates any key. SA_RESTORE is a measured setting, so the release that sets it is a release like any other, approved by the Safe.

  1. Write the restore release. Copy the release file of the code to run, set "SA_RESTORE": "1" in its settings with SA_OPERATORS naming at least one operator wallet (the desk refuses to start without one), and write the compose with node ops/release-compose.ts.

  2. Approve its compose hash. Get the hash with phala deploy ... --prepare-only as for any release; the Safe calls addComposeHash(0x<hash>). A backup sealed under an earlier app key epoch opens only while this hash is also allowed at that epoch (addComposeHashAtEpoch).

  3. Deploy it to the replacement CVM with phala deploy --commit, with the same encrypted variables as before. The desk starts on the empty data volume and waits: /ready answers 503 with one failing check, restore, and every other route answers 503 restoring.

  4. Send the backup from a machine that holds an operator key:

    SHIPPED_AGENTS_URL=https://<the desk's domain> npm run cli -- ops restore desk-backup.sealed

    The answer is {"restored": {"at": <when the backup was taken>, "files": <n>}}. A refused archive answers 400 bad_backup with the reason and leaves the data volume empty, so the desk keeps waiting for a whole one. The desk re-seals an archive from older epochs under the current ones, then starts from the restored data with the same wallets and agents.

  5. Verify. /ready reports the desk’s own checks again, npm run cli -- ops agents lists the agents, and ops alerts shows anything that needs a person. The restore release has its own compose hash, so the pool renews every agent’s evidence as after any release; then run npm run -s cli -- verify agent <agentId> --pins pins.json for each agent (Re-attest every agent).

On a data volume that holds a desk, SA_RESTORE=1 does nothing and the desk starts as it is. Whether later releases keep it is the owner’s decision; the code allows both:

  • Kept at 1: a desk whose data volume is lost waits for a backup instead of starting a fresh desk with new keys, wallets and agents.
  • Set back to 0: an empty data volume starts a fresh desk. Restoring then needs a release with SA_RESTORE=1 first.

Either change is a release whose compose hash the Safe approves. In development mode, copy dev-seal.key into the new data directory before the desk starts: it is the key that opens the archive, and the archive leaves it out (Restore a backup).