> For the complete documentation index, see [llms.txt](https://docs.duplocloud.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.duplocloud.com/docs/advanced-topics/access-control/command-policy.md).

# Command Policy

Command Policies let administrators define, once, which shell commands an agent may run without asking and which it may never run — applied platform-wide, per workspace, or per project, rather than set up by hand on every ticket. A **Command Policy Definition** holds the regex rules, and a **Command Policy Mapping** applies a definition to a scope.

Go to **AI Admin → Access Control → Command Policy**.

![Command Policy tab](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-df163487f287c87be60eb504c29af41502b7e8b1%2Fcommand-policy-step-01-definitions.png?alt=media)

***

## Command Policy Definitions

The **Command Policy Definition** tab lists every definition. The cards at the top summarize them: how many there are, the total allow and block patterns, and the most recently modified. The table shows each definition's description and a preview of its allow and block patterns.

A definition holds two lists of regular expressions, one per line:

* **Allow List** — commands matching any pattern here are auto-approved
* **Block List** — commands matching any pattern here are always denied

### Add a Command Policy Definition

Click **+ Add** and fill in:

* **Name\*** — a label for the policy. It must start with a letter, and can't be changed after the policy is created.
* **Description** — optional
* **Allow List** — one regex per line
* **Block List** — one regex per line

Click **Create**. Every pattern is checked when you save, and an invalid regex is rejected.

![Add Command Policy form filled in](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-be3a6c77c64f464f1b649f114434185d00a37d94%2Fcommand-policy-step-02-add-definition.png?alt=media)

![Command Policy added](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-259151fbe7b3807e04bb43f042a834131ffa9e15%2Fcommand-policy-step-03-definition-added.png?alt=media)

{% hint style="info" %}
Patterns are matched case-insensitively, and anywhere in the command — `kubectl get` also matches `sudo kubectl get pods`. Start a pattern with `^` to match only from the beginning of the command, as in `^kubectl get` .
{% endhint %}

A definition does nothing on its own until a mapping applies it. A definition can't be deleted while an active mapping still references it — delete the mapping first.

***

## Command Policy Mappings

Click the **Command Policy Mapping** tab. A mapping binds a definition to a level and, for Workspace and Project levels, to one or more targets. The cards at the top show how many mappings there are, how many definitions they reference, and whether a System-wide mapping exists. The table shows each mapping's policy definition, level, and target.

![Command Policy Mapping tab](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-c5cd5337859b554fb3c1b32c837c5ce67e2d90c8%2Fcommand-policy-step-04-mappings.png?alt=media)

### Add a Command Policy Mapping

Click **+ Add** and fill in:

* **Name\*** — a label for the mapping
* **Description** — optional
* **Command Policy\*** — the definition to apply
* **Level\*** — **System**, **Workspace**, or **Project**. The form opens with **System** selected, so change it before you click **Create** if you don't mean to apply the policy platform-wide.
* **Target Workspace(s)\*** / **Target Project(s)\*** — shown only for Workspace or Project level; select one or more

![Add Command Policy Mapping form — Workspace level](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-3787850fb8be8210fda767c540c02e814b2bb526%2Fcommand-policy-step-05-add-mapping-workspace.png?alt=media)

![Add Command Policy Mapping form — Project level](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-7ea9a737a7c52d082e8d3003e1236738c7ee03c7%2Fcommand-policy-step-06-add-mapping-project.png?alt=media)

Click **Create**.

![Command Policy Mapping added](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-758f6a11759b14924486f80de45d0c02c3165e1e%2Fcommand-policy-step-07-mapping-added.png?alt=media)

Only one active System mapping can exist, and each workspace or project can be covered by only one active mapping at its level. Adding a target that another mapping already covers fails with an error naming that mapping — remove the target from the existing mapping first.

Click a mapping's name to open it. The **Details** tab shows its definition, level, targets, and the allow and block patterns it applies.

![Command Policy Mapping details](https://2471407984-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F68cb0s9ce5UIUKWPuYs8%2Fuploads%2Fgit-blob-965938e96371b1e3262b182407581412cd2dac04%2Fcommand-policy-step-08-mapping-view.png?alt=media)

***

## How commands are evaluated

Policies at different levels add up rather than override each other. When the agent asks to run commands on a ticket, the patterns that apply are:

* the ticket's own **Commands** patterns (see [Create a Ticket](https://docs.duplocloud.com/docs/concepts/tickets.md#commands))
* the active **System** mapping's policy
* the policy mapped to the ticket's **workspace**
* the policy mapped to the ticket's **project**, if the ticket was started from a project

These are evaluated in two steps:

1. **Block** — if any command matches a block pattern from any of these sources, the whole request is rejected. Block always wins over allow.
2. **Allow** — the allow patterns from all sources are pooled. If every command matches at least one of them, the request is approved without asking.

Anything else waits for a person to approve it on the ticket, as described in [Approving commands as the agent works](https://docs.duplocloud.com/docs/concepts/tickets.md#approving-commands-as-the-agent-works).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.duplocloud.com/docs/advanced-topics/access-control/command-policy.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
