Skip to content

Detect sandbox mode and network in statusline example#322

Open
raybell-md wants to merge 3 commits into
google-antigravity:mainfrom
raybell-md:statusline-sandbox-workaround
Open

Detect sandbox mode and network in statusline example#322
raybell-md wants to merge 3 commits into
google-antigravity:mainfrom
raybell-md:statusline-sandbox-workaround

Conversation

@raybell-md

@raybell-md raybell-md commented Jun 7, 2026

Copy link
Copy Markdown

What

Makes the example statusline detect terminal sandbox mode even though the statusLine payload doesn't currently report it.

Why

As of agy 1.0.6, agy --sandbox enables the terminal sandbox but does not set .sandbox.enabled in the statusLine payload — it stays false. As a result the example's sandbox badge always reads sandbox off even when running under --sandbox.

I confirmed there's no other clean signal available to a statusLine script:

  • Payload.sandbox.enabled stays false; no populated execution_mode field either.
  • Environment — sandbox env vars (_AGY_SBOXSERVE, SANDBOX) are not exported to the statusLine process.
  • Process tree — the statusLine process is reparented to init, so its parent command line can't be inspected.

The only reliable signal is the session log line --sandbox: enabling terminal sandbox for this session, which ~/.gemini/antigravity-cli/cli.log symlinks to.

How

Keep .sandbox.enabled as the primary source and, only when it's not already true, fall back to grepping the current session log. This means the workaround self-corrects automatically once the payload field is populated upstream — no follow-up change needed.

if [ "$SANDBOX" != "true" ]; then
  SANDBOX_LOG="$HOME/.gemini/antigravity-cli/cli.log"
  if [ -r "$SANDBOX_LOG" ] && grep -q 'enabling terminal sandbox' "$SANDBOX_LOG" 2>/dev/null; then
    SANDBOX="true"
  fi
fi

Caveat

This is an interim workaround, not a real fix. cli.log always points at the newest session, so a stale refresh from an older non-sandbox terminal could theoretically read a newer sandbox session's log. The proper fix is for agy to populate sandbox.enabled (and/or execution_mode) in the payload — tracked in #321. Happy to drop this if you'd prefer to fix it at the source instead.

Testing

  • bash -n passes.
  • With a session log containing the sandbox line + payload sandbox.enabled=false → renders sandbox ON.
  • With no sandbox line in the log → renders sandbox off.

Update: also show sandbox network mode (closes #399)

Added a second commit that surfaces the network mode in the badge, addressing the confusion reported in #399 where users couldn't tell whether sandboxAllowNetwork had taken effect.

Same shape as the .enabled workaround above. The payload's sandbox object only carries .enabled — there is no .sandbox.allow_network field — and the session log has no network-specific line. So the badge reads the authoritative sandboxAllowNetwork from settings.json, while still preferring .sandbox.allow_network from the payload when present (self-corrects upstream, #321).

The badge now reads sandbox ON (net) or sandbox ON (no-net).

Testing

  • bash -n passes.
  • Payload allow_network=true/false(net)/(no-net).
  • Payload sandbox absent + sandboxAllowNetwork:true in settings.json → (net); false(no-net).
  • Payload allow_network=true overrides settings → (net).
  • All paths exit 0 under set -euo pipefail.

`agy --sandbox` enables the terminal sandbox but does not populate
.sandbox.enabled in the statusLine payload (it stays false as of 1.0.6),
so the example's sandbox badge always reads "off" under --sandbox.

The flag is not exported to the statusLine process's environment, and the
process is reparented to init, so neither env nor the parent command line
can be inspected. The only reliable signal is the session log line
"--sandbox: enabling terminal sandbox for this session", which cli.log
symlinks to.

Keep .sandbox.enabled as the primary source and fall back to grepping the
session log, so the badge self-corrects once the payload field is fixed
upstream (see google-antigravity#321).
@weby-homelab

weby-homelab commented Jun 15, 2026

Copy link
Copy Markdown

Hi @raybell-md! I also addressed sandbox state formatting in my responsive statusline script, providing distinct badges for ON (net), ON (no-net), and OFF based on the JSON payload.

Antigravity-cli-statusline-max

Feel free to check out the implementation or use it as a reference:
https://github.com/weby-homelab/antigravity-cli-statusline

Community discussion: #397

The sandbox badge only showed ON/off, giving no indication of whether
sandboxAllowNetwork was in effect — a frequent source of confusion (google-antigravity#399).

The payload's sandbox object only carries .enabled; there is no
.sandbox.allow_network field, so it can't drive the badge on its own. The
session log has no network-specific line either. Mirror the existing
.enabled workaround: read sandboxAllowNetwork from settings.json as the
authoritative source, while still preferring .sandbox.allow_network from the
payload when present, so it self-corrects once that field is populated
upstream (google-antigravity#321).

The badge now reads "sandbox ON (net)" or "sandbox ON (no-net)".

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@raybell-md raybell-md changed the title Detect sandbox mode via session log in statusline example Detect sandbox mode and network in statusline example Jun 15, 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.

sandbox and sandboxAllowNetwork settings are a mess

2 participants