# run_with

Source: https://botpassword.com/docs/intents/run_with

Built. run_with runs a command with granted credentials injected by BotPassword and returns the exit status and output.

**Status: Built.** Sealed delivery (`sealed`) runs on Linux and macOS; on Windows a sealed run answers `not_implemented`.

## At a glance

| Property | Value |
|---|---|
| MCP tool | `run_with` ("Run a command with a credential") |
| CLI | `bpw agent run_with` |
| Default friction | None inside a grant that lists the command (or an argv rule that matches it). Disclosing injection needs the grant's disclosure opt-in. |
| Delivery | Sealed with `sealed`: the command gets only a placeholder. Disclosing with `env` or `files`: the command and anything it starts can read the value, and the result says `delivery: disclosing`. |
| MCP hints | `readOnlyHint`: false, `destructiveHint`: true, `idempotentHint`: false, `openWorldHint`: true |

## Parameters

Required: `command`. Unknown arguments are refused. The descriptions are the tool's own, as `bpw mcp` serves them.

| Name | Type | Required? | Description |
|---|---|---|---|
| `command` | array of string | required | The program and its arguments, run directly (no shell unless you name one). The program is looked up on a fixed PATH. 1 to 257 items. |
| `env` | object (name → string) | optional | Environment variables to set: variable name to credential reference. The command sees the value; the result never does. At most 16 entries. Names match `^[A-Za-z_][A-Za-z0-9_]*$`. |
| `files` | object (name → string) | optional | Variables that hold the path of a private file with the credential's value: variable name to credential reference. The file is deleted when the command ends. At most 16 entries. Names match `^[A-Za-z_][A-Za-z0-9_]*$`. |
| `sealed` | object (name → string) | optional | Sealed credentials: variable name to credential reference. The variable holds a placeholder, not the value. Send it in a header the grant names, in the grant's form (for example Authorization: Bearer $VAR, or curl -u user:$VAR under a grant with that Basic user), to a host the grant names, and BotPassword's egress proxy for this run swaps the value in. Only the command and processes descended from it can use the proxy, so a background daemon is refused. The command never sees the value; the placeholder is useless anywhere else. Linux and macOS. At most 16 entries. Names match `^[A-Za-z_][A-Za-z0-9_]*$`. |
| `environment` | string | optional | Environment reference as ORG:ENV or ORG/ENV (ADR 0063 section 7). In run_with, replaces env, files and sealed; in request_access, replaces credential and looking_for. 1 to 121 bytes. |
| `only` | array of string | optional | With environment: restrict to these variable names. Under a sealed environment grant, pass only sealable variable names to omit unsealable ones. 1 to 256 items, each once. |
| `disclose` | boolean | optional | run_with: let the command read the value. Without it a run_with ask is sealed and must name hosts. |
| `timeout_seconds` | integer | optional | Seconds before BotPassword stops the command or request (default 30). 1 to 100. |
| `max_output_bytes` | integer | optional | Most bytes of stdout and stderr together to return (default 1 MiB). 1 to 2097152. |

## Example

