Secrets
bhatti stores secrets encrypted per API-key owner. There are two ways to use one: inject its real value as a guest environment variable with create --secret, or grant a sandbox a placeholder for outbound HTTPS headers to named hosts. For agent code you don’t want to trust with the value itself, use grants.
Encryption and ownership
Section titled “Encryption and ownership”The server creates an age key at <data_dir>/age.key when it first needs to encrypt a secret. Values in the secret store are encrypted under that key. Back it up with the database: losing either loses access to your secrets. Host root and anyone who gets both the database and key can decrypt them. Secrets are scoped to an owner/API key; another owner cannot reference them. bhatti secret list prints names, never values. bhatti secret set NAME value replaces a value but there is no read-back command.
secret set accepts the value as a positional CLI argument, which can leak through shell history and local process listings. See secret set for precautions.
Plain environment injection
Section titled “Plain environment injection”bhatti secret set API_KEY 'your-key'bhatti create --name trusted-agent --secret API_KEYThe server decrypts API_KEY when it creates the sandbox and includes the plaintext in its boot configuration. lohar makes API_KEY=<real value> available to commands inside the VM. Code running in the guest can read this environment value and send it anywhere its network policy permits. Encryption at rest protects the stored value, not a copy injected into the guest. Memory snapshots may contain the real value. Updating/deleting the store’s entry does not retract a value already injected into a running sandbox.
A warm pause keeps guest RAM resident. Thermal cold and an explicit
bhatti stop instead power off
the VM: disk remains but processes and /tmp are gone. Neither is a
memory-preserving checkpoint; use an explicit named snapshot when you
need one. Plain secrets resolved at creation remain part of the
sandbox’s boot settings, not dynamically re-read from the store on
each wake. See Durability.
Host-scoped grant substitution
Section titled “Host-scoped grant substitution”bhatti secret set GH_TOKEN 'your-token'bhatti create --name bot --allow-host api.github.com --secret-grant GH_TOKEN@api.github.com# Or grant an existing networked sandbox:bhatti secret grant GH_TOKEN --sandbox bot --host api.github.com --ttl 7dAt creation, --secret-grant NAME@host[,host...] puts a placeholder in the guest environment variable named NAME. A later secret grant prints a placeholder that you must supply to the guest yourself (for example export GH_TOKEN=<placeholder>). Neither path hands the real secret to guest code. On an allowed HTTPS connection to a granted host, netd replaces that placeholder only in HTTP/1.1 request header values, after validating the upstream TLS certificate. A grant does not allow any new destination: create the sandbox with --allow-host for that destination (or --net if public egress is intended). With the default no-NIC policy, there is no gateway and grants cannot operate. HTTP bodies, URLs, arbitrary TCP protocols, and nonmatching hosts do not get substitution; this is not a general-purpose credential proxy.
Use bhatti secret grants to list active, expired and revoked grants and their IDs, then bhatti secret revoke ID to revoke one. Expiry is optional (--ttl 90m, 24h or 7d); a grant without TTL lasts until revoked or the sandbox is destroyed. Revocation blocks new connections; an already-open connection can keep its previously resolved value until it closes. Sandboxes created before v2.4 retain their old guest agent; recreate them if a grant fails with an upgrade-required response. See Credentials for agents for an end-to-end recipe and Networking internals for the interception boundary.
Env var priority
Section titled “Env var priority”For values provided at creation, defaults (PATH, HOME, TERM, LANG)
can be overridden by sandbox --env, which is in turn overridden
by a plain --secret with the same name (direct and template-based
creates). A plain secret and --secret-grant of the same name cannot
be combined; choose one mechanism per credential.
Templates and request flags
Section titled “Templates and request flags”--template uses the template’s defaults and merges request-side --secret and --file flags. Request-side secret names must exist; nonexistent names return an error instead of being silently ignored. Files supplied with --file local:guest are added at creation. See bhatti create.
Threat boundary
Section titled “Threat boundary”- A stolen database without
age.keycontains encrypted stored secrets; both files together expose them. A host root compromise is outside this boundary. - Plain
--secretputs the real value into guest RAM/environment; do not treat the guest as unable to read it. An explicit memory snapshot can capture it. - A grant limits where and how the placeholder can resolve, not what an authorized destination does with the secret. A compromised guest can spend a grant on approved HTTPS requests while it is valid. Keep hosts narrow, give the sandbox the minimum egress it needs, use TTL, and revoke when done.
See also
Section titled “See also”- Credentials for agents — practical grant workflow
- Secrets CLI — store and grant commands
- Network & egress — give a sandbox only the outbound connections it needs