# Disk, secrets & databases

> Index of all pages: https://anywhere.so/llms.txt

Every worker runs on its own persistent ZFS Linux disk inside an isolated gVisor sandbox. Nothing on another user's worker or your other workers can read your disk or secrets.

## Persistent disk layout

Keep code and durable state cleanly separated:

| Path                           | Survives sleep | Survives deploy                              | What to put here                                                                                                  |
| ------------------------------ | -------------- | -------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `/app/`                        | Yes            | Uploaded paths overwritten; other files kept | Your `anywhere.toml`, prompts, scripts, and dependencies installed by `build`.                                    |
| `/app/data/`                   | Yes            | Yes (keep `/data/` in `.gitignore`)          | Git clones, SQLite databases, agent memory notes, and CLI sign-in folders (`/app/data/claude`).                   |
| `/tmp/`                        | Yes            | Yes                                          | Temporary files. Note that `/tmp` lives on the worker's persistent disk, so remove large scratch files when done. |
| `$ANYWHERE_RUN_DIR/artifacts/` | Yes (50 runs)  | Yes                                          | Deliverables uploaded to Postgres at run end (`index.html`, `summary.md`, `transcript.jsonl`, JSON/CSV).          |

Add `/data/` and `*.db*` to `.gitignore` so `anywhere deploy` never overwrites live state on disk. Deploys overwrite uploaded paths and never roll back; copy files down anytime with `anywhere pull`:

```sh
anywhere pull triage /app/data ~/.anywhere/workers/triage-data
```

### SQLite on the worker's disk

SQLite works directly on the persistent disk with zero extra service. Enable WAL mode and a busy timeout when multiple triggers touch the same database:

```sql
PRAGMA journal_mode = WAL;
PRAGMA synchronous = FULL;
PRAGMA busy_timeout = 5000;
```

## Encrypted secrets

Store API keys, tokens, and connection strings in the encrypted vault rather than files or `anywhere.toml`. Secrets live at two levels in both personal and team workspaces:

- **Workspace secrets** are encrypted with a per-workspace AES-256-GCM key and shared across workers in that workspace. Give each workspace secret either `all` scope (shared with every current and future worker, such as `ANTHROPIC_API_KEY`) or `selected` scope (attached only to specific projects or workers, keeping sensitive keys like `STRIPE_SECRET_KEY` away from untrusted webhook workers).
- **Worker secrets** are encrypted with a per-worker AES-256-GCM key and apply to one worker. Setting a worker-local secret with the same name as an inherited workspace secret overrides the workspace value for that worker only; unsetting the local override reverts the worker to the inherited workspace secret.

Pipe secret values on stdin (never as command-line arguments) or load multiple worker pairs from a local `.env` file:

```sh
# Workspace secrets (personal or team workspace namespace)
printf %s "$ANTHROPIC_API_KEY" | anywhere secrets set ANTHROPIC_API_KEY --workspace acme --scope all
printf %s "$STRIPE_SECRET_KEY" | anywhere secrets set STRIPE_SECRET_KEY --workspace acme --scope selected --project billing --worker invoice-sync
anywhere secrets scope STRIPE_SECRET_KEY --workspace acme --scope selected --project billing
anywhere secrets attach STRIPE_SECRET_KEY --workspace acme --worker refund-bot
anywhere secrets detach STRIPE_SECRET_KEY --workspace acme --worker refund-bot
anywhere secrets list --workspace acme

# Worker-local secrets (also override a workspace secret of the same name)
printf %s "$POSTHOG_KEY" | anywhere secrets set --worker triage POSTHOG_KEY
anywhere secrets set --env-file .env --worker triage
anywhere secrets list --worker triage --effective
anywhere secrets unset --worker triage POSTHOG_KEY
```

### Staged pending-apply

Editing workspace secrets, changing a worker's project when project-scoped secrets apply, saving secrets in the portal, or running worker CLI edits with `--staged` **never silently kills awake workers**. Affected deployed workers are marked as having pending secret changes while running work finishes uninterrupted.

Apply staged changes whenever you are ready from the portal's pending-secrets banner (or per worker) or with the CLI:

```sh
anywhere secrets apply --worker triage --wait
anywhere secrets apply --workspace acme --wait
```

- **Asleep workers** receive the updated merged environment without waking.
- **Awake workers** restart when applied (ending active runs as `sandbox_stopped`; the portal asks for confirmation before restarting awake workers).
- **Deploy and resume sync automatically:** running `anywhere deploy` or `anywhere workers resume` always pushes the worker's latest effective secrets and clears any pending state.
- **Backwards-compatible worker CLI:** `anywhere secrets set` and `anywhere secrets unset` on a worker without `--staged` still apply immediately.

### Security, portal & limits

