This repository contains the content (Integrations, Scripts, Playbooks, Reports, Modeling Rules, Parsing Rules) for the Cortex Platform (XSOAR, XSIAM, etc.).
This file provides guidance to agents when working with code in this repository.
This project uses demisto-sdk as the primary CLI for all development tasks.
- Linting & Testing:
demisto-sdk pre-commit -i <path>(runs in Docker, replaceslint) - Formatting:
demisto-sdk format -i <path>(fixes style/lint issues) - Validation:
demisto-sdk validate -i <path>
# Run lint, tests, and validation (single file/dir) - MUST run in Docker
demisto-sdk pre-commit -i Packs/MyPack/Integrations/MyInt/
# Format code (fixes many lint errors automatically)
demisto-sdk format -i Packs/MyPack/Integrations/MyInt/MyInt.py
# Validate content against XSOAR standards (also run by pre-commit)
demisto-sdk validate -i Packs/MyPack/Integrations/MyInt/
# Run pre-commit hooks on all files
demisto-sdk pre-commit -a- Runtime Injection:
CommonServerPythonis injected at runtime and must be imported:from CommonServerPython import *. Note:CommonServerUserPythonis also injected but is typically not imported explicitly by integrations. - Imports: MUST import
demistomock as demistoat the top of every integration/script. - Docker Dependency: Dependencies are managed via Docker images defined in the
.ymlfile, not localpip. You cannotpip installin the runtime environment. - Test Execution: Standard
pytestoften fails due to missing runtime context. Usedemisto-sdk pre-commitwhich sets up the correct Docker environment. - Error Handling: Use
return_error("message")for user-facing errors. Only raise exceptions for unexpected failures. - Outputs: Use
CommandResultsobjects withreturn_results():return_results(CommandResults(outputs_prefix='MyPrefix', outputs=data)). Output keys should be CamelCase. - Logging: Use
demisto.debug()anddemisto.info(). Avoidprint().
- Pack Structure:
Packs/<PackName>/<Entity>/<EntityName>/. Entities includeIntegrations,Scripts,Playbooks,ModelingRules,ParsingRules,XDRCTemplates, etc. Flat structures are forbidden. - Metadata: Every pack requires
pack_metadata.json. Every entity requires a YAML/JSON configuration file. - Versioning: Changes require a new entry in
Packs/<PackName>/ReleaseNotes/<Version>.md. - Isolation: Integrations are stateless and run in isolated containers. No shared state between executions.
- Source of Truth:
xsoar.pan.devis the official documentation.
- Variable Names: Use descriptive, self-explanatory names.
- Type Hints: Always use type hints.
mypyis enforced. - Formatting:
demisto-sdk formatis MANDATORY. It fixes YAML structure, JSON formatting, and Python style.
- Parameters: Use
demisto.params()for configuration anddemisto.args()for command arguments. - Function Size: Keep functions small (~30 lines) and focused on a single responsibility.
- Conditionals: Use early returns (guard clauses) to avoid deep nesting.
-
Explore
- Understand existing implementation and patterns.
- Check
Templates/for reference implementations.
-
Plan
- List files to create/modify.
- Identify necessary Docker image dependencies.
- Plan for
pack_metadata.jsonandReleaseNotes.
-
Implement
- Start with core logic in
.pyfile. - Define commands/args in
.ymlfile.
- Start with core logic in
-
Test
- Create
_test.pyfile. - Use
demistomockandrequests_mock. - Run
demisto-sdk pre-commit -i <path>.
- Create
-
Self-review
- Check for hardcoded values.
- Ensure
CommandResultsandreturn_results()are used correctly. - Verify
dockerimagein YAML matches requirements.
- Statelessness: Integrations must be stateless.
- Isolation: Each execution is independent.
- Security: No hardcoded credentials. Use
demisto.params(). - Clarity: Human-readable outputs (
tableToMarkdown) are as important as machine-readable context.