[FEATURE] Centralize capability-based authorization for agent execution
Problem statement
OpenSRE has multiple agent-reachable ways to execute code, start processes, read or modify the host, use credentials, and mutate external systems. Authorization is currently enforced differently by opensre ask, the interactive shell, and chat gateways. A tool can therefore be protected on one surface and silently allowed on another.
execute_python_code in #6373 is one instance of the broader problem. A Python-only fix or a longer API denylist would leave equivalent execution paths exposed through shell commands, CLI dispatchers, coding agents, skill helpers, credentialed vendor CLIs, and generic API tools.
@muddlebee requested this feature and should be tagged for design and review.
Current execution-equivalent paths
| Category | OpenSRE examples | Possible effect |
|---|---|---|
| Arbitrary local execution | shell_run, execute_python_code |
Host code execution, filesystem and network access |
| CLI dispatch | cli_exec, github_cli |
Local execution, credential use, or external mutation |
| Coding agents | code_implement, Pi, CI/security repair tools |
Filesystem modification, subprocesses, and network access |
| Skill helpers | Bundled Python script tools | Process execution with model-controlled arguments |
| Cloud/API dispatch | AWS/Yandex operations, gh api |
Credential use and external mutation |
| Internal processes | Scheduler workers, gateway supervision, version probes | Usually trusted fixed commands rather than model-controlled work |
Why the current metadata is insufficient
SideEffectLevel.READ_ONLYdoes not mean safe: a read-capable process can read credentials or host files and exfiltrate them.requires_approvalis only a Boolean and is not enforced consistently by every host.- Some tools mix reads and writes behind one generic dispatcher.
- Negative command denylists miss new subcommands and indirect execution paths.
- Tool execution currently accepts an empty set of lifecycle hooks, so a host that forgets to install an approval hook can execute a risky tool.
The current policy is fragmented:
| Surface | Current decision source |
|---|---|
opensre ask |
SideEffectLevel or requires_approval |
| Chat gateways | requires_approval |
| Interactive shell | Tool-name lists, tool types, /auto, and trust mode |
| Unattended runs | A separate side-effect/name filter |
flowchart LR
DATA[Untrusted logs, alerts, files, tool results] --> LLM[LLM selects a tool]
LLM --> ASK[opensre ask policy]
LLM --> REPL[Interactive-shell policy]
LLM --> CHAT[Gateway policy]
ASK --> TOOL[Tool implementation]
REPL --> TOOL
CHAT --> TOOL
TOOL --> HOST[Host process / filesystem]
TOOL --> EXT[Credentialed external system]
classDef risk fill:#fecaca,stroke:#b91c1c,color:#000
class ASK,REPL,CHAT,TOOL riskEach route currently makes a different decision. Security depends on which surface happened to invoke the same tool.
Proposed solution
Introduce one mandatory, capability-based authorization layer in core/tool. The policy must be based on what a request can do, not its implementation language or tool name.
1. Capability contract
Every registered tool declares a security profile:
class ToolCapability(StrEnum):
HOST_FILE_READ = "host_file_read"
HOST_FILE_WRITE = "host_file_write"
FIXED_PROCESS = "fixed_process"
ARBITRARY_PROCESS = "arbitrary_process"
GENERATED_CODE = "generated_code"
NETWORK_EGRESS = "network_egress"
CREDENTIAL_USE = "credential_use"
EXTERNAL_MUTATION = "external_mutation"
DELEGATED_AGENT = "delegated_agent"
@dataclass(frozen=True)
class ToolSecurityProfile:
capabilities: frozenset[ToolCapability]
resource_scope: ResourceScopeA missing or unknown profile must fail closed. It must never inherit a default “safe” classification.
Example profiles:
read_structured_file
HOST_FILE_READ
scope: one validated input path
shell_run
ARBITRARY_PROCESS, HOST_FILE_READ, HOST_FILE_WRITE, NETWORK_EGRESS
scope: host
execute_python_code
GENERATED_CODE, ARBITRARY_PROCESS, HOST_FILE_READ,
HOST_FILE_WRITE, NETWORK_EGRESS
scope: isolated workload only
github_cli read operation
FIXED_PROCESS, CREDENTIAL_USE
scope: configured GitHub host and repository
github_cli mutation
FIXED_PROCESS, CREDENTIAL_USE, EXTERNAL_MUTATION
scope: exact repository and operation
code_implement
DELEGATED_AGENT, HOST_FILE_READ, HOST_FILE_WRITE, NETWORK_EGRESS
scope: selected workspaceTools declare capabilities; the central policy decides whether those capabilities are allowed, require approval, or are prohibited. Tools must not choose their own effective privileges.
2. Mandatory authorization in the shared executor
The security decision belongs in _execute_one_tool_call() after public-input validation and before credential injection or tool.run().
flowchart TD
CALL[Provider tool call] --> VALIDATE[Validate public input]
VALIDATE --> PROFILE[Resolve request-specific security profile]
PROFILE --> POLICY[Central policy evaluation]
POLICY -->|Deny| BLOCK[Return blocked result]
POLICY -->|Approval required| GRANT[Verify exact single-use grant]
POLICY -->|Allow| BACKEND[Select permitted execution backend]
GRANT -->|Missing or mismatch| BLOCK
GRANT -->|Valid| BACKEND
BACKEND --> INJECT[Inject only permitted resources and credentials]
INJECT --> RUN[Execute tool]
RUN --> AUDIT[Record decision and outcome]ExecutionAuthority should become a required input to shared tool execution. Without authority:
- pure and explicitly bounded read operations may run;
- risky, unclassified, and unknown operations are denied.
Surface hooks may render terminal prompts or chat buttons, but omitting a hook must not remove the security boundary.
3. Exact, single-use grants
Approval must authorize the proposed operation rather than the whole tool. A grant should be bound to:
tool name
+ canonical argument digest
+ actor
+ session/conversation
+ capability set
+ resource scope
+ expiry
+ one permitted useExamples:
- Approval for
shell_run(command="kubectl get pods")cannot authorize a later delete command. - Approval for a GitHub issue comment cannot authorize merging a pull request.
- Changing one argument invalidates the grant.
- A Slack approval cannot be replayed in another channel or by another actor.
- Approval for one delegated coding task cannot authorize a second task.
--allowed-tool execute_python_code is too broad for generated code because it authorizes code the user has not seen. Non-interactive CLI flows should return an approval request containing a redacted argument preview and resume only with an exact grant. A deliberately named global bypass may remain available for trusted environments, but it must be explicit and auditable.
Literal host-parsed entry points such as !command can create an exact grant because the host receives the command verbatim. Natural-language intent must not be converted into authority through keyword or intent matching.
4. Central process broker
Agent-reachable process creation should go through an infrastructure-owned broker:
process_broker.run_fixed(spec)
process_broker.run_isolated(spec, grant)
process_broker.spawn_managed_service(spec)run_fixed
For trusted, bounded subprocesses:
- argv list only; never
shell=True; - known executable;
- positive executable/subcommand policy;
- sanitized environment;
- explicit working directory;
- timeout, output, and process limits.
Examples include version probes, a fixed git status, or a managed OpenSRE command whose argument grammar is independently validated.
run_isolated
For generated code, arbitrary commands, and delegated workloads:
- OS/container isolation rather than language-level monkey-patching;
- no host filesystem mounts by default;
- no integration credentials;
- no network by default;
- non-root identity and user namespace;
- read-only root filesystem and isolated scratch space;
- CPU, memory, PID, output, and wall-clock limits;
- whole-process-group termination on timeout.
The model must not elevate a workload by setting an input such as allow_network=true. Network, filesystem, and credential capabilities come from the verified authority and broker.
spawn_managed_service
Trusted long-lived OpenSRE services such as gateway or scheduler workers should use a separate API. They are not model-authored workloads and should not be forced through the arbitrary-code sandbox.
5. Mixed read/write dispatchers
Prefer separate, narrow tools:
github_query # positive allowlist of read operations
github_mutation # exact approval requiredIf a dispatcher must remain, it needs a request-specific profile resolver:
def security_for_github_cli(arguments: dict[str, object]) -> ToolSecurityProfile:
# Known positive read operation -> fixed process + credential use.
# Known mutation -> add external mutation.
# Alias, extension, custom command, or unknown operation -> deny.github_cli is a concrete example of why denylists are insufficient:
- GitHub CLI aliases may expand to shell expressions executed through
sh. gh apisupports POST, PATCH, PUT, and DELETE.- Supplying fields to
gh apican implicitly switch a request from GET to POST. - File-backed arguments such as
@filenamecan introduce host-file access.
Therefore:
- block aliases, extensions, and unknown/custom commands;
- classify
gh apifrom the resolved method and endpoint; - reject implicit mutation unless the request carries mutation authority;
- scope credentials to the configured host/repository;
- treat file-backed arguments as an additional host-file capability.
Apply the same pattern to generic cloud operations and database queries: positive read registries plus read-only credentials/transactions, not name-prefix heuristics.
6. Generic policy matrix
| Capability or combination | Default decision |
|---|---|
| Pure computation with bounded inputs | Allow |
| Provider-specific bounded read | Allow within configured scope |
| Fixed process with positive argv policy | Allow or request scoped approval according to effect |
| Host-file write | Exact approval |
| External mutation | Exact approval |
| Arbitrary process | Exact approval plus isolated backend unless entered verbatim through an explicit host command path |
| Generated code | Explicit opt-in, exact approval, isolated backend |
| Delegated coding agent | Exact approval and workspace scope |
| Generated code + injected credentials | Deny |
| Generated code + unrestricted host filesystem | Deny |
| Generated code + unrestricted direct network | Deny |
| Arbitrary process + integration credentials | Deny unless implemented as a separately constrained fixed operation |
| Unknown capability/profile | Deny |
Approval and containment are separate controls: approval does not make an unsafe sandbox safe, and isolation does not grant permission to perform an external mutation.
7. Quality enforcement
Add repository checks that:
- fail when a registered tool lacks a security profile;
- reject direct
subprocess,os.system,os.popen,posix_spawn,spawn*,exec*, andshell=Truein agent-facing tool packages except audited infrastructure adapters; - ensure protected credentials cannot appear in model-provided schemas;
- require mixed-operation dispatchers to provide a request-specific security resolver;
- exercise the same policy matrix against every host surface.
The subprocess check should target agent-facing execution code rather than banning legitimate internal process management across the entire repository.
8. Initial migration inventory
| Tool/path | Target treatment |
|---|---|
execute_python_code |
Disabled by default; generated-code profile; no credentials; isolated backend |
shell_run |
Arbitrary-process profile; exact command grant |
cli_exec |
Derive effects from canonical OpenSRE command metadata; unknown commands denied |
github_cli |
Split read/write or add positive request resolver; aliases/custom commands denied |
code_implement and Pi |
Delegated-agent profile; exact approval; workspace scope |
| CI/security repair tools | Delegated-agent/external-mutation profiles according to stage |
| Skill script tools | Fixed bundled-script profile with declared per-script capabilities |
| Cloud generic operations | Positive read-operation catalog; mutations require separate tools/grants |
| Database query tools | Read-only DB role/transaction plus query bounds |
| Scheduler/gateway supervision | Trusted managed-service broker, not an agent arbitrary-execution path |
Delivery plan
- Add
ToolCapability,ToolSecurityProfile, resource scopes, and the central policy decision type. - Make security authority mandatory in shared execution, with unknown/risky tools failing closed.
- Inventory and classify every registered tool.
- Add exact single-use grants and adapt CLI, REPL, and gateway approval UI to the same contract.
- Quarantine arbitrary execution and mixed dispatchers.
- Add the process broker and isolated backend.
- Move agent-facing subprocess call sites behind the broker.
- Remove duplicated surface-specific authorization rules after parity tests pass.
Acceptance criteria
- Every registered tool has a security profile; missing profiles fail CI.
- A risky tool cannot run when a host forgets to install an approval hook.
- CLI, REPL, Slack, Telegram, Discord, Buzz, and unattended execution use the same central decision matrix.
- Exact grants cannot be replayed, changed, or reused across actors, sessions, or conversations.
- Generated or arbitrary workloads cannot receive integration credentials or unrestricted host filesystem/network access.
- Model-provided inputs cannot increase a tool's effective capabilities.
- Mixed dispatchers positively classify known operations and deny unknown operations.
- Raw agent-facing subprocess creation outside audited broker modules fails a quality test.
- Regression tests provide untrusted context and attempt every risky capability class; execution must not begin without matching authority.
- Fixed internal process management continues to work without being treated as model-generated code.
- #6373 is covered by the generic policy rather than a Python-specific exception.
References
- Related security report: #6373
- GitHub CLI shell aliases: https://cli.github.com/manual/gh_alias_set
- GitHub CLI API methods and implicit POST behavior: https://cli.github.com/manual/gh_api
- Python isolated mode scope: https://docs.python.org/3/using/cmdline.html#cmdoption-I
- Rootless container isolation: https://docs.docker.com/engine/security/rootless/
- Container execution hardening controls: https://docs.docker.com/reference/cli/docker/container/run
Source: Tracer-Cloud/opensre