Skip to main content
The Palyra Policy Engine provides a fine-grained, centralized authorization layer built on top of the Cedar Policy Language. It is responsible for evaluating every sensitive action within the daemon—ranging from tool execution and skill invocation to vault access and memory management. The engine bridges high-level security requirements with low-level runtime constraints like sandboxing tiers and egress enforcement.

Architecture and Data Flow

The policy engine operates as a request-response system. When a component (e.g., the GatewayService or ToolCallHandler) needs to verify an action, it constructs a PolicyRequest and a PolicyRequestContext. These are then evaluated against a PolicySet containing Cedar policies.

Policy Evaluation Flow

Sources: crates/palyra-policy/src/lib.rs#217-250, crates/palyra-daemon/src/tool_protocol.rs#3-10

Key Data Structures

PolicyRequest and Context

The engine uses three primary structures to define the authorization boundary:
StructureRoleKey Fields
PolicyRequestThe “Triple” of the requestprincipal, action, resource
PolicyRequestContextEnvironment/Execution datadevice_id, run_id, capabilities, tool_name
PolicyEvaluationConfigRuntime allowlistsallowlisted_tools, sensitive_actions, tool_execute_channel_allowlist
Sources: crates/palyra-policy/src/lib.rs#11-38

Cedar Policy Implementation

Palyra ships with a DEFAULT_POLICY_SRC that defines the baseline security posture. This includes “Deny by Default” logic and specific permits for core operations.

Baseline Policy Logic

AccessRegistry and Feature Flags

The AccessRegistry manages the persistence of identity-linked permissions, API tokens, and feature flags. It is stored in access_registry.json crates/palyra-daemon/src/access_control.rs#13-14.

Feature Flags and RBAC

The system uses feature flags to toggle advanced authorization modes:

Integration with Tool Execution

The policy engine is tightly coupled with the SandboxProcessRunner. Before a tool is executed, the ToolCallConfig determines the sandbox tier and egress enforcement mode.

Egress Enforcement Modes

  1. None: No network restrictions.
  2. Preflight: Checks requested hosts against an allowlist before spawning.
  3. Strict: Enforces network isolation at the OS level (e.g., via bwrap --unshare-net) crates/palyra-daemon/src/sandbox_runner.rs#47-62.

Mapping System Logic to Code Entities

Sources: crates/palyra-policy/src/lib.rs#11-38, crates/palyra-daemon/src/access_control.rs#186-200, crates/palyra-daemon/src/sandbox_runner.rs#81-93

API Token Management

The AccessRegistry handles ApiTokenRecord structures, which are used for the OpenAI-compatible “Compat API” crates/palyra-daemon/src/transport/http/handlers/compat.rs#105-126. These tokens are hashed using SHA-256 before storage crates/palyra-daemon/src/access_control.rs#155.
FeatureCode Reference
Token Rate LimitingDEFAULT_TOKEN_RATE_LIMIT_PER_MINUTE crates/palyra-daemon/src/access_control.rs#16
Scope ValidationMissingScope Error crates/palyra-daemon/src/access_control.rs#71
Token Rotationrotated_from_token_id crates/palyra-daemon/src/access_control.rs#172

Sandbox Tier Policy

Policy decisions also dictate the sandbox “Tier” used for execution: Sources: crates/palyra-daemon/src/sandbox_runner.rs#64-78, crates/palyra-sandbox/src/lib.rs#81-91