---
title: How Executor protects credentials
description: "Understand where Executor stores encrypted credentials on Local, Self-host, and Cloud, how browser connection links keep secrets out of agent chats, and how declared hosts keep raw secrets out of app code."
---

Executor encrypts saved account credentials at rest with **AES-256-GCM**, collects new credentials through one-time browser **connection links** so agents never handle secrets in chat, and — when a provider declares `hosts` in `defineProvider` — replaces raw secrets with short-lived opaque **credential handles** (`exsec_..._` or `exsec2_..._`) so app code cannot read or exfiltrate them.

Applies to **Local**, **Self-host**, and **Cloud**, with per-target key storage described below.

**Prerequisites:** If you are authoring or reviewing an app, declare `hosts` (and `request` placement where applicable) on every `defineProvider` call so Executor seals secret fields into handles rather than passing raw values into app code.

**You'll know it worked when:** Inside a deployed app whose provider declares `hosts`, reading `ctx.user.accounts.<slot>.fields.<secret>` returns an opaque `exsec_..._` or `exsec2_..._` handle, outbound `fetch` requests to a declared host succeed with the real credential attached, and requests to any undeclared host fail with `NetworkRefused` (`reason: "credential_host"`).

## Where credentials live

Every Executor target encrypts saved account fields using **AES-256-GCM** with a 32-byte (64-hex-character) key, a fresh 12-byte random IV on every write, and the account ID bound as additional authenticated data so ciphertext from one account cannot be substituted into another. Saved secret fields and OAuth client secrets are never returned to the browser or API callers after saving.

| Target | Where encrypted credentials are stored | Where the encryption key (`EXECUTOR_ENCRYPTION_KEY`) lives |
| --- | --- | --- |
| **Local** | SQLite database in `EXECUTOR_DATA_DIR`. | Stored in your **OS credential store** by default (macOS Keychain, Windows Credential Manager, or Linux Secret Service such as GNOME Keyring). If `EXECUTOR_KEY_STORAGE=file` is set (or no OS store is available on first start without `EXECUTOR_KEY_STORAGE=os`), keys are saved in `keys.json` inside `EXECUTOR_DATA_DIR`. Alternatively, supply both `EXECUTOR_API_KEY` and `EXECUTOR_ENCRYPTION_KEY` via environment variables; supplied keys are never written to disk. |
| **Self-host** | Your PostgreSQL database (or embedded `hosted.pglite` in `EXECUTOR_DATA_DIR`, `/app/data` in Docker). | Read from `EXECUTOR_ENCRYPTION_KEY` if set, or generated on first start and saved to `encryption.key` (mode `0600`) in `EXECUTOR_DATA_DIR`. |
| **Cloud** | Executor Cloud's database. | Managed as `EXECUTOR_ENCRYPTION_KEY` in Executor Cloud's server environment. |

Because each installation encrypts credentials with its own key, saved credentials do not copy or transfer between Local, Self-host, and Cloud.

## Connection links keep secrets out of agent chats

When an agent needs you to connect or reconnect an account, it never asks you to paste an API key or password into chat and never reads secrets from your files:

1. The agent calls the Executor management tool (`appAccounts.userConnect` or `appAccounts.appConnect` on Hosted; `appAccounts.userConnect` or `accountConnections.create` on Local).
2. Executor returns a pending **connection link** (`/org/<slug>/connections/<con_id>` on Hosted, `/connections/<con_id>` on Local) that expires after **30 minutes** and can be completed once.
3. You open the link in your browser and enter the secret fields or finish OAuth sign-in directly in Executor.
4. Executor encrypts and saves the account and links it to the app requirement in the same transaction.
5. The agent checks the connection state (`accounts.connection` on Hosted, `accountConnections.get` on Local) and receives only the status and account metadata (ID, label, provider) — never the entered secret fields or OAuth tokens.

## Declared hosts and what apps never see

When a provider declares `hosts` in `defineProvider`, Executor does not pass the raw secret string to app code:

