antigravity-sdk-python icon indicating copy to clipboard operation
antigravity-sdk-python copied to clipboard

policy.workspace_only() discards its workspaces argument and never confines file tools

Open YashvantHange opened this issue 2 weeks ago • 2 comments

Environment

  • SDK version: 0.1.23
  • Python version: 3.10.1
  • OS / platform: Windows 11 x86_64 (win_amd64 wheel, bundled localharness.exe)
  • Install method: pip install google-antigravity==0.1.23

Source read at commit 75ba22bd00afae2f46393ff31f30c3f0df52982f.

Description

policy.workspace_only(workspaces) is documented as the SDK's file containment control, but it never consults a path. The workspaces argument is discarded at the top of the function, so the rules it returns carry no path information, and nothing downstream can scope anything to the directories that were passed in.

Three things combine:

  1. The paths are dropped at the entry point — google/antigravity/hooks/policy.py:551-553:

      del workspaces
      file_tools = [t.value for t in types.BuiltinTools.file_tools()]
      return [deny(tool, name=_WORKSPACE_ONLY_POLICY_NAME) for tool in file_tools]
    

    What comes back is three unconditional deny rules for view_file, create_file and edit_file, all named workspace_only, none of which reference a path.

  2. The in-process evaluator skips those rules — policy.py:716-719:

          if p.name == _WORKSPACE_ONLY_POLICY_NAME or p.auto:
            # Workspace boundary containment and auto policy mode safety evaluation
            # are enforced at the platform/execution layer.
            continue
    

    Enforcement is deferred to the platform layer — but after step 1 there is no path to defer.

  3. The platform is never asked to enable containment — policy.py:914-920:

      workspace_containment = (
          localharness_pb2.PolicyConfig.WORKSPACE_CONTAINMENT_UNSPECIFIED
      )
      if has_allow_all and not has_workspace_only:
        workspace_containment = (
            localharness_pb2.PolicyConfig.WORKSPACE_CONTAINMENT_DISABLED
        )
    

    PolicyConfig.WorkspaceContainment defines UNSPECIFIED = 0, ENABLED = 1, DISABLED = 2, but WORKSPACE_CONTAINMENT_ENABLED is never emitted anywhere in the package — the field is only ever UNSPECIFIED or DISABLED. The same logic is duplicated for the Interactions API at connections/local/interactions_config_converter.py:563-564.

Steps to Reproduce

Driven offline so no API key or network is needed: a local mock OpenAI-compatible endpoint returns one scripted write_to_file tool call, against the real bundled localharness.exe.

config = LocalOpenAIAgentConfig(
    model="mock-model",
    base_url="http://127.0.0.1:8778/v1",   # mock endpoint, replies with one tool call
    workspaces=[str(ws)],                  # <root>/ws
    app_data_dir=str(appdata),
    policies=[policy.allow_all(), *policy.workspace_only([str(ws)])],
)
async with Agent(config) as ag:
    await (await ag.chat("Create the file as instructed.")).text()

The scripted call is write_to_file with TargetFile set either to <root>/ws/probe.txt (inside the declared workspace) or <root>/OUTSIDE/probe.txt (outside it), then the same run is repeated for each policies= value below.

The serialization half needs no harness at all:

from google.antigravity.hooks import policy
cfg, _ = policy._to_policy_config_proto([policy.allow_all()])
print(cfg.workspace_containment)    # 2 == DISABLED
cfg, _ = policy._to_policy_config_proto([policy.allow("*")])
print(cfg.workspace_containment)    # 0 == UNSPECIFIED

print(any("/tmp/only-here" in repr(p) for p in policy.workspace_only(["/tmp/only-here"])))
# False — the path is not retained anywhere

Expected Behavior

Per the docstring at policy.py:540-543:

Restricts file tools to the given workspace directories.

File read/write/create operations targeting paths outside any of the configured workspace directories are denied. Other tools are unaffected.

So: a write to <root>/ws/probe.txt should succeed, and a write to <root>/OUTSIDE/probe.txt should be denied. types.py:615 makes the same promise ("can be scoped to specific workspace directories via policy.workspace_only()"), as does policy.py:165 and :573 ("For file-write containment, pair policy.auto(...) with policy.workspace_only(workspaces)").

Actual Behavior

No configuration produces that behaviour. The result is all-or-nothing and never path-dependent:

