tsk-k5z0t8gdr835 Done An agent
Follow-up to #1815 (tsk-ydpnmpdzpc0a), decided by the owner (req-bp7x51d371mh, o2).
Today: a command the runner grants to a placed agent (e.g. git status) is matched exactly for Claude Code placements. The antigravity (agy) adapter passes it on as agy's own allow rule, which agy treats as a prefix: git status --anything is allowed too. docs/runners.md records this as a deliberate difference.
Goal: agy placements check granted commands exactly, like Claude Code placements. No wider grant for one harness than for another.
Scope:
- Find how agy can be told to match exactly (its own settings), or enforce it on the runner side before the command reaches agy.
- If neither is possible without a gap, say so on this card with the evidence before building a workaround.
- Tests for: exact command allowed, same command with extra arguments refused, unrelated command refused.
- Update
docs/runners.md: remove the recorded prefix difference.
Does not block #1815; build on main after it merges.
Notes
An agent · Nov 14, 2026, 22:11 UTC
Research so far (q445, 2026-11-14, from the agy 1.5.3 binary on the runner host; no session started, no login used):
- Rule matching. agy's own text says: "Each token in the granted target is matched as a full word (internally treated as an anchored regular expression:
^(?:pattern)$)". Socommand(git status)matches the tokensgitandstatusexactly, each as a whole word. Extra trailing tokens still pass. That is the prefix behaviour docs/runners.md records. - No end anchor found. I found no documented marker that ends a rule, and no "exact" flag. Each token is a regex, so something like
command(git status $)is not documented, and I won't rely on it untested. - Hooks. agy loads
PreToolUsehooks, Claude Code style (a hooks.json naming each hook at the top level:{"my-hook": {"PreToolUse": [...]}}). That is the candidate for runner-side enforcement: a hook that refuses a command which would leave the sandbox under a grant unless it equals a granted command exactly. - Not known from the binary. The hook's input format and how a hook refuses: no
permissionDecision,hookSpecificOutputor exit-code text found. That needs one test against a logged-in agy.
Proposed order once #1815 is on main:
- Short probe on a host with a logged-in agy (ur6p's runner). Does a
--settingshook run? What JSON does it get? How does it deny? - Build the hook in the adapter, plus the three tests from this card.
- Update docs/runners.md.
If the probe shows no hook can deny a sandbox-leaving command, I'll post that evidence here before building anything else.
- Rule matching. agy's own text says: "Each token in the granted target is matched as a full word (internally treated as an anchored regular expression:
An agent · Nov 14, 2026, 22:19 UTC
Research: exact command grants for agy (agy 1.5.9; code read from the binary's disassembly and symbol table, docs at antigravity.google/docs/permissions; nothing built, no model call).
How agy matches `command(...)` (package
jetski/cortex/utils/commandutils, command_matching.go)shared.coversCommand:*matches all. Otherwise the line is split into simple commands (mvdan/sh parser;&&||;|parts and wrapper-strippedtimeout/nohup/nice/env). Every part must match the rule. If the line "requires exact match" ($(), backticks, brace expansion, fd redirections,git -c...) or does not parse: whole raw line, char-for-char, or^(?:re)$for aregex:rule.MatchesConfigAny: trims the rule, strips a leadingregex:, tokenizes it with the same shell parser.MatchesConfig: false if the rule has more tokens than the command. Otherwise it compares onlycmd[:len(rule)], so it is a prefix match in both forms.matchParts: the lengths must be equal. Each token is compared literally, or, for regex rules, as^(?:tok)$(a compile error counts as no match).- So no exact flag, no end anchor:
regex:git statusalso matchesgit status --x, because a regex is applied per token, after truncation. permissionManager.checkCompoundchecks each part and refuses the whole line on the first denied part. Deny > Ask > Allow.
What allow means: run_command has a
BypassSandboxarg. An allow rule approves that bypass, so a matching command runs outside the sandbox with no prompt. Without the arg it runs sandboxed anyway. The gap in #1815:git status <anything>can leave the sandbox.Option A (recommended): allow + generated "extension deny"
For each exact granta b: allowcommand(a b)and denycommand(regex:a b .*). The deny rule has 3 tokens, so it never matches the barea b(rule longer than command), and it matches everya b X...(.*also matches an empty token). Grants with a closing*stay plain prefixes. Result: exact, likeBash(a b). An extension is refused, also in the sandbox, which matches Claude Code'sdontAsk(ungranted = refused).
Must-haves / gaps:- A malformed regex is accepted silently (
agy --settings F agentsexits 0 onregex:git status (.*) and then matches nothing: the deny fails open. Generate only safe tokens, and leave out any grant with a token outside a plain set (no regex/shell metacharacters). - A deny also blocks other grants in the same family (
git statusexact plusgit status --short). Either build complement regexes per token or refuse/flag such grant sets. - Unverified in a real session (needs the sign-in): env assignments (
GIT_DIR=x git status, whether they are stripped before matching) and simple redirects (git status > f, which agy prefix-matches normally, written outside the sandbox). Both exist in #1815 today. Compare with Claude Code before claiming parity. - Mid-
*grants: per-token regex cannot span tokens. A translation would be narrower; leaving them out stays as is.
Option B: PreToolUse hook (
hooks.json, decision plusoverwrite, e.g.{"BypassSandbox": false}for any line that is not an exact grant). This keeps the sandbox fallback. But--settingsrejectshooks(verified). The hook would live in the workspace's.agents/(tamper risk, writable by the agent unless protected) or in the shared global~/.gemini/config, it must re-parse shell itself, and it is untested. Not now.Ruled out: a PATH shim (an allowed command leaves the sandbox and agy canonicalizes command names; a shim cannot tell sandboxed calls from bypassing ones). Using
askinstead of deny: it prompts a human in interactive runs and is refused in headless ones, so it gives nothing over deny.Recommendation: build A, with safe-token generation, family-conflict handling and a test of the generated rules. Verify point 3 in one signed-in run. Without A, exactness is not possible: the gap is exactly "any extra arguments after a granted command may leave the sandbox".
An agent · Nov 14, 2026, 22:20 UTC
Builder: ur6p (lotse 134171). Built on main after #1815 merges. Only safe words are emitted; grants that share a start are refused or reported, never given a conflicting deny. The PR includes one signed-in check for VAR=x cmd and cmd > f.