SafePilot Deployment and Usage Guide
This guide provides comprehensive instructions for deploying and using SafePilot, an AI assistant designed to execute real work safely.
1. Prerequisites
Before deploying SafePilot, ensure you have the following installed and configured:
- Rust Toolchain: SafePilot is built with Rust. Install
rustupby following the instructions on rustup.rs. - Docker and Docker Compose: For containerized deployment, Docker and Docker Compose are highly recommended.
- Telegram Bot Token: Obtain a bot token by talking to BotFather on Telegram.
- LLM Provider API Key: SafePilot supports Anthropic and OpenAI. You will need an API key for your chosen provider.
- SQLite: SafePilot uses SQLite for persistent storage. No separate installation is typically needed as it's embedded, but ensure your environment can handle SQLite database files.
2. Installation
-
Clone the Repository:
git clone https://github.com/3DCF-Labs/safepilot.git cd safepilot -
Build (if not using Docker):
cargo build --releaseThe executable will be located at
target/release/safepilot.
3. Configuration
SafePilot is configured primarily through environment variables. It's recommended to use a .env file for local development or Docker Compose secrets for production.
Minimum Required Configuration:
BOT_TOKEN: Your Telegram bot token.ALLOWED_USER_ID: Your Telegram user ID (numeric) to bootstrap as the owner. This user will have full access.LLM_MODE:directoragent.directis recommended for initial setup.LLM_PROVIDER:anthropicoropenai.ANTHROPIC_API_KEYorOPENAI_API_KEY: Your API key for the chosen LLM provider. UseANTHROPIC_API_KEY_FILEorOPENAI_API_KEY_FILEfor production with file-based secrets.
Recommended Security Configuration:
STRICT_SECRET_FILE_PERMS=1: Enforceschmod 600on secret files.ORCH_MASTER_KEY_FILE: Path to a file containing your master encryption key for sensitive DB fields. If unset, a key will be auto-generated at~/.tg-orch/keys/master.key.AGENT_ENABLE_WRITE_TOOLS=0: Disable agent's write capabilities by default.AGENT_ENABLE_BROWSER_TOOL=0: Disable agent's browser tool by default.
File-based Secrets (Recommended for Production):
Instead of directly setting *_KEY environment variables, use *_KEY_FILE to point to a file containing the secret.
Example:
BOT_TOKEN_FILE=/run/secrets/telegram_bot_token
ANTHROPIC_API_KEY_FILE=/run/secrets/anthropic_api_key
ORCH_MASTER_KEY_FILE=/run/secrets/master_encryption_key
Ensure these files have chmod 600 permissions.
Other Important Configuration Variables:
DATA_DIR: Directory for SQLite database and other persistent data (default:./data).LOG_DIR: Directory for logs (default:./logs).WORKSPACE_BASE_DIR: Base directory for workspace execution (default:./workspaces).LLM_HTTP_TIMEOUT_SECS: Timeout for LLM HTTP requests (default: 60).ANTHROPIC_MODEL/OPENAI_MODEL: Specify the LLM model to use.ALLOWED_SHELL_COMMANDS: Comma-separated list of bare binary names allowed forshellactions (e.g.,git,ls,cat).UNSAFE_SHELL_COMMANDS: Comma-separated list of bare binary names allowed forshellactions that require approval.TG_ORCH_SAFE_PATH: MinimalPATHfor subprocesses.TG_ORCH_DANGEROUS_SANDBOX_ENABLED: Enable Linux sandboxing for dangerous jobs.
4. Build & Run
Local Development (without Docker)
-
Create a
.envfile:BOT_TOKEN=YOUR_TELEGRAM_BOT_TOKEN ALLOWED_USER_ID=YOUR_TELEGRAM_USER_ID LLM_MODE=direct LLM_PROVIDER=anthropic # or openai ANTHROPIC_API_KEY=YOUR_ANTHROPIC_API_KEY # or OPENAI_API_KEY DATA_DIR=./data LOG_DIR=./logs WORKSPACE_BASE_DIR=./workspaces -
Run SafePilot:
cargo run --release
Production with Docker Compose (Recommended)
The provided docker-compose.yml is configured for production use, leveraging secrets and persistent volumes.
-
Prepare Secret Files: Create files for your secrets (e.g.,
telegram_bot_token.txt,anthropic_api_key.txt,master_encryption_key.txt).echo "YOUR_TELEGRAM_BOT_TOKEN" > telegram_bot_token.txt echo "YOUR_ANTHROPIC_API_KEY" > anthropic_api_key.txt # Generate a random 32-byte key for ORCH_MASTER_KEY_FILE openssl rand -base64 32 > master_encryption_key.txtEnsure these files have
chmod 600permissions. -
Edit
docker-compose.yml:- Uncomment and configure the
secretssection to point to your secret files. - Adjust
environmentvariables as needed, especiallyLLM_MODE,LLM_PROVIDER,ALLOWED_USER_ID, andORCH_MASTER_KEY_FILE. - Ensure
DATA_DIRandLOG_DIRare mapped to persistent volumes.
Example
docker-compose.ymlsnippet:version: '3.8' services: safepilot: image: 3dcf/safepilot:latest container_name: safepilot restart: unless-stopped environment: # Basic configuration ALLOWED_USER_ID: "YOUR_TELEGRAM_USER_ID" LLM_MODE: "direct" LLM_PROVIDER: "anthropic" # or openai # File-based secrets BOT_TOKEN_FILE: "/run/secrets/telegram_bot_token" ANTHROPIC_API_KEY_FILE: "/run/secrets/anthropic_api_key" # or OPENAI_API_KEY_FILE ORCH_MASTER_KEY_FILE: "/run/secrets/master_encryption_key" # Security recommendations STRICT_SECRET_FILE_PERMS: "1" AGENT_ENABLE_WRITE_TOOLS: "0" AGENT_ENABLE_BROWSER_TOOL: "0" # Data directories DATA_DIR: "/app/data" LOG_DIR: "/app/logs" WORKSPACE_BASE_DIR: "/app/workspaces" # Optional: 3DCF compression # ENABLE_3DCF_COMPRESSION: "1" volumes: - safepilot_data:/app/data - safepilot_logs:/app/logs - safepilot_workspaces:/app/workspaces secrets: - telegram_bot_token - anthropic_api_key # or openai_api_key - master_encryption_key secrets: telegram_bot_token: file: ./telegram_bot_token.txt anthropic_api_key: file: ./anthropic_api_key.txt master_encryption_key: file: ./master_encryption_key.txt volumes: safepilot_data: safepilot_logs: safepilot_workspaces: - Uncomment and configure the
-
Deploy with Docker Compose:
docker compose up -d
5. Deployment
SafePilot is designed for self-hosted deployment. The recommended approach is using Docker Compose as detailed above.
Key considerations for production deployment:
- Security Hardening: Review
docs/hardening.mdanddocs/docker.mdfor host and Docker hardening best practices. - Secrets Management: Always use file-based secrets (
*_FILEenvironment variables) and integrate with your secret management solution (e.g., Docker secrets, Kubernetes secrets, Vault). - Persistent Storage: Ensure
DATA_DIR,LOG_DIR, andWORKSPACE_BASE_DIRare mapped to persistent volumes to avoid data loss on container restarts. - Resource Allocation: Monitor CPU, memory, and disk usage and allocate sufficient resources. LLM interactions can be memory-intensive.
- Monitoring and Logging: Set up monitoring for the SafePilot container and review logs regularly for issues.
6. Troubleshooting
-
Bot Not Responding:
- Check
BOT_TOKENandALLOWED_USER_IDare correctly set. - Verify the bot token is active with BotFather.
- Check SafePilot logs for connection errors to Telegram.
- Ensure your server's network allows outbound connections to Telegram API.
- Check
-
LLM API Errors:
- Verify
ANTHROPIC_API_KEYorOPENAI_API_KEYis correct and has access to the specified model. - Check SafePilot logs for LLM provider error messages.
- Ensure your server's network allows outbound connections to Anthropic/OpenAI APIs.
- Check your LLM provider's usage limits and billing.
- Verify
-
"Permission Denied" Errors:
- If running without Docker, ensure the user running SafePilot has write permissions to
DATA_DIR,LOG_DIR, andWORKSPACE_BASE_DIR. - If using Docker, verify volume mounts are correctly configured and the container user has permissions within the mounted volumes.
- For file-based secrets, ensure the secret files are readable by the SafePilot process (e.g.,
chmod 600).
- If running without Docker, ensure the user running SafePilot has write permissions to
-
Tasks Blocked / Not Executing:
- In
LLM_MODE=agent, risky tasks require approval. Check Telegram for approval prompts (inline buttons or natural language "yes"). - Review the
docs/security-model.mdfor understanding task classification and approval workflows. - Check the SafePilot logs for policy enforcement messages.
- In
-
shellcommand failures:- Ensure the command is in the
ALLOWED_SHELL_COMMANDSorUNSAFE_SHELL_COMMANDSlist. - Remember that
bashandshare explicitly refused by default for safety. Use specific binaries likegit,ls,cat. - Subprocesses run with a cleared environment and minimal
PATH. Ensure necessary binaries are available in theTG_ORCH_SAFE_PATHor fully qualified.
- Ensure the command is in the
-
SSRF Protection Blocking
fetch:- The
fetchtool blocks private/loopback/link-local/metadata IPs by default. If you need to access internal resources, you might need to adjust network policies (refer to security documentation, but proceed with caution).
- The
-
Database Encryption Issues:
- If
ORCH_MASTER_KEY_FILEis used, ensure the file exists and contains the correct key. - Losing the master key will result in unrecoverable encrypted data. Back up your master key securely.
- If
For further debugging, increase the logging level by setting RUST_LOG=debug or RUST_LOG=trace in your environment variables.