Skip to main content
File tools reject writes to sensitive paths — .env, SSH keys, the SDK, and system files.
from praisonaiagents import Agent
from praisonai.code.tools import write_file

agent = Agent(
    name="SafeCoder",
    instructions="Edit project files only. Never touch system paths.",
    tools=[write_file],
)

agent.start("Append 'test' to /etc/passwd")
# Tool returns: Path '/etc/passwd' is protected
The user asks the agent to change files; protected-path rules block dangerous writes before the tool runs.

How It Works

Quick Start

1

Simple Usage

Protected-path checks apply automatically when using praisonai code tools:
from praisonaiagents import Agent
from praisonai.code.tools import write_file

agent = Agent(name="Coder", instructions="Edit safely", tools=[write_file])
agent.start("Write hello to src/app.py")
2

With Configuration

Inspect protection before a write:
from praisonai.security import is_protected, get_protection_reason

if is_protected(".env"):
    print(get_protection_reason(".env"))
# Environment file containing secrets

How It Works

is_protected() and get_protection_reason() in praisonai.security.protected guard write_file, append_to_file, search_replace, and apply_diff. Protected targets include environment files, .git/, SSH keys, ~/.aws/, /etc/passwd, praisonaiagents/, and audit.jsonl. Blocked calls return:
{"success": False, "error": "Path '/etc/passwd' is protected: <reason>"}

Configuration Options

FunctionReturnsDescription
is_protected(path)boolWhether the path is blocked
get_protection_reason(path)str | NoneHuman-readable reason
is_protected(path, extra_protected=[...])boolAdd project-specific paths

Best Practices

Protected-path checks are a safety default — extend extra_protected only after review.
Protection is enforced in praisonai.code.tools, not the core FileTools class.
Call is_protected() in custom write tools that bypass the built-in guards.
Even with protection, avoid passing .env contents into agent context.

Security Overview

Full security feature matrix

Shell Tools

Dangerous command protection