DEV Community

Taylor Lin
Taylor Lin

Posted on

Deny, Dry-Run, or Sandbox: Gating Agent Shell Commands

An agent proposes formatting a file, building an artifact and releasing it. Those operations need different authority. Giving all three the same shell makes it hard to state what a successful review actually authorized.

Define operations the runner understands

Expose a small set of named operations with validated parameters and documented outputs. Treat text read from documents and issue descriptions as data. Calling a proposal “read only” does not authorize reading arbitrary files or exposing their contents. Check the requesting principal, resource and task scope before deciding whether any operation may proceed. Docker documents the runtime authority behind these checks in its Engine security overview.

For a formatter, prefer a tool with a documented preview that returns a diff. Bind the approved change to the same source revision, parameters and formatter version; reject a changed input or request a fresh preview. For a build, use an isolated job with a declared input set and a disposable output directory. A preview command can itself have effects, so evaluate its documented behavior and test it in the same restricted setting.

A release is a separate operation. Bind any required approval to the intended environment, artifact digest and expiry. The component applying it should check those fields at execution. Keep the release credential out of the formatter and build environments.

Exercise four decisions

Use synthetic inputs and a fake release destination. An authorized formatter should produce only a proposed diff. A build must be able to produce its declared artifact without reading a release credential. A changed artifact digest should invalidate the old release grant. An unrecognized operation should have no executable mapping. Record the actual outputs and mock destination changes along with the decision. That makes it possible to diagnose a policy error separately from a runner that ignored a correct decision.

Test a grant against a changed build artifact

Give the fake release service a grant for digest A in a staging environment. Exercise the supported release operation first with digest B and then with A. Expect zero destination changes for B and one staging change for A, subject to the grant still being valid. Also check the fake runner has no release authority while exercising the formatter. A UI message alone does not establish either result.

This article was created with AI assistance.

Top comments (0)