policies= inside ws outside ws
[allow_all()] wrote wrote
[allow("*")] wrote wrote
[allow("*", name="allow_all")] wrote wrote
[allow_all(), *workspace_only([ws])] wrote wrote
[*workspace_only([ws]), allow("*")] wrote wrote
[*workspace_only([ws])] blocked blocked
[auto(), *workspace_only([ws])] blocked blocked
[auto()] wrote wrote
[deny_all()] blocked blocked
(default, no policies) wrote wrote

There is no row where inside is allowed and outside is denied. [deny_all()] blocking is the positive control: policy rules really are enforced on this path, so the workspace_only rows are not an artefact of a misconfigured harness.

Two sub-cases worth separating:

  • Fails open: workspace_only() combined with a permissive policy (the documented way to enable autonomous file and shell access) gives no containment.
  • Fails closed: workspace_only() alone, or paired with auto() as the docs suggest, denies file writes inside the workspace too, which also contradicts the documented behaviour.

Additional Context

allow_all() is not equivalent to allow("*")

policy._to_policy_config_proto(...).workspace_containment:

policies= emitted
[allow_all()] DISABLED
[allow("*")] UNSPECIFIED
[allow("*", name="allow_all")] DISABLED
[allow_all(), *workspace_only([d])] UNSPECIFIED

allow_all()'s docstring (policy.py:458) states it is "Equivalent to allow("*")", but the two emit different values for workspace_containment.

The discriminator is the name field, documented at policy.py:129 as a "Human-readable label used in logging and deny reasons" — so allow("*", name="allow_all") changes a filesystem-containment setting purely by virtue of its label. A field presented as cosmetic is load-bearing, which seems worth decoupling regardless of the rest of this issue.

policy.deny() silently ignores unknown builtin tool names

Related footgun found while testing: the tool names the model is offered (write_to_file, replace_file_content, …) are not the names policy.deny() matches (create_file, edit_file, …). policy.deny("write_to_file") matches nothing, raises nothing, logs nothing, and the call proceeds. enforce() already guards the analogous MCP case and refuses rather than under-matching, explicitly "to enable secure policy matching and prevent silent bypasses" (policy.py:970-975); the same reflex would help for builtin names.

Alternative explanations I tried to rule out

  • The platform enforces it and the SDK is a thin client — then the platform has to be told which paths; no path is sent (step 1) and ENABLED is never sent either (step 3).
  • UNSPECIFIED means enabled-by-default — tested, it does not: [allow("*")] wrote outside the workspace.
  • The documented pairing is auto(), not allow_all() — tested; that combination blocks everything including in-workspace writes.
  • Policies are not wired on the LocalOpenAI path — [deny_all()] blocks on that same path.
  • Rule ordering should put the specific denies first — enforce() does sort that way (policy.py:964, via _policy_sort_key at policy.py:935), but the local-connection path serializes to the proto instead of going through enforce(); [*workspace_only([ws]), allow("*")] wrote outside with the denies listed first.

Suggested fix

Any one of these closes the gap; the first is the smallest.

  1. Make the no-op explicit — have workspace_only() raise NotImplementedError or log a warning, and say so in the docstring, if containment is not yet wired. This matches the existing treatment of policy.auto(), which fails loudly on the Interactions path ("not yet supported by the GAOS Interactions API protocol in localharness", interactions_config_converter.py:515-519).
  2. Carry the paths through — give Policy a path/scope field, keep workspaces rather than del workspaces, serialize them into PolicyConfig, and emit WORKSPACE_CONTAINMENT_ENABLED when workspace_only is present.
  3. Enforce in-process as a fallback — ToolCall.canonical_path is already populated for file tools (hook_router.py:191), so _PolicyDecideHook could perform a real containment check instead of continue-ing past the rule.

On disclosure, and what is not shown here

Filing this publicly rather than through g.co/vulnz because it does not fire on the SDK as shipped — it needs a developer to opt into workspace_only() in the first place, and the package is 0.1.x / Development Status :: 3 - Alpha, so "containment is not wired up yet" may simply be the intended state. Happy to move it if you would rather handle it privately.

Limits of what I actually tested, so nothing above is over-read:

  • Only LocalOpenAIAgentConfig was exercised at runtime. LocalAgentConfig and LiteRTAgentConfig share _to_policy_config_proto, so the serialization claim holds for them by inspection, but the behavioural matrix was not re-run on those paths.
  • Windows only; macOS and Linux untested.
  • write_to_file only. run_command was not used to escape, and read containment (view_file), though covered by the same docstring, was not separately probed.
  • The harness binary was read only through its symbol and string tables, so why UNSPECIFIED does not contain is inferred from observed behaviour rather than from its code.
  • The model was a mock returning scripted tool calls, so this demonstrates the policy layer's behaviour, not any particular real-world agent trajectory.

