AgentKit
DocsKitsCLI ReferenceDesktop App
BetaYou are reading docs for the beta channel (3.2.0-beta.10). Features may change before the next stable release.Switch to stable →

secrets

ak secrets run

Run one program with secrets delivered only in named environment variables, under exec grants.

Use ak secrets run to start one program with secrets in the environment variables --env names, and nowhere else. It serves a coding agent: the caller is identified the way ak secrets resolve identifies it, by walking the process tree and hashing the agent's binary.

If a grant for the same secret nearly matches, the refusal names the mismatched fields. Compare those fields with the program and environment variable you intended to authorize before requesting another grant.

Usage

ak secrets run --env VAR=REF [--env VAR=REF ...] [--purpose <text>] [--project <slot>] [--session <id>] -- <program> [args...]
ak secrets run --bundle FILE --profile NAME [--key-env VAR] -- <program> [args...]

The second form is CI bundle mode.

The program and its arguments come after --; everything after the separator belongs to the program, never to ak. At least one --env pair is required, at most 16 are accepted, and no variable may be named twice. --purpose is at most 200 characters. --json is not supported: the program's own output is the output.

FlagDefaultDescription
--env VAR=REFrequiredDeliver secret REF in environment variable VAR. Repeatable.
--purpose <text>emptyPurpose label the grant must match literally.
--project <slot>the AK project containing the current directoryProject slot the grants are scoped to.
--session <id>noneSession id tying this run to the agent run that asked for it.
--backend <backend>keychainBackend that holds the values: keychain, file or memory.
--unlock-with-recoveryoffOpen the file backend's vault with a recovery private key and set a new passphrase.
--bundle FILEnoneCI bundle file to decrypt and deliver. No vault, grant, or prompt is used.
--profile NAMEnoneWith --bundle, required: the environment profile this job expects. A bundle made for another profile is refused.
--key-env VARAK_CI_DECRYPT_KEYWith --bundle: the environment variable that holds the decryption key.

Exec grants

Each VAR=REF pair needs an exec grant (ak secrets grant REF --exec PROGRAM --env VAR) for the calling agent on exactly this program: its path with every symlink resolved and its content hash. For a #!/usr/bin/env NAME script, the pinned hash also covers the interpreter NAME resolves to, by its resolved path and content hash. A program found elsewhere on PATH, or changed since the grant, matches no grant, and each uncovered scope is filed for the operator to answer with ak secrets approve, as resolve files one. An ordinary grant never releases here, and an exec grant never releases to resolve.

A REF with no stored value that names an alias follows it one hop, and the exec grant is checked against the alias's target, never the alias name.

Every scope is checked, and the program re-hashed, before any value is read, so a run a grant check refuses spends no allow-once. If the program still cannot start after its values were released, the ledger records that it never started.

How the program runs

  • No shell. The program is started directly, in the current working directory, so nothing in its arguments is expanded. Shells and launchers are refused.
  • A rebuilt environment. A few variables are copied from this one (HOME, USER, LANG, TERM, TMPDIR and their kind), PATH is a fixed list of the system directories (led, for a #!/usr/bin/env NAME script, by the directory NAME was found in), and the granted variables are added; nothing else, proxies and runtime options included. A program that runs a helper installed outside the system directories must name it by path. A copied variable such as HOMEPATH cannot be named in --env.
  • A pinned interpreter. For a #!/usr/bin/env NAME script, an interpreter that changed after it was checked is refused before the program starts.
  • Struck output. The program's output is relayed with every granted value struck out. The last few bytes are held back (fewer than the longest form of a value, which for an escaped form can exceed the value) until the program writes more or exits. Its output goes to pipes, not a terminal.
  • Signals and exit. Ctrl-C reaches the program from the terminal, and SIGTERM and SIGHUP are passed on to it; ak waits for it to exit and never kills it. The program's exit status is this command's. ak's own failures always print an error starting secrets run: on stderr; the program's status is passed on with nothing added, though the program itself can print anything.

An exec grant bounds which program gets a value, not what the program does with it. The program can still send it anywhere, write it to a file or pass it to a child of its own; an interpreter runs whatever script it is given; a program such as curl, wget or gh can be told by its arguments to send a variable anywhere or to run another program; and any process of the same user can read the program's environment while it runs. Grant exec scopes to programs you would hand the value to yourself.

The command reads the vault, the alias file and the grant file, writes one audit row per variable, and starts the program. It never prints a value.

CI bundle mode

--bundle FILE --profile NAME serves a protected CI job. It decrypts a bundle made with ak secrets bundle locally, with the key held in the --key-env variable, and delivers every entry in the bundle to the one program.

  • No vault, grant, approval, prompt, or audit row is used. The key is the whole authorization, so scope each bundle and key to one trust boundary.
  • --profile must match the profile the bundle was made for.
  • --env is refused with --bundle; the bundle's own entries name the variables.
  • The job's environment is kept, minus the key variable. A bundle that names the key variable is refused.
  • Output is struck of the delivered values. This is a best-effort filter: it misses transformed forms such as encoded, split, or reversed values. The program and anything it starts still see the plaintext, so run only reviewed code.
  • Under GitHub Actions, the pull_request_target event is refused.
  • A missing or empty key, a wrong key, an altered, truncated, or oversized bundle, or a profile mismatch exits 6 and starts nothing.
ak secrets run --bundle ci-production.akv --profile ci-production -- ./deploy.sh

Output

There is no ak output of its own on success: stdout and stderr carry the program's relayed output, with granted values struck out.

Exit behavior

ExitMeaning
0The program exited 0. Any other status it exits with is passed on (128 plus the signal number if a signal ended it).
2Invalid flags, --json, no program after --, a refused program or variable, or --purpose longer than 200 characters. In bundle mode, also a missing bundle file, --env with --bundle, no --profile, an invalid --key-env, a bundle that names the key variable, or a program not found on PATH.
3No secret by that ref.
5The vault, alias file, grant file or audit ledger could not be used, or the program could not start.
6A block refuses the caller, its identity cannot be named, or the program or its interpreter changed after it was checked. In bundle mode, a missing or empty key, a wrong key, an altered, truncated, or oversized bundle, a profile mismatch, or a refused CI event.
7The file backend's vault needs a passphrase and this run has no terminal.
8No exec grant covers a variable; a request is waiting for ak secrets approve.
9The caller raised too many approval requests and is in its cool-down.
15A synced vault policy refuses this release, or whether one governs it cannot be answered; the JSON error's sync.reason names why.