- Postgres stores only ciphertext; each workspace and each worker has its own AES-256-GCM key sealed under the vault master key.
- Effective secrets are injected as environment variables into runs and `anywhere exec`.
- **`build` receives no secrets**, and secret values never appear in logs, error messages, or analytics. Revealing a secret in the portal or with `anywhere secrets get` returns `Cache-Control: no-store` and writes an audit record by name.
- Manage workspace secrets from the portal's account menu (`Secrets` at `/secrets` for personal workspaces or `/workspaces/<team>/secrets` for team workspaces) and per-worker effective secrets, overrides, and attachments under **Settings → Secrets**.
- Limits: up to **200** workspace secrets per workspace, and up to **100** effective secrets (**1 MiB** total) per worker after merging workspace and worker secrets.

## Optional projects

Create optional projects inside any personal or team workspace to group related workers and attach `selected` workspace secrets by group:

```sh
anywhere projects create billing --workspace acme
anywhere workers project acme/invoice-sync billing
anywhere projects list --workspace acme
anywhere projects rename billing revenue --workspace acme
anywhere workers project acme/invoice-sync --none
anywhere projects delete revenue --workspace acme
```

- **Flat worker addresses stay unchanged:** workers are always addressed as `workspace/worker`, never `workspace/project/worker`. Moving a worker between projects or deleting a project never changes its name, webhook URLs, bindings, or `anywhere exec` name.
- **No extra permissions or billing:** workspace membership, plan status, and usage caps remain the only access and billing boundary.
- **Progressive disclosure in the portal:** when a workspace has no projects, `Workers` and `Inbox` stay uncluttered; once you create a project, `Workers` groups by project and `Inbox` adds a project filter (`GET /v1/runs?project=<id>`).

## Workspace MCP connections

For remote MCP servers (such as Notion, Linear, Sentry, or PostHog), connect the server once at the workspace level instead of storing OAuth tokens or API keys on individual worker disks:

```sh
anywhere connections add notion https://mcp.notion.com/mcp --scope selected --workers triage
anywhere connections list
anywhere connections scope notion --workers triage,digest
anywhere connections test notion
anywhere connections remove notion
```

- **Credentials never reach worker disks:** OAuth access and refresh tokens, static API keys, and custom OAuth client secrets are encrypted in Postgres under your workspace's vault key and injected upstream by Anywhere's proxy.
- **Live updates with zero restarts:** Reconnecting, rotating a key, changing which workers have access, or removing a connection takes effect immediately on the proxy without stopping running workers or redeploying.
- **Scoped run tokens:** Every run of a worker with at least one connection in scope receives `ANYWHERE_MCP_URL`, `ANYWHERE_MCP_TOKEN` (a short-lived token valid only for `/v1/mcp` while that run is active), and `ANYWHERE_MCP_CONNECTIONS`. Builds never receive MCP tokens.
- **Portal and CLI management:** Manage connections in your workspace menu under **Connections** (for both personal and team workspaces) or with `anywhere connections`. Removing a connection immediately revokes worker access and erases its stored credentials.

See [Authenticating remote MCP servers](/docs/harnesses#authenticating-remote-mcp-servers) for harness configuration snippets across Claude Code, Codex, OpenCode, Python, and TypeScript.

## Networking & connecting to external databases

Inside the sandbox, **loopback (`127.0.0.1`)** is available on every port except `7682` (reserved for the `/_anywhere/done` helper), so a run can start a local HTTP MCP server, an SSH tunnel, or a short-lived helper process while it executes.

Outbound, workers connect to the internet over IPv4 TCP on any port except email SMTP ports (`25`, `465`, `587`, which are refused; send email via HTTPS APIs like Resend instead).

1. **Use the public IPv4 connection string.** Internal provider hosts (such as `*.railway.internal`) are unreachable from outside that provider. Use the external URL and connect over TLS.
2. **Store the URL as a secret:**

   ```sh
   printf %s "$DATABASE_URL" | anywhere secrets set --worker my-worker DATABASE_URL
   ```

3. **Allowlist outbound IP addresses (if required):** Check `dig +short outbound.anywhere.so` for current outbound addresses. Because workers share outbound addresses, always rely on strong database credentials and TLS rather than IP allowlisting alone.

| Provider        | Connection string to use                                                                                      |
| --------------- | ------------------------------------------------------------------------------------------------------------- |
| Railway         | `DATABASE_PUBLIC_URL` (`proxy.rlwy.net`)                                                                      |
| Render          | External Database URL (add outbound IP under inbound rules if restricted)                                     |
| Supabase        | Pooler string (`*.pooler.supabase.com`); direct `db.*.supabase.co` is IPv6-only unless IPv4 add-on is enabled |
| Neon            | Standard connection string from the Connect panel                                                             |
| AWS RDS         | Publicly accessible instance with security group rule for the database port                                   |
| MongoDB Atlas   | Add outbound address under Network Access                                                                     |
| Fly.io Postgres | Assign a public IPv4 address for external connections                                                         |

### Reaching a private database via SSH bastion

Install `openssh-client` in `build`, store `BASTION_KEY` and `BASTION_KNOWN_HOSTS` as secrets, and open a short-lived `-L 127.0.0.1:5432:db.internal:5432` tunnel at the start of your run script (closing it in a `trap` on exit).