A `tools/call` request, with placeholder references (use the `id` that `list_credentials` returns):

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "run_with",
    "arguments": {
      "command": [
        "curl",
        "-sS",
        "-H",
        "Authorization: Bearer $API_TOKEN",
        "https://api.example.com/v1/status"
      ],
      "sealed": {
        "API_TOKEN": "ITEM-EXAMPLE-01"
      },
      "timeout_seconds": 30
    }
  }
}
```

The result. The same JSON is also sent as text in `content[0].text`; `isError` is false for `success`.

```json
{
  "structuredContent": {
    "outcome": "success",
    "exit": "code",
    "exit_code": 0,
    "stdout": "{\"status\":\"ok\"}",
    "stderr": "",
    "timed_out": false,
    "truncated": false,
    "delivery": "sealed"
  },
  "isError": false
}
```

No shell is involved: `$API_TOKEN` reaches curl as written, and curl expands nothing. Name a shell in `command` only if the grant allows that shell.

## From the command line

```sh
bpw agent run_with --sealed API_TOKEN=ITEM-EXAMPLE-01 -- curl -sS -H 'Authorization: Bearer $API_TOKEN' https://api.example.com/v1/status
```

`bpw agent <intent>` sends the same request as the MCP tool, through the same policy. Every intent except `status` needs a live agent session, or the answer is `session_required`. Run the harness with `bpw agent run -- <harness>`. On macOS and Linux, an enrolled harness started normally can also be approved in the desktop app or with `bpw session approve`.

## Result fields

Every result is one JSON object. Only `outcome` is always present.

| Field | Type | Meaning |
|---|---|---|
| `outcome` | string | The [typed outcome](/docs/outcomes) code. Always present. |
| `detail` | string | The request ID, rotation step, revision or reason, for the outcomes that carry one. |
| `intent` | string | With `not_implemented`: the intent this build cannot carry out. |
| `reason` | string | With `rejected`: why the call was refused. |
| `message` | string | With `rejected` or `daemon_unavailable`: what was wrong. Never quotes an argument value. |
| `next_step` | string | On a result that is not a plain success: one sentence on what to do now. Fixed text chosen by the outcome code; it never asks for a password or secret and never says to get around a refusal. |
| `exit` | string | How the command ended: `code`, `signal`, or `killed` at the timeout or by a stop. One of `code`, `signal`, `killed`. |
| `exit_code` | integer | The exit code, when `exit` is `code`. |
| `signal` | integer | The signal number, when `exit` is `signal`. |
| `stdout` | string | Standard output. A disclosing run's output has injected values redacted as `[bpw:redacted]`. |
| `stderr` | string | Standard error, redacted the same way. |
| `timed_out` | boolean | Whether BotPassword stopped the command at `timeout_seconds`. |
| `truncated` | boolean | Whether output was cut: beyond the byte limit, or thrown away because a stop killed the command as it started. |
| `delivery` | string | `sealed` or `disclosing`: whether code the agent controls could read the value. One of `disclosing`, `sealed`. |
| `stopped` | string | Present only when BotPassword stopped the command before it ended by itself, with `exit` `killed`: `grant_revoked`, `grant_expired` (the grant ran out mid-run), `session_ended` (ended by the person, ran out, or its anchor process exited), `vault_locked` (a command that held a value), or `daemon_stopped` (the daemon shut down). Stopping takes nothing back: a value already disclosed to the command cannot be taken back. |
| `stopped_note` | string | With `stopped`: why, in words, and for a disclosing run that a value already disclosed stays disclosed and the credential should be rotated if the command may have copied it. |

## Outcomes it can return

- [`success`](/docs/outcomes/success): The request ran.
- [`scope_denied`](/docs/outcomes/scope_denied): The most common refusal.
- [`disclosure_not_granted`](/docs/outcomes/disclosure_not_granted): The request would let code the agent controls read the value (`run_with` with `env` or `files`, `cli_login`, `sign_in`, `fill_totp`), and the grant does not allow disclosure.
- [`grant_expired`](/docs/outcomes/grant_expired): A grant names this credential for this client, but its lifetime is over.
- [`value_reflected`](/docs/outcomes/value_reflected): A form of a credential's value appeared in an HTTP response or in a sealed run's output.
- [`value_too_short`](/docs/outcomes/value_too_short): The credential's value is under 16 bytes.
- [`minting_blocked`](/docs/outcomes/minting_blocked): `http_request`, or a sealed `run_with` request through the egress proxy, targeted a provider endpoint that creates or returns tokens or keys.
- [`host_restricted`](/docs/outcomes/host_restricted): The host resolved to an address BotPassword never sends a credential to, such as loopback, a private network or link-local, even when the grant names the host.
- [`containment_unsupported`](/docs/outcomes/containment_unsupported): The request needs something BotPassword cannot do while keeping the value contained: the credential is too large to inject and redact, this platform has no private place for a file injection, or, inside a sealed run, a response came back in a form the egress proxy cannot scan (the command sees HTTP 502).
- [`provider_unavailable`](/docs/outcomes/provider_unavailable): The host did not resolve, the connection failed, or the command could not be started.
- [`not_implemented`](/docs/outcomes/not_implemented): Policy allowed the request, and this build has no way to carry it out.
- [`session_required`](/docs/outcomes/session_required): The call did not come from inside a live agent session: none was presented, it expired, or it is malformed.
- [`vault_locked`](/docs/outcomes/vault_locked): BotPassword on this device is locked, so no credential can be used.
- [`rejected`](/docs/outcomes/rejected): The request was malformed before policy saw it.
- [`daemon_unavailable`](/docs/outcomes/daemon_unavailable): `bpw mcp` or `bpw agent` could not reach `botpasswordd`, the desktop daemon that holds the keys.

See the [outcome reference](/docs/outcomes) for what each one means and what to do next.

## Limits

- A disclosing run hands the value to the child process. That process, anything it runs and other processes of the same user can read it. Redaction of the output is best effort.
- A sealed run still lets the command use the credential at the grant's hosts while it runs. A tool that ignores `HTTPS_PROXY` or the run's CA fails rather than falls back. `git clone`, `fetch` and `push` are refused under a sealed run.
- git, gh, npm, cargo, shells and interpreters run only with arguments that match one of the grant's argv patterns, and take a value only in their token variable (`GH_TOKEN`, `NPM_TOKEN`, `CARGO_REGISTRY_TOKEN` and the like). Variables that change how programs run (`PATH`, `LD_*`, `NODE_OPTIONS`, `*_PROXY` ...) are `scope_denied`.
- A value under 16 bytes cannot be delivered sealed (`value_too_short`).
- `bpw run --with` is planned, not built yet; the CLI form today is `bpw agent run_with`.

## Tool description

What the MCP tool tells the agent, verbatim from `bpw mcp`:

> Runs a command with granted credentials injected by BotPassword, in a fixed minimal environment, in the session's project directory, only for an executable the grant lists. Sealed credentials (sealed) give the command a placeholder; BotPassword's egress proxy for the run (HTTPS_PROXY, with a trust file for the run's own CA) serves only the command's process tree, and swaps the value into the headers the grant names only on requests to the grant's hosts, so the command never holds the value; a tool that ignores the proxy or its CA fails rather than falls back. Environment variables (env) and private files (files) hold the value itself, which the command can read, so only grants that allow disclosure permit them. git, gh, npm, cargo, shells and interpreters run only with arguments that match one of the grant's argv patterns exactly: the subcommand (or, for an interpreter, the script path relative to the project) first, no options before it, options spelled as in the pattern, and only operands where it ends in * (never a URL or path in place of a ref). A git ref is a branch or tag name, never an object id or abbreviation (4 or more hex digits; write such a branch refs/heads/<name>), describe output (v1-1-g600b5d3) or revision syntax (HEAD, FETCH_HEAD, main~1). Inject a runner's value only as its token variable: GH_TOKEN or GITHUB_TOKEN for git and gh, NPM_TOKEN or NODE_AUTH_TOKEN for npm, CARGO_REGISTRY_TOKEN for cargo. No command may take a value in a variable that changes how programs run or connect (PATH, LD_*, GIT_*, NODE_OPTIONS, *_PROXY, ...); those requests answer scope_denied. Returns the exit status and the output, or value_reflected. This tool takes no secret value from you: the daemon injects the granted credential. A disclosing run's output is returned with each injected value replaced by [bpw:redacted] in its raw, base64, hex, percent-encoded, JSON and HTML forms (best effort; other transformations are not caught). When a value comes back in an HTTP response or in a sealed run's output, the result is value_reflected with none of that output, and that value's grant is revoked; a person decides whether to grant it again. Never put a secret value in arguments. The result is a typed outcome such as success, vault_locked or scope_denied.

## Related

- [`http_request`](/docs/intents/http_request): sends one HTTPS request with a granted credential injected by BotPassword, after checking the origin, path and method against the grant.
- [`request_access`](/docs/intents/request_access): asks the person for a grant on one credential, with the intents, scope, lifetime and a one-line reason.
- [`cli_login`](/docs/intents/cli_login): checks that git, docker, aws or kubectl may log in with a granted credential at a host, and returns the setup lines that point the tool at BotPassword's credential helper.
- [Intent catalog](/docs/intents), [MCP server](/docs/mcp-server), [Grants and approvals](/docs/grants-and-approvals)
