> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-cli/cortex-cli-usage.md).

# Cortex CLI usage

To execute a Cortex CLI scan, run:

```programlisting
cortexcli [global flags] [module name] scan [module flags]
```

### Command breakdown

#### `cortexcli`:

The Cortex CLI binary - a global option. Establishes the execution environment for all subsequent commands

#### Global flags:

Flags that apply across all supported modules. Place global flags between `cortexcli` and the `module` name

* `--api-base-url <value>`
* `--api-key <value>`
* `--api-key-id <value>`

Additional global flags are supported by the AppSec and CWP modules, but not the WAAS module. Refer to [Cortex CLI common command line reference guide](/cortex-cli/cortex-cli-common-command-line-reference-guide.md) for more information.

#### Module name:

Select the module (environment) to be scanned:

* `api` — API Security. For more information about API Security scans, refer to [Cortex CLI for API Security](/cortex-cli/cortex-cli-for-api-security.md)
* `image` — CWP. For more information about CWP scans, refer to [Cortex CLI for Cloud Workload Protection](/cortex-cli/cortex-cli-for-cloud-workload-protection.md)
* `code` — Application Security. For more information about Application Security refer to [Cortex CLI for Code Security](/cortex-cli/cortex-cli-for-code-security.md)

#### Module flags:

The flags available for the selected command:

* For flags common to all environments, refer to [Cortex CLI common command line reference guide](/cortex-cli/cortex-cli-common-command-line-reference-guide.md)
* For flags specific to CWP refer to [Cloud Workload Protection command line reference](/cortex-cloud-runtime-security/cortex-cli/cortex-cli-for-cloud-workload-protection/cloud-workload-protection-command-line-reference.md)
* For flags specific to API Security, refer to [Cortex CLI API Security command line reference guide](/cortex-cli/cortex-cli-for-api-security.md)
* For flags specific to Application Security, refer to [Cortex CLI Application Security command line reference](/cortex-cli/cortex-cli-for-code-security/cortex-cli-application-security-command-line-reference.md)

### Examples

#### Global flags:

Apply to all modules. Place between cortexcli and the module name:

{% code overflow="wrap" %}

```programlisting
# Authenticate and scan with global authentication flags
cortexcli --api-base-url https://api.xdr.us.paloaltonetworks.com --api-key <KEY> --api-key-id <KEY_ID> code scan --directory .
```

{% endcode %}

#### Global flags common to AppSec and CWP:

Upload mode, exit code handling, and log output. Not supported by WAAS:

{% code overflow="wrap" %}

```programlisting
# Run an AppSec scan in no-upload mode with soft-fail and log output
cortexcli --upload-mode no-upload --soft-fail --no-fail-on-crash --log code scan --directory .
```

{% endcode %}

#### AppSec scan:

Scan source code for IaC misconfigurations, SCA vulnerabilities, and secrets:

{% code overflow="wrap" %}

```programlisting
# Scan a repository directory and filter results to critical and high severity
cortexcli --upload-mode no-upload code scan --directory /path/to/repo --severity critical,high
```

{% endcode %}

#### CWP scan:

Scan a container image for vulnerabilities:

```programlisting
# Scan a container image with soft-fail enabled
cortexcli --soft-fail image scan --image myapp:latest
```

#### API Security scan:

Scan APIs for security issues. Global flags (other than authentication) are not supported:

```programlisting
# Run an API Security scan
cortexcli api scan --api-spec /path/to/openapi.yaml
```

{% hint style="info" %}
**Note**

* For more information about CLI usage for CWP, refer to [Cortex CLI for Cloud Workload Protection](/cortex-cli/cortex-cli-for-cloud-workload-protection.md)
* For more information about CLI usage for API Security, refer to [Cortex CLI for API Security](/cortex-cli/cortex-cli-for-api-security.md)
* For more information about CLI usage for Application Security, refer to [Cortex CLI usage for Application Security](/cortex-cli/cortex-cli-for-code-security/cortex-cli-usage-for-application-security.md)
  {% endhint %}


---

# 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 dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-cli/cortex-cli-usage.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