- **Sealed handles:** Secret fields are encrypted with AES-256-GCM into opaque handles (`exsec_..._`, or `exsec2_..._` when the auth method declares `request` placement or uses managed OAuth) bound to that specific app ID, account ID, allowed `hosts`, and a **1-hour** lifetime.
- **Host enforcement:** When the app calls `fetch(...)`, Executor's outbound proxy inspects the request, opens each handle, verifies that the handle belongs to the calling app and has not expired, and verifies that the destination matches a declared host (exact hostname, optional `:port`, or single-level wildcard such as `*.example.com`). Any other host is refused with `NetworkRefused` (`reason: "credential_host"`).
- **Placement and HTTPS enforcement:** When an auth method declares `request` placement (such as `bearer(token)`, `basic(user, password)`, `header(...)`, or `query(...)`), or for managed OAuth credentials, Executor only substitutes the secret into the declared header or query parameter format (refusing it in the URL path, request body, or other headers: `credential_placement`) and requires **HTTPS** (`credential_transport`, allowing plain HTTP only for loopback hosts when private addresses are permitted).
- **Transport protections:** Requests using `TRACE` with handles are refused (`credential_method`), redirects are not automatically followed with credentials (`redirect: "manual"`), and hosted deployments with private-address egress blocking refuse private network hosts (`private_address`).
- **Response and error scrubbing:** Before returning a response to app code, Executor scans response headers and text, JSON, or form bodies (up to **1 MiB**) and replaces any echoed secret back with its opaque handle. Transport errors are scrubbed the same way.
- **Cross-app isolation:** Another app that receives a handle string cannot use it because the handle is bound to the original app ID (`credential_app`).
- **Agent isolation:** Agents calling an app's tools never receive saved credentials; even if an app with declared `hosts` returns its `account.fields`, the caller receives only a short-lived opaque handle that cannot be decrypted outside Executor.

## Example

Declaring `hosts`, a non-secret `plain` field, and `request` placement on a provider keeps the token sealed as an `exsec2_..._` handle and ensures Executor only sends it over HTTPS in the `Authorization` header to `api.example.com`:

```ts
import {
  base64,
  defineApp,
  defineProvider,
  header,
  object,
  plain,
  query,
  router,
  secrets,
  string,
  t,
} from "apps";

const service = defineProvider({
  name: "Example API",
  hosts: ["api.example.com"],
  auth: {
    key: secrets({
      label: "API token",
      fields: object({
        email: plain(string()),
        token: string(),
      }),
      request: ({ email, token }) =>
        header("authorization", t`Basic ${base64(t`${email}:${token}`)}`),
    }),
  },
});

export default defineApp({ user: { accounts: { service } } }, {
  tools: router({
    me: query({ input: object({}) }, async ({ user: { accounts } }) => {
      const response = await fetch("https://api.example.com/v1/me", {
        headers: accounts.service.headers(),
      });
      return await response.json();
    }),
  }),
});
```

In this app, `accounts.service.fields.email` is readable in code because it is wrapped in `plain(...)`, while `accounts.service.fields.token` is an opaque `exsec2_..._` handle. Attempting to send `token` to another host, in a JSON body, or over plain HTTP fails with `NetworkRefused`.

## Limits

- **Providers without `hosts` are not sealed:** If a provider omits `hosts` (and is not a managed OAuth credential), Executor passes its account field values directly to app code. Always declare `hosts` on providers whose credentials should stay hidden from app code.
- **`plain(...)` and `raw(...)` fields:** Fields wrapped in `plain(...)` (non-secret values such as email or region) or `raw(...)` (secrets app code must compute with directly, such as HMAC signing keys) are intentionally unsealed.
- **Response scrubbing size and media types:** Response body scrubbing applies to text, JSON, and `application/x-www-form-urlencoded` responses up to **1 MiB** (`1,048,576` bytes); binary bodies, event streams (`text/event-stream`), and bodies larger than 1 MiB are streamed through without body rewriting.
- **Handle lifetime:** Credential handles expire after **1 hour** and cannot be reused across apps (`credential_app`) or after expiry (`credential_expired`).
- **Connection link lifetime:** Pending browser connection links expire after **30 minutes** and fail if the app's requirement changed before submission (`AccountConnectionTargetChanged`).
- **Local key storage is fixed per data directory:** Executor never automatically moves keys between the OS credential store and `keys.json` after a directory is initialized.

## Related

- [Providers and accounts](/docs/concepts/providers-and-accounts)
- [Connect an account](/docs/connect-an-account)
- [Organizations and access](/docs/concepts/organizations-and-access)
- [Activity and tool call log](/docs/activity)
- [Author an app](/docs/author-an-app)
