Skip to content

Configuration

This page covers all configuration options for Anvil.

VariableProviderDescription
ANTHROPIC_API_KEYAnthropicClaude API key
OPENAI_API_KEYOpenAIGPT-4 API key
XAI_API_KEYxAIGrok API key
VariableDescription
FIRECRAWL_API_KEYFor fetching API documentation
Terminal window
# In terminal
export ANTHROPIC_API_KEY="sk-ant-..."
# In .env file
ANTHROPIC_API_KEY=sk-ant-...
FIRECRAWL_API_KEY=fc-...
from anvil import Anvil
anvil = Anvil(
# LLM Provider
provider="anthropic", # "anthropic", "openai", "grok"
model=None, # Provider-specific default if None
api_key=None, # From environment if None
# Tool Storage
tools_dir="./anvil_tools", # Where to save generated tools
)
anvil = Anvil(
self_healing=True, # Enable automatic regeneration
max_heal_attempts=2, # Max retries before giving up
)
anvil = Anvil(
mode="local", # "local", "stub", or "cloud"
use_stub=False, # Shorthand for mode="stub"
)
ModeDescription
localUse LLM to generate tools (default)
stubGenerate placeholder tools (no LLM)
cloudUse Anvil Cloud (coming soon)
anvil = Anvil(
interactive_credentials=True, # Prompt for missing keys
env_file=".env", # Where to save credentials
)
from anvil.sandbox import SecurityPolicy
anvil = Anvil(
verified_mode=True, # Verify code in sandbox
security_policy=SecurityPolicy( # Custom policy
allow_network=True,
allow_subprocess=False,
),
)
anvil = Anvil(
log_file="./anvil.log", # Enable file logging
)
from anvil.sandbox import SecurityPolicy
policy = SecurityPolicy(
# Network
allow_network=False,
allowed_hosts=None, # ["api.example.com"]
# Filesystem
allow_filesystem_read=True,
allow_filesystem_write=False,
allowed_paths=None, # ["/tmp", "./data"]
# System
allow_subprocess=False,
allow_env_access=True,
# Resource Limits
max_memory_mb=256,
max_cpu_seconds=30.0,
max_output_size_kb=1024,
# Custom Blocks
blocked_imports=None, # Additional imports to block
blocked_functions=None, # Additional functions to block
)
from anvil import InputParam
param = InputParam(
name="query", # Parameter name
param_type="str", # "str", "int", "float", "bool", "list"
required=True, # Is this required?
description="Search query", # Help text
default=None, # Default value
)

When model=None, these defaults are used:

ProviderDefault Model
Anthropicclaude-sonnet-4-20250514
OpenAIgpt-4o
Grokgrok-2-latest

After initialization, your project structure:

my-project/
├── .env # API keys (gitignored)
├── .gitignore # Protects .env
├── anvil_tools/
│ ├── __init__.py
│ ├── tool_registry.json # Tool metadata
│ ├── search_github.py # Generated tool
│ └── get_weather.py # Generated tool
├── anvil.log # Event log (if enabled)
└── main.py # Your code

anvil_tools/tool_registry.json:

{
"search_github": {
"name": "search_github",
"intent": "Search GitHub repositories",
"docs_url": "https://docs.github.com/...",
"hash": "a1b2c3d4e5f6",
"version": "1.0",
"status": "active",
"created_at": "2025-01-18T10:00:00Z",
"last_generated": "2025-01-18T10:00:00Z",
"error_count": 0
}
}

anvil_tools/search_github.py:

1.0
# ---
# ANVIL-MANAGED: true
# INTENT-HASH: a1b2c3d4e5f6
# ---
import requests
def run(query: str, **kwargs) -> dict:
"""Search GitHub repositories."""
response = requests.get(
"https://api.github.com/search/repositories",
params={"q": query}
)
response.raise_for_status()
return response.json()

JSON Lines format (one JSON object per line):

{"timestamp": "2025-01-18T10:00:00Z", "event_type": "tool_generated", "tool_name": "search_github", "duration_ms": 1250.5, "metadata": {}}
{"timestamp": "2025-01-18T10:00:01Z", "event_type": "tool_executed", "tool_name": "search_github", "duration_ms": 150.2, "metadata": {}}
anvil = Anvil(
tools_dir="./anvil_tools",
self_healing=True,
interactive_credentials=True,
)
anvil = Anvil(
use_stub=True, # No LLM calls
self_healing=False,
)
anvil = Anvil(
tools_dir="/app/tools",
self_healing=True,
max_heal_attempts=1,
verified_mode=True,
interactive_credentials=False,
log_file="/var/log/anvil/anvil.log",
)
anvil = Anvil(
use_stub=True,
interactive_credentials=False,
)