DEV Community

Qasim Muhammad
Qasim Muhammad

Posted on

Agent Policies and Rules — Control What Your AI Agent Can Send and Receive

The nylas agent policy and nylas agent rule commands define guardrails for AI agent email accounts. Set who the agent can email, what triggers are allowed, and what actions to take on inbound messages — all enforced server-side.

What policies and rules do

A policy is a named container for rules. Rules define conditions and actions: "if the sender is external, block" or "if sending to a non-internal domain, require approval." These fire before the agent sees the message, so prompt injection can't bypass them.

Quick Start

nylas agent policy create --name "production-guardrails" --json
nylas agent rule create \
  --name "internal-only-outbound" \
  --condition "recipient_domain != company.com" \
  --action block
Enter fullscreen mode Exit fullscreen mode

Key commands

Command What it does
nylas agent policy list List all policies
nylas agent policy create --name N Create a named policy
nylas agent policy get <id> Show policy details
nylas agent policy delete <id> --yes Delete a policy
nylas agent rule list List all rules
nylas agent rule create --name N --condition C --action A Create a rule from flags
nylas agent rule create --data-file rule.json Create from JSON file
nylas agent rule get <id> Show a rule
nylas agent rule delete <id> --yes Delete a rule
nylas agent account create <email> --policy-id <id> Attach policy to agent

Example: restrict outbound to internal domains only

# Create policy
POLICY=$(nylas agent policy create --name "internal-only" --json | jq -r '.id')

# Add rule: block any outbound to non-company domains
nylas agent rule create \
  --policy-id $POLICY \
  --name "block-external-send" \
  --condition "direction == outbound AND recipient_domain != mycompany.com" \
  --action block

# Attach to agent account
nylas agent account create agent@mycompany.nylas.email --policy-id $POLICY
Enter fullscreen mode Exit fullscreen mode

Example: auto-archive marketing emails

nylas agent rule create \
  --name "archive-marketing" \
  --condition "sender_domain IN (marketing.example.com, promo.example.com)" \
  --action archive
Enter fullscreen mode Exit fullscreen mode

Related posts


All commands: Nylas CLI Command Reference

Get started: brew install nylas/nylas-cli/nylasother install methods

Top comments (0)