Skip to content

agent-guard: env/command prefixes and a quoted ~ slip past vetted-ops-spelling #1679

Closed

Description

@potiuk

The agent-guard vetted-ops-spelling guard added in #1674 leaves two spellings unchecked.
Neither one escapes the sandbox (the exclusions name only the literal ~/.claude/magpie/<tool> form), but both slip past the guard that should catch them.

1. Prefix wrappers: env uv run …

env uv run --project tools/vetted-ops vetted-op-read pr-view 1
command uv run --project /home/alice/.claude/magpie/vetted-ops vetted-op-read pr-view 1

The engine looks only at a segment's first word (argv[0]), and env / command are not guarded heads.
This is not specific to the new guard: Segment.__init__ in tools/agent-guard/src/agent_guard/__init__.py already notes that env git / command git stay unguarded for every guard (commit-trailer, empty-rebase, mention, …).

Proposed fix, in the engine rather than in one guard: strip env (with its NAME=value assignments and options such as -i, -u NAME) and command (with -p) before matching, so every guard sees the wrapped command.
Prefix assignments must still feed Segment.env, so overrides such as MAGPIE_ALLOW_VETTED_PATH=1 keep working.

2. A quoted ~

uv run --project "~/.claude/magpie/vetted-ops" vetted-op-read pr-view 1

The guard compares the base after shlex removes the quotes, so this matches the allowed spelling.
The shell does not expand a quoted ~, though: uv gets a directory literally named ~, the sandbox exclusion does not match, and the call fails inside the sandbox instead of being refused with the corrected command.

Proposed fix: have the guard look at the raw segment and refuse a quoted ~ with the same corrected-command message.

Acceptance

  • env … and command … around a guarded command are checked as that command, by every guard, with tests per guard family.
  • A quoted ~ base is refused by vetted-ops-spelling, with a test.
  • The "prefix wrappers … remain a separate, pre-existing gap" comment in Segment.__init__ is removed.

Activity

  1. added
    substrate:action-guard
    on Oct 17, 2026
  2. added
    family:setup
    family:docs
    capability:platform
    on Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    capability:platformfamily:docsfamily:setupfamily:toolssubstrate:action-guard

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions