Skip to main content
Outcome: After this guide, you can create AI-powered threat monitors that detect security scenarios in real-time using natural language descriptions.
Prerequisites: SSH or Kubernetes configured, Formal API key, with an AI provider configured; optionally an deployed and linked to the connector.

Overview

Formal’s Session Monitors use large language models to detect security threats in SSH and Kubernetes sessions based on natural language descriptions. Instead of writing complex regex patterns or code, you describe the threat scenario in plain English, and Formal’s AI analyzes session activity in real-time. When a scenario is detected, it appears in input.triggered_monitors and can trigger actions like blocking, alerting, or requiring MFA.

How It Works

  1. Create a scenario monitor with a natural language description of the threat
  2. AI analyzes sessions in real-time (SSH commands, Kubernetes operations)
  3. Scenario detection adds an entry to the input.triggered_monitors array
  4. Policy enforcement takes action when scenarios are detected
Each entry is an object. Match on its name, as described in Using Scenarios in Policies.

Creating Monitors

Via Control Plane

Navigate to Session Monitors in the Control Plane and click Create:
  1. Name: Identifier for the scenario (e.g., ssh_curl_to_bash)
  2. Description: Natural language description of the threat
  3. Status: Active to enable detection, or Inactive to disable

Example Scenarios

Prevent Secrets Exfiltration

Name: prevent_secrets_exfil Description:

Jailbreak Detection

Name: jailbreak Description:

Prevent PR Review Manipulation

Name: prevent_pr_review Description:

SSH Curl to Bash

Name: ssh_curl_to_bash Description:

Via API

Use the CreateScenarioMonitor endpoint to create scenarios programmatically:

Using Scenarios in Policies

Once a scenario monitor is active, detected scenarios appear in the input.triggered_monitors array during policy evaluation. Each entry is an object: Match on name. SSH and Kubernetes sessions only set name, so id and reason are empty there.

Block Detected Threats

Quarantine the User

Quarantine ends every active session of the user and blocks the user. The user can’t open SSH, Kubernetes, or RDP sessions until an admin clicks Unblock User on the user’s page. See Quarantine Action.

Require MFA for Risky Actions

Alert on Suspicious Activity

Set policy notification to “Owners” to receive alerts.

Policy Actions

Available actions when scenarios are detected:

Best Practices

Provide clear context and specific examples in scenario descriptions. Instead of “detect suspicious commands,” write “detect commands that attempt to access /etc/shadow or other password files.”
Start with allow action and logging to validate detection accuracy before blocking or quarantining.
quarantine locks the user out of SSH, Kubernetes, and RDP until an admin unblocks them. Use it when access should resume only after human review, such as potential data exfiltration. Use suspend to end one session without locking the user out.
Use AI scenario monitoring alongside traditional Rego policies for defense in depth. AI handles complex patterns; Rego handles precise rules.
Review detected scenarios regularly to tune descriptions and reduce false positives.

Troubleshooting

Possible causes:
  • Scenario description is too vague or ambiguous
  • Status is set to inactive
  • Session type doesn’t match (e.g., database sessions vs. SSH)
Solution:
  1. Make description more specific with concrete examples
  2. Verify status is active
  3. Ensure scenario is appropriate for the resource type (SSH/K8s only)
Possible causes:
  • Description is too broad
  • Lacks sufficient context
Solution:
  1. Add specific exclusions to the description (e.g., “but not in login forms”)
  2. Provide more context about legitimate vs. malicious behavior
  3. Use allow with a reason to log borderline cases before enforcing
Possible causes:
  • No active scenario monitors
  • Policy evaluated before scenario analysis completed
  • Resource type doesn’t support scenario monitoring
Solution:
  1. Verify scenarios exist and are active
  2. Check that resource technology is SSH or Kubernetes
  3. Review session logs to confirm AI analysis ran