# Secrets

This page says how an app gets the values its code reads from
`process.env` and what the platform keeps of them (the name, the targets,
who set it and when; never the value). It teaches `durable-sdk secrets
set|list|rm`.

## Set

```bash
printf '%s' "$STRIPE_KEY" | durable-sdk secrets set STRIPE_KEY
durable-sdk secrets set STRIPE_KEY --value-file ./stripe.key
durable-sdk secrets set STRIPE_KEY --target preview < preview.key
durable-sdk secrets set STRIPE_KEY --redeploy < stripe.key
```

The value comes from stdin or `--value-file`, never an argument (an
argument lands in your shell's history). The CLI sends it in the JSON
body of `PUT /apps/:slug/secrets/:name { value, targets?, redeploy? }`
over TLS. The platform seals the value before any run, the run's one
step unseals it, writes the project's sensitive variable for the
targets named and deletes the sealed row in the same step. The run's
test proves no ledger image, output or log line carries the value.

- `--target production,preview` names the environments; both by
  default. A preview deployment reads the `preview` target.
- A change applies at the next build. `--redeploy` makes one from the
  current production deployment at once ([Deploy](https://durablesdk.com/docs/hosting/deploy.md#reading-promoting-cancelling-redeploying)).
- A name is `[A-Z][A-Z0-9_]*`. The platform's own variables are reserved
  and refused by name (`plane.secret.reserved`): `DATABASE_URL`,
  `DATABASE_URL_UNPOOLED`, `CRON_SECRET`, `ADMIN_TOKEN`,
  `ADMIN_READ_TOKEN`, `CONSOLE_SESSION_PUBLIC_KEYS`, every `DURABLE_*`
  ([Environment variables](https://durablesdk.com/docs/reference/environment-variables.md)).

## List

```bash
durable-sdk secrets list
```

```text
NAME         TARGETS              SET BY            SET AT
STRIPE_KEY   production,preview   user:8f3a…        2026-10-28T12:04:31Z
```

The list is `GET /apps/:slug/secrets`: names and stamps. There is no
read of a value, on the API, the dashboard or the CLI; the platform
holds none.

## Remove

```bash
durable-sdk secrets rm STRIPE_KEY
```

The variable is removed from the project; the running deployment keeps
the value it was built with until the next build.

## Reading a secret in a workflow

A value read from the environment inside a step stays out of the ledger
when it is a `Secret`:

```ts
import { defineWorkflow, Secret } from "@durable-sdk/core";

export const chargeOnce = defineWorkflow({
  name: "charge.once",
  version: 1,
  describe: "Charges a customer once per order.",
  key: ["orderId"],
  example: { orderId: "o1" },
  async run(ctx) {
    return ctx.step(
      "charge.once.charge",
      async () => {
        const key = new Secret(process.env.STRIPE_KEY ?? "");
        const response = await fetch("https://api.example.com/charges", {
          method: "POST",
          headers: { authorization: `Bearer ${key.reveal()}` },
          body: JSON.stringify({ order: ctx.input.orderId }),
        });
        const { id } = (await response.json()) as { id: string };
        return { chargeId: id };
      },
      { irreversible: "a charge is refunded by a person", effect: "provider" },
    );
  },
});
```

The serializer refuses a `Secret` in a step's output and the logger
refuses one in a line; a value read at module load, outside a step, is
a finding of `durable-sdk doctor --host`. [Steps and undo](https://durablesdk.com/docs/guide/steps-and-undo.md)
has the rule and [Ledger and data](https://durablesdk.com/docs/concepts/ledger-and-data.md) the
redaction policy.

## Scope

`secrets set` and `rm` need a key of scope `deploy`; `list` needs
`read`. [Accounts and keys](https://durablesdk.com/docs/operate/accounts-and-keys.md).

---

Prompt for an agent:

```text
Read https://durablesdk.com/docs/hosting/secrets.md, then set, list and remove an app's secrets on durablesdk.com; run durable-sdk doctor --host before and after; a refused line is a refusal id: durable-sdk explain <id>
```
