> ## Documentation Index
> Fetch the complete documentation index at: https://praison.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Lifecycle Command Guard Policy • AI Agent SDK

> LifecycleCommandGuardPolicy: Config-driven, command-anchored guard against gateway self-lifecycle hits.

# LifecycleCommandGuardPolicy

> Defined in the [**protocols**](../modules/protocols) module.

<Badge color="blue">AI Agent</Badge>

Config-driven, command-anchored guard against gateway self-lifecycle hits.

The default referenced by `gateway.lifecycle_guard` blocks in
`gateway.yaml` and the `BotOS(..., lifecycle_policy=...)` Python
surface. It is intentionally minimal and dependency-free so the decision
lives in core and is provable in isolation; the wrapper owns the consult
points (shell-tool executor, scheduler job registration) and the audit log.

Matching is *structural*, not prose-based, to avoid false positives on
ordinary English (e.g. "please stop the gateway from spamming"):

* `praisonai gateway stop|restart|reload` — the CLI self-control verbs,
  matched only when `praisonai` and `gateway` appear as adjacent
  command tokens followed by a lifecycle verb.
* `pkill` / `kill` / `killall` naming the gateway (a configured
  `process_names` token — `praisonai` by default — appearing as a whole
  component in the argument list or a `-f` pattern).
* `systemctl` / `launchctl` / `sc` `stop` / `restart` / `kill`
  on a unit whose name mentions the gateway (same whole-component match).

Matching is *whole-component*, not bare substring: unrelated services whose
name merely contains a token (`api-gateway`, `kong-gateway`) are not
tripped, while the real `praisonai-gateway` unit still matches.

The scan is applied to every `;`/`&&`/`||`/pipe-separated segment of
the command *and* to any additional script text supplied, so a command that
shells out to a wrapper script cannot smuggle the intent past the guard.

`default_allow` is a fail posture: on any internal parsing error the guard
keeps today's behaviour (allow) unless `default_allow=False` is set for a
strict, fail-closed deployment. `enabled=False` disables the guard
entirely (an operator who legitimately wants an agent to manage the
process).

Example::

```python theme={"theme":{"light":"vitesse-light","dark":"vitesse-dark"}}
LifecycleCommandGuardPolicy()                    # on by default
LifecycleCommandGuardPolicy(enabled=False)       # opt out
LifecycleCommandGuardPolicy(process_names=["praisonai", "mybot"])
```

## Constructor

<ParamField query="enabled" type="bool" required={false} default="True">
  No description available.
</ParamField>

<ParamField query="process_names" type="Optional" required={false}>
  No description available.
</ParamField>

<ParamField query="default_allow" type="bool" required={false} default="True">
  No description available.
</ParamField>

## Methods

<CardGroup cols={2}>
  <Card title="evaluate()" icon="function" href="../functions/LifecycleCommandGuardPolicy-evaluate">
    Return a :class:`LifecycleCommandDecision` for `command`.
  </Card>
</CardGroup>

## Source

<Card title="View on GitHub" icon="github" href="https://github.com/MervinPraison/PraisonAI/blob/main/src/praisonai-agents/praisonaiagents/gateway/protocols.py#L4986">
  `praisonaiagents/gateway/protocols.py` at line 4986
</Card>
