Secrets in machines
A secret lives on the host. A VM gets nothing of it unless the vm (or its template) lists it under secrets, and each entry says how the machine may use it. The list is on the host, where nothing in the machine can change it. Pick the narrowest way that works for the program in the VM.
credential |
proxy |
resource |
|
|---|---|---|---|
| the VM holds the value | no, a stand-in | no | yes |
| the client needs | a variable and HTTPS to the secret’s hosts | a base URL setting | nothing special |
needs inject on the secret |
yes | yes | no |
needs daemon: true |
no | yes | yes |
| WebSockets and bodies over 8 MiB | no | yes | the program holds the value |
| a change | credential recreates or restarts the machine |
in place | in place |
The three combine in one entry. The host’s own use of a secret, in a process’s env, is described on Secrets.
credential: the driver substitutes it
Section titled “credential: the driver substitutes it”The guest gets a stand-in in a variable, and smolvm replaces it with the value on HTTPS requests to the secret’s inject.hosts. The value never enters the VM.
secrets: - secret: ${ secret.github } # inject: { hosts: [api.github.com] } credential: GITHUB_TOKENWith the default header, Authorization: Bearer {value}, the guest writes the header itself, for instance curl -H "Authorization: Bearer $GITHUB_TOKEN" https://api.github.com/user. With another header or value, smolvm sets that header to the formatted value. The value is handed to smolvm machine start in its environment at every start and is in no argument, file, status or journal line. A start whose secret has no value fails, naming the variable and the secret.
The driver’s limits: HTTP/1.1 toward the guest, no WebSockets on a bound host, bodies up to 8 MiB and port 443 only. A credential also turns the machine’s network on. With an egress allow list, the secret’s inject.hosts are added to it, so a credential always reaches its hosts. A driver that cannot substitute credentials reports a credential entry as an error.
Only credential entries touch the machine. The binding, which is the variable, the secret, its hosts and its header, is part of the machine: a changed binding recreates it (an Error with persistent: true). A rotated value or a changed value format stops the machine and starts it with the new value.
proxy: the host’s gateway
Section titled “proxy: the host’s gateway”A process in the VM calls the secret’s gateway at the same URL as on the host, http://<name>.<namespace>.secret.runy.localhost (http://<name>.secret.runy.localhost at the top level), on the machine’s own runy proxy. The daemon inside carries the request over its link to the host, which forwards it to the secret’s host with the header set. The VM sends only the secret’s name and the path, never a host.
secrets: - secret: ${ secret.anthropic } # inject: { hosts: [api.anthropic.com], header: x-api-key, value: "{value}" } proxy: truePoint the client at the gateway inside the VM, for instance ANTHROPIC_BASE_URL=http://anthropic.secret.runy.localhost. A secret of the same name with inject in the machine’s own workspace publishes that URL as status.url, so a process there can read it with ${ secret.anthropic.status.url }, also when the host grants it only with proxy: true.
Everything the gateway guide lists applies: only the first of inject.hosts is served, bodies stream, WebSockets work, redirects are not followed and a browser’s request is refused before it is sent. Any process in the VM can spend the credential while the entry is there.
When the host refuses (no entry with proxy: true, or the secret does not run with inject), the guest answers 403 with one fixed message that does not say which check failed. A host the guest cannot reach within 15 seconds is 502, and a machine that is not linked yet answers 404 for the name.
The machine’s daemon serves a gateway name itself only for a secret it resolved by itself, from its own key, command, file or env. A secret whose value came from the host (source: hub, see below) leaves its name to the host, so its requests go out from the host with the host’s value, and only with proxy: true on the entry: resource: true alone gives the value to the resources inside and the gateway answers 403.
Claude Code in a machine
Section titled “Claude Code in a machine”Claude Code can use a Claude subscription in a machine without the machine holding the token. Run claude setup-token on the host and store its token as a top-level secret named claude (runy secret set claude), served on the gateway for the Anthropic API with the default header, Authorization: Bearer {value}:
kind: secretname: claudespec: inject: hosts: [api.anthropic.com] # encrypted: ... (written by `runy secret set claude`)---kind: vmname: sandboxspec: secrets: - secret: ${ secret.claude } proxy: trueIn the machine, point Claude Code at the gateway and give it any token; the gateway replaces the Authorization header with the real one:
export ANTHROPIC_BASE_URL=http://claude.secret.runy.localhostexport CLAUDE_CODE_OAUTH_TOKEN=any-stand-inAn interactive claude also needs {"hasCompletedOnboarding": true} in ~/.claude.json, or it asks for a login before it uses the token; claude -p works without it. Put the variables in a file under /etc/profile.d and the flag in the machine’s build and refresh steps (a template’s, for instances) so every shell and every new machine has them.
resource: the value, for the resources inside
Section titled “resource: the value, for the resources inside”Resources in the machine’s own workspaces can read the secret with ${ secret.<name> } from a secret document of their own, which must have the same namespace and name as on the host. When that document’s encrypted value does not decrypt in the guest, because the guest has no key or its key is not a recipient, the daemon inside asks the host for the value. Only an encrypted source asks the host: command, file and env resolve in the guest as anywhere.
secrets: - secret: ${ ns.notes.secret.db } resource: trueThe secret then shows source: hub inside, and its value is kept in that daemon’s memory only. The host answers only when the vm’s current spec has an entry with resource: true for that secret and the secret has a value there. Anything else is refused with one message that does not say why, and the guest secret’s error says to add the entry. A refusal, an unreachable host and a machine whose link is not up yet are asked again with a pause that grows from 1 second to 60, and on restart.
Use it when a program needs the value itself, such as a database password or a signing key. The value is in the VM: any root process there can read it.
A config file in a machine
Section titled “A config file in a machine”A program in the VM that reads its keys from a config file gets one from a file resource in the machine’s own workspace. Grant each secret with resource: true on the host:
kind: vmname: sandboxspec: daemon: true secrets: - secret: ${ secret.openai } resource: true - secret: ${ secret.anthropic } resource: trueand declare the secrets and the file in the workspace inside the VM:
kind: secretname: openaispec: encrypted: | -----BEGIN AGE ENCRYPTED FILE----- ...---kind: secretname: anthropicspec: encrypted: | -----BEGIN AGE ENCRYPTED FILE----- ...---kind: filename: configspec: path: config/local.toml content: | openai_api_key = "${ secret.openai }" anthropic_api_key = "${ secret.anthropic }"The daemon inside asks the host for each value, the file stays Pending until both arrive, and the values end up in the file in the VM, readable by its owner (mode 0600) and by root there.
Templates and instances
Section titled “Templates and instances”A template may list secrets. Its instances inherit the entries and may add their own, and an instance’s entry for a secret replaces the template’s entry for the same secret. The template’s builder machine gets no secret, since its disk is packed and every instance starts from it, so a build has no secrets, and a change of secrets never makes a build stale.
Agents
Section titled “Agents”An agent has no secrets key, so the requests of the daemon on an ssh machine over the link are always refused.
What the journals say
Section titled “What the journals say”Every request of a machine over the link is written to the vm’s journal and to the secret’s journal, never with the value:
machine sandbox asked for secret _/db over the hub: grantedmachine sandbox asked for the gateway of secret _/anthropic over the hub: refusedA gateway request that goes through is in the secret’s journal with machine sandbox as its caller.

