> ## Documentation Index
> Fetch the complete documentation index at: https://docs.run.cloud/llms.txt
> Use this file to discover all available pages before exploring further.

# Credentials sync

> Sign in to your tools once, and keep your sandboxes signed in as the credentials rotate.

`runcloud credentials` reads the logins already on your machine (gcloud, AWS,
GitHub, Claude Code, or any file or command you name) and keeps them pushed to
[secret groups](https://docs.run.cloud/sandboxes/secrets.md). A sandbox that takes one of those groups
holds the current credentials, and keeps holding them as they rotate.

It works on macOS and Linux. It uses no server feature beyond secret groups, so
a sandbox takes the groups the way it always does:

```bash theme={null}
runcloud sandbox create --secret-group cloud-dev --secret-group agents
```

## The config file

Everything the sync does is listed in `~/.run-cloud/credentials.yaml` (mode
0600\). It is the whole contract: **what is in this file is exactly what leaves
your machine**, and nothing else is ever uploaded. Edit it by hand or with
`runcloud credentials add`.

```yaml theme={null}
groups:
  cloud-dev:                       # a secret group you name
    - preset: gcloud
    - preset: aws
      profile: admin
    - preset: github

  agents:
    - preset: claude

  stripe:
    - file: ~/.config/stripe/config.toml
      to: .config/stripe/config.toml
    - command: vault print token
      env: VAULT_TOKEN
      refresh: 30m

org: your-org-id                  # optional default org id; a group may set its own `org:`
```

A group can also be a mapping, when it needs options:

```yaml theme={null}
groups:
  cloud-dev:
    org: your-org-id               # an org id, not the org's display name
    credentials:
      - preset: gcloud
```

## Presets

| Preset | What it pushes |
| - | - |
| `gcloud` | Your application default credentials file (`~/.config/gcloud/application_default_credentials.json`), at the same path in the sandbox, and `CLOUDSDK_CORE_PROJECT` from `gcloud config get-value project`. Client libraries use the file. The `gcloud` command itself is not covered. With no project set, the file is still pushed and `status` shows a warning. |
| `aws` | Short-lived credentials from `aws configure export-credentials` for one profile (`profile`, default `default`), refreshed every 30 minutes, and `AWS_REGION`. It never pushes the SSO cache, so the laptop and the sandbox cannot sign each other out. With no region set for the profile, the credentials are still pushed and `status` shows a warning. |
| `github` | `GH_TOKEN` from `gh auth token`: whichever account `gh` is signed in as. |
| `claude` | `CLAUDE_CODE_OAUTH_TOKEN`. `add` runs `claude setup-token` for you (finish the sign-in it opens) and captures the token it prints; pass `--paste`, or run it without a terminal, to paste the token instead. `claude setup-token` shows the token on screen during sign-in, so run it where your screen is not shared or recorded, or use `--paste` with a token you created elsewhere. The token is stored in the macOS Keychain, in `secret-tool` on Linux when present, or in a 0600 file in `~/.run-cloud`. Nothing is stored until you confirm. |

Adding a preset checks that the tool is installed and signed in, and tells you
the login command to run if it is not.

## Your own entries

A custom entry has one source and one target.

| Key | Meaning |
| - | - |
| `file` | Read this file. `~` expands. The agent watches it for changes. |
| `command` | Run with `/bin/sh -c`. Standard output is the value. Standard error is never logged. |
| `format` | For a command: `raw` (default, one value; trailing newlines are removed, spaces are kept) or `dotenv` (`KEY=VALUE` lines, each becomes one secret). In `dotenv`, blank lines and `#` comments are skipped. Any other line that is not `KEY=VALUE`, or a key with an empty value, fails the entry. The message gives the line number only, never the line. |
| `env` | Push as this environment variable. |
| `to` | Push as a file at this path, relative to the sandbox's home directory. |
| `refresh` | How often a command reruns. Default `1h`, minimum `1m`. |
| `timeout` | Longest a command may run. Default `30s`. |
| `encoding` | `base64`, for a binary `file` (not allowed on a `command`). The sandbox receives the base64 text, not the bytes: decode it there, for example with `base64 -d`. |
| `name` | The secret's name in the group. By default the env name, or the file's name with a leading dot written as `dot-` (`.npmrc` becomes `dot-npmrc`). |

The usual [secret limits](https://docs.run.cloud/sandboxes/secrets.md#limits) apply, and the CLI checks
them before it sends anything. `SBX_` names are refused. A single item over
32 KiB is refused, and `status` warns when a group passes 48 KiB, because 64 KiB
is the limit for everything a sandbox takes.

## Commands

```bash theme={null}
runcloud credentials add cloud-dev gcloud
runcloud credentials add cloud-dev aws --profile admin
runcloud credentials add stripe --file ~/.config/stripe/config.toml --to .config/stripe/config.toml
runcloud credentials add vault --command "vault print token" --env VAULT_TOKEN --refresh 30m
runcloud credentials list                       # groups, entries, targets; never values
runcloud credentials push [group...]            # push now; --force ignores the change check
runcloud credentials status [--json]            # last push, refresh intervals, sizes, warnings
runcloud credentials remove cloud-dev           # a whole group, or pass an entry index
runcloud credentials sync                       # run the agent in the foreground
runcloud credentials sync --install             # run it in the background
```

`add` edits the YAML and keeps your comments and order. It prints what each
entry resolves to, asks `Push these to group <group>? [y/N]` (or pass `--yes`),
and then pushes that group right away.

`push` pushes only what changed since the last successful push, and prints one
line per group: pushed, unchanged, or the warning. `--force` pushes everything
again, which also repairs a secret someone deleted by hand. A group name that is
not in `credentials.yaml` is an error. A `push` with no group names also deletes
the secrets of groups you took out of the file.

`remove` deletes the secrets the sync pushed for that group or entry, and takes
them out of every running sandbox that takes the group. It deletes first: if a
delete fails, `remove` says which names failed, leaves `credentials.yaml` as it
was, and exits 1. Names it did delete are pushed again by the next push.
`--keep-remote` leaves the secrets in your org and only stops managing them.

`status` shows each group's last push, size and warnings, and how often each
command reruns (`refreshes every 30m`). A group that is still recorded but no
longer in the file shows as `no longer in credentials.yaml` until the next push
deletes its secrets.

Warnings, `status` and the agent log name an entry by its group, index and kind
(`group "stripe" entry 1 (command)`), never by the command text, which can hold
a credential.

## Before each sandbox

`runcloud sandbox create` and `runcloud sandbox shell` push first when the config
file exists. The push has a 10 second budget, and a failure is a one-line
warning: the command carries on. Set `RUNCLOUD_CREDENTIALS_PUSH=0` to turn it
off.

## The background agent

```bash theme={null}
runcloud credentials sync --install     # launchd on macOS, a systemd user unit on Linux
runcloud credentials sync --uninstall
```

The agent pushes at start, watches each file, reruns each command on its
`refresh` timer, and rereads the YAML every minute. After you edit the YAML it
pushes every group, so an entry or group you take out has its secrets deleted. A
failed push retries within 5 minutes. It logs group and entry names and
outcomes, never values or command text, to `~/.run-cloud/logs/credentials.log`.
It needs no `sudo`. The unit runs the same binary that installed it, with your
`PATH` recorded, so `gcloud`, `aws` and `gh` are found. Only one agent runs per
machine. While it runs, `sandbox create` and `sandbox shell` skip their own push.

The unit records the path of the Node binary that installed it. After you
upgrade or switch Node (for example with nvm), run
`runcloud credentials sync --install` again.

`--install` needs a stored login that does not expire, because the agent cannot
see your shell's environment and a browser login expires. Create a token and log
in with it:

```bash theme={null}
runcloud token create
read -rs RC_TOKEN && runcloud login --token "$RC_TOKEN" && unset RC_TOKEN
```

`read -rs` takes the token without echoing it and keeps it out of your shell
history. While `login` runs, the token is briefly visible to other processes on
your machine.

`--install` refuses, and says so, when the login comes only from environment
variables or has an expiry. `status` shows the same warning.

## Groups the sync did not create

A group you list is managed by the sync, so it takes care not to touch anything
it did not write:

* The first push into a group that already holds secrets the sync did not write
  is refused. Run `runcloud credentials push --adopt <group>` once to take it
  over.
* The sync deletes only names it wrote itself, never names it finds in the org.
* A failed read (a missing file, a command that errors or times out, empty
  output) pushes nothing for that entry and never deletes the names that entry
  owns. When the failed entry is a `dotenv` command, whose names come from its
  output, nothing in the group is deleted that run. The other entries are still
  pushed, and the group shows as failed. A credential in a group is never
  blanked by a local hiccup.
* A generated file name, with its `-2` suffix, depends only on the order of the
  entries in the YAML, never on which entries read.
* A failed push deletes nothing.

## What you should know

**Writing a secret needs the admin or owner role.** The CLI cannot check your
role up front, so a refused write says `admin or owner role required to write
secrets in this org`. When you set `org:`, it says `refused (403): needs admin
or owner role in this org, or org "<org>" is not one you belong to`: check that
`org:` is an org id you belong to. Ask an admin to push, or to change your role.

**Groups belong to the org, not to you.** Any admin can see a group's names, and
any sandbox in the org can take it. Name groups accordingly, and do not put a
personal credential in a group a colleague's sandboxes take.

**A pushed credential acts as you** wherever a sandbox uses it.

**Logging out locally does not revoke a pushed credential.** Remove it with
`runcloud credentials remove`, or rely on the provider's expiry. AWS role
credentials expire within hours. Google refresh tokens last until the account's
reauth interval.

**Removing an entry or a group takes the credential out of every running
sandbox that takes the group**, because secret groups [stay current](https://docs.run.cloud/sandboxes/secrets.md#groups-stay-current).

**Sync a group from one machine only.** Two machines syncing the same group
overwrite each other in turn, and nothing on the server can tell them apart.

**Nothing secret is kept locally besides your own files.** The state file
(`~/.run-cloud/credentials-state.json`) holds hashes, times, outcomes and the
names written. It never holds a value.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.