Skip to main content

Runnable Examples

The repository includes runnable TypeScript examples in docs-site/examples/. They exercise the same public SDK APIs documented in the guides and can be run with tsx from the repository root.

Setup

Install dependencies and create an environment file:

npm install
cp .env.example .env

Fill in the credentials required by the workflow you want to run:

  • Scan examples require PANW_AI_SEC_API_KEY or PANW_AI_SEC_API_TOKEN, plus PANW_AI_SEC_PROFILE_NAME.
  • Management examples require PANW_MGMT_CLIENT_ID, PANW_MGMT_CLIENT_SECRET, and PANW_MGMT_TSG_ID.
  • Model Security and Red Team examples can use their service-specific PANW_MODEL_SEC_* / PANW_RED_TEAM_* credentials or fall back to PANW_MGMT_*.
  • Validation scripts marked as mock-backed do not require live AIRS credentials.

Run examples with:

npx tsx --env-file=.env docs-site/examples/<script>.ts

AI Runtime Security Scan Examples

ScriptWhat it demonstrates
basic-scan.tsCalls init(), creates Content, and runs Scanner.syncScan() with metadata.
async-scan.tsSubmits a batch with Scanner.asyncScan(); batch size is capped at 20 items.
query-results.tsFetches async scan results and threat reports by scan ID or report ID.
npx tsx --env-file=.env docs-site/examples/basic-scan.ts
npx tsx --env-file=.env docs-site/examples/async-scan.ts
npx tsx --env-file=.env docs-site/examples/query-results.ts

Management and DLP Examples

ScriptWhat it demonstrates
mgmt-auth.tsConstructs ManagementClient and triggers OAuth on the first API call.
mgmt-profiles.tsLists and works with AI security profiles.
mgmt-topics.tsUses custom topic management APIs.
mgmt-dashboard.tsReads runtime dashboard application and violation data.
mgmt-dlp-data-filtering-profiles.tsLists and replaces DLP data filtering profiles.
mgmt-dlp-data-patterns.tsCreates, reads, replaces, patches, and deletes DLP data patterns.
mgmt-dlp-data-profiles.tsWorks with DLP data profiles and merge-patch updates.
mgmt-dlp-dictionaries.tsUses DLP dictionary CRUD with multipart keyword uploads.
npx tsx --env-file=.env docs-site/examples/mgmt-auth.ts
npx tsx --env-file=.env docs-site/examples/mgmt-profiles.ts
npx tsx --env-file=.env docs-site/examples/mgmt-topics.ts
npx tsx --env-file=.env docs-site/examples/mgmt-dashboard.ts
npx tsx --env-file=.env docs-site/examples/mgmt-dlp-data-filtering-profiles.ts
npx tsx --env-file=.env docs-site/examples/mgmt-dlp-data-patterns.ts
npx tsx --env-file=.env docs-site/examples/mgmt-dlp-data-profiles.ts
npx tsx --env-file=.env docs-site/examples/mgmt-dlp-dictionaries.ts

Model Security and Red Team Examples

ScriptWhat it demonstrates
model-security-scans.tsLists Model Security scans and related data-plane resources.
red-team-scans.tsLists Red Team scan jobs and categories.
red-team-targets.tsWorks with Red Team targets and profile helpers.
red-team-network-broker.tsLists, reads, and inspects stats for Red Team network broker channels.
npx tsx --env-file=.env docs-site/examples/model-security-scans.ts
npx tsx --env-file=.env docs-site/examples/red-team-scans.ts
npx tsx --env-file=.env docs-site/examples/red-team-targets.ts
npx tsx --env-file=.env docs-site/examples/red-team-network-broker.ts

Mock-Backed Validation Scripts

These scripts spin up local mock servers or validate schemas directly, so they can run without live tenant credentials:

ScriptWhat it validates
profiles-get-validation.tsprofiles.get() and profiles.getByName() behavior.
profiles-crud-validation.tsManagement profile create, list, get, update, delete, and force-delete flow.
oauth-lifecycle-validation.tsOAuth token caching, refresh, 401/403 retry, callbacks, and token state inspection.
red-team-mgmt-validation.tsRed Team target and custom attack schemas plus management-plane workflows.
npx tsx --env-file=.env docs-site/examples/profiles-get-validation.ts
npx tsx --env-file=.env docs-site/examples/profiles-crud-validation.ts
npx tsx --env-file=.env docs-site/examples/oauth-lifecycle-validation.ts
npx tsx --env-file=.env docs-site/examples/red-team-mgmt-validation.ts