YashvantHange avatar Nov 17 '26 19:11 YashvantHange

@dkalcantara110297-tech

dkalcantara110297-tech avatar Nov 17 '26 21:11 dkalcantara110297-tech

Correcting this report: my central empirical claim was wrong, and the cause was a flaw in my own test setup rather than anything in the SDK. I'm sorry for the noise.

What was wrong

I claimed there is no configuration in which file operations inside the workspace are allowed and those outside are denied, and I published a matrix showing writes outside the workspace succeeding in every usable configuration.

Every "outside the workspace" target in that matrix was a path under %LOCALAPPDATA%\Temp, because I ran the probes from a scratch directory there. The harness grants that directory. Its own denial message lists what it allows, and the third entry is the temp root:

denied by pre-tool hook: Access to path "...\OUTSIDE\verify_none.txt" is denied.
It is outside the allowed workspace directories:
[.../probe/ws  .../probe/appdata  C:\Users\<user>\AppData\Local\Temp]

So my writes were landing in an allowed location. The matrix measured my own test layout, not the absence of containment.

What actually happens

Re-run with the out-of-workspace target genuinely outside that grant (under a project directory, not under %TEMP%), same four configurations:

policies= inside ws outside ws
(default, no policies) wrote denied
[allow_all(), *workspace_only([ws])] wrote denied
[*workspace_only([ws])] denied denied
[allow_all()] wrote wrote

Rows 1 and 2 are exactly the behaviour I said never occurs. Workspace containment is real, it is on by default, and pairing workspace_only() with allow_all() preserves it — which also matches the code I quoted: workspace_containment is set to DISABLED only when has_allow_all and not has_workspace_only, so UNSPECIFIED means enabled, not off. I inferred the opposite from the bad matrix. The harness's own check also reads the raw argument, not canonical_path, and correctly denies a file://host/... target under the default policy.

Please disregard the matrix, the "no containment in any configuration" conclusion, and the allow_all() + workspace_only() row in particular.

What still stands, and is the narrower point worth keeping

Row 4 against rows 1-2 is the real issue, and it is sharper than what I filed:

policy.allow_all() disables workspace containment, and nothing says so. Row 4 writes outside the workspace where rows 1-2 deny, so the control is lost — and allow_all()'s docstring describes it purely as approving tool calls, "Equivalent to allow("*")". At the serialization level the two are not equivalent, and the discriminator is the name field, documented at policy.py:129 as a "Human-readable label used in logging and deny reasons":

policies= emitted workspace_containment
[allow_all()] DISABLED
[allow("*")] UNSPECIFIED
[allow("*", name="allow_all")] DISABLED
[allow_all(), *workspace_only([d])] UNSPECIFIED

That table is from policy._to_policy_config_proto directly, so it holds regardless of the harness. A human-readable label deciding a filesystem-containment field looks like something you would not have chosen deliberately.

I am deliberately not claiming that allow("*") therefore behaves like rows 1-2 at runtime. When I ran it, [allow("*")] and [allow("*", name="allow_all")] both denied file writes inside the workspace as well as outside, which I cannot account for and which does not follow from the serialization. I am reporting that as an observation rather than a conclusion — I was wrong once already in this thread by reasoning past what I had actually measured.

Two smaller things also hold:

  • workspace_only(workspaces) does del workspaces at policy.py:551 and keeps no path, so it cannot confine to the directories passed to it — it preserves containment against the agent's configured workspaces instead. The docstring's "the given workspace directories" over-promises.
  • workspace_only() used alone denies file operations inside the workspace too (row 3), since what it returns is three unconditional deny rules for view_file, create_file and edit_file.

So the suggestions I'd still make, much reduced in scope:

  1. Correct or drop allow_all()'s "Equivalent to allow("*")" claim, and document that it disables workspace containment. That coupling is the one that can surprise someone into losing a control they never knew they had.
  2. Stop keying workspace_containment off the human-readable name.
  3. Either keep workspace_only()'s paths and confine to them, or document that the argument is ignored and the agent's workspaces govern.

Method note

For anyone reproducing this: put the out-of-workspace target outside %LOCALAPPDATA%\Temp. A probe written into a directory the product already grants will succeed for that reason and look like a missing control.

YashvantHange avatar Nov 18 '26 04:11 YashvantHange