Skip to content

Agent lines: follow variables set earlier in the line (#86) - #87

Merged
paureis merged 2 commits into
mainfrom
fix/86-env-in-line
Oct 14, 2026
Merged

paureis merged 2 commits into
mainfrom
fix/86-env-in-line

Conversation

@paureis

@paureis paureis commented Oct 14, 2026

Copy link
Copy Markdown
Owner

Closes #86

Found in the review of the threat model (#85). Before this, a variable an agent set earlier in the same command line was ignored, and a value only known when the line runs was read as empty. cloudpin checked the default account while the command ran on another:

Agent's line Before Now
export AWS_PROFILE=other; aws s3 ls checked the default profile checks other
$env:AWS_PROFILE = 'other'; aws s3 ls (PowerShell) default profile other
GH_TOKEN=$(cat other.token) gh repo list default login (token read as empty) blocked, saying GH_TOKEN is set from something only known when it runs

How

  • The command parser carries export, declare -x/typeset -x, unset and $env: through the rest of the line. These don't leak out of a ( ) subshell, bash -c or $( ).
  • A plain X=1; reaches a command only if X is already exported, so envFor applies it only then. Applying it otherwise would check an account the command won't use.
  • A value from $(...), backticks or $VAR is unknown. If it's one of the CLI's identity variables (e.g. GH_TOKEN, GH_HOST, AWS_*), the guard blocks it as "can't tell". Other unknown values are dropped before the CLI's identity check runs.
  • The hook and cloudpin explain share envFor. Agents still can't set or unset CLOUDPIN_ENV, CLOUDPIN_CONFIRM or CLOUDPIN_SKIP.

Checked

  • Typecheck clean; 760 tests pass, 8 skipped on Windows. The new tests failed before the change.
  • Mutation-checked, each mutation confirmed applied and restored: dropping the unknown check; applying plain assignments regardless; not carrying exports; leaking subshell variables; taking $(...) as known. All five caught.
  • Against the real gh (read-only explain --agent): gh repo list allowed; GH_TOKEN=$(...) gh repo list and export GH_HOST=$(...); gh repo list blocked with the reason.

On the critical path for 1.0.0, so it merges when CI is green.

🤖 Generated with Claude Code

paureis and others added 2 commits October 14, 2026 15:39
Found in the review of the threat model. `export AWS_PROFILE=other; aws
...` and PowerShell `$env:AWS_PROFILE='other'; aws ...` were checked
against the default account, and `GH_TOKEN=$(cat other.token) gh ...`
read GH_TOKEN as empty; each ran on another account.

The command parser now carries export / declare -x / typeset -x /
unset / $env: through the rest of the line (not out of a ( ) subshell or
bash -c). A plain `X=1;` reaches a command only if X is already
exported, so envFor applies it only then. A value from $(...), backticks
or $VAR is unknown: if it decides the CLI's account (its identity
variables, e.g. GH_TOKEN, AWS_*), the guard blocks and says why instead
of guessing; other unknown values never reach the CLI. The hook and
explain share envFor; agents still can't set the user-only variables.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paureis paureis added this to the 1.0.0 milestone Oct 14, 2026
@paureis
paureis merged commit 42a844f into main Oct 14, 2026
5 checks passed
@paureis
paureis deleted the fix/86-env-in-line branch October 14, 2026 19:43
@carlosrod1231 carlosrod1231 mentioned this pull request Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Variables set earlier in an agent's command line are ignored (export X=...; cli)

1 participant