10 AutoGPT Environment Variables You Need to Configure
Master AutoGPT configuration with these 10 essential environment variables. Set API keys, select models, control costs, and tune performance.
Get more content like this on Telegram!
Daily AI tips, notes & resources — free
Getting AutoGPT running is one thing. Getting it running correctly is another. Most people clone the repo, paste in an API key, and then watch their autonomous agent either hallucinate wildly, spend $40 in an afternoon, or refuse to do anything useful at all.
The difference between those outcomes almost always lives in the .env file.
AutoGPT exposes dozens of configuration options through environment variables, and the defaults are tuned for demonstration — not production use. This guide covers the 10 variables that actually matter, what they do, what the sane defaults are, and what you should change before you let your agent run loose.
What Is the .env File?
When you clone AutoGPT, the project ships with a .env.template. Your first step is always:
cp .env.template .env
This file is a flat key=value store that AutoGPT reads at startup. It is not Python, not YAML, and not JSON — it is a plain text file. If a value contains spaces, wrap it in double quotes. If you need to comment something out, prefix it with #.
Never commit .env to version control. It contains your API keys. Add it to .gitignore immediately.
# Make sure .env is ignored
echo ".env" >> .gitignore
The .env Reference Table
Here are all 10 critical variables in one place before we go deep on each:
| Variable | Default | Purpose |
|---|---|---|
OPENAI_API_KEY | (empty) | Authenticates all GPT calls |
SMART_LLM | gpt-4 | Model for complex reasoning tasks |
FAST_LLM | gpt-3.5-turbo | Model for simple/fast tasks |
OPENAI_API_BUDGET | 0.0 (unlimited) | Hard stop on spending in USD |
MEMORY_BACKEND | local | Where agent memory is stored |
RESTRICT_TO_WORKSPACE | True | Prevents file writes outside workspace |
BROWSE_CHUNK_MAX_LENGTH | 3000 | Chars per web page chunk |
EXECUTE_LOCAL_COMMANDS | False | Allows shell command execution |
USER_AGENT | Mozilla string | Browser identity for web requests |
TEMPERATURE | 0 | LLM response randomness |
Now let us walk through each one in detail.
1. OPENAI_API_KEY
OPENAI_API_KEY=sk-proj-xxxxxxxxxxxxxxxxxxxx
This is the non-negotiable one. Without it, nothing works. A few things worth knowing:
- Generate a fresh key specifically for AutoGPT at platform.openai.com. Do not reuse keys from other projects.
- Set a spending limit on the OpenAI dashboard as a secondary guard — do not rely on
OPENAI_API_BUDGETalone. - If you are using Azure OpenAI, you also need
OPENAI_API_BASE,OPENAI_API_TYPE=azure, andOPENAI_API_VERSION.
For Azure:
OPENAI_API_KEY=your-azure-key
OPENAI_API_BASE=https://your-resource.openai.azure.com/
OPENAI_API_TYPE=azure
OPENAI_API_VERSION=2024-02-15-preview
If you want to understand how this integrates with a full stack, see our OpenAI API integration guide.
2. SMART_LLM and FAST_LLM
SMART_LLM=gpt-4-turbo
FAST_LLM=gpt-3.5-turbo
AutoGPT uses a two-tier model system. SMART_LLM handles planning, reasoning, and anything complex. FAST_LLM handles quick classification, summarization, and auxiliary tasks.
The cost difference between these two settings is dramatic:
| Configuration | Approx. cost per hour of agent work |
|---|---|
| Both GPT-4 | $12–25 |
| GPT-4 smart + GPT-3.5 fast | $3–8 |
| Both GPT-3.5 | $0.50–2 |
| GPT-4o smart + GPT-3.5 fast | $2–6 |
For most research and automation tasks, gpt-4-turbo for smart and gpt-3.5-turbo for fast is the practical sweet spot. Switch both to GPT-4o if you are doing heavy code generation.
If you are building a LangChain-based agent, you handle model selection differently — but AutoGPT's split approach is one of its more sensible architectural choices.
3. OPENAI_API_BUDGET
OPENAI_API_BUDGET=5.0
This sets a hard dollar limit. When accumulated costs hit this number, AutoGPT stops and asks before continuing. Setting it to 0.0 means unlimited, which is the default and also the easiest way to get an unpleasant surprise on your billing statement.
For development and testing, set this to 1.0 or 2.0. For production tasks you trust, set it to a realistic ceiling for that task. For a task that should cost $0.50, setting a $10 budget still protects you from runaway loops.
# Development
OPENAI_API_BUDGET=1.0
# Production task with known scope
OPENAI_API_BUDGET=10.0
# Unlimited (only for benchmarking)
OPENAI_API_BUDGET=0.0
4. MEMORY_BACKEND
MEMORY_BACKEND=local
This controls where AutoGPT stores its working memory — the information it accumulates across task steps. Options include local, redis, pinecone, milvus, and weaviate.
The local backend writes to a local JSON file. It is slow for large knowledge bases but requires zero setup. For anything more serious, read our dedicated AutoGPT memory types guide which covers all five backends with benchmarks.
# For Redis (fast, ephemeral)
MEMORY_BACKEND=redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# For Pinecone (persistent, cloud)
MEMORY_BACKEND=pinecone
PINECONE_API_KEY=your-pinecone-key
PINECONE_ENV=us-east-1
See also our vector database guide for help choosing between Pinecone, Weaviate, and Milvus for production deployments.
5. RESTRICT_TO_WORKSPACE
RESTRICT_TO_WORKSPACE=True
When True, AutoGPT can only read and write files within its designated workspace directory (auto_gpt_workspace/ by default). This is a critical security control.
With it set to False, a sufficiently creative agent goal could result in the agent reading files from anywhere on your filesystem or writing to system directories. This is not hypothetical — autonomous agents are genuinely good at finding creative paths to their goals.
Leave this True unless you have a specific, understood reason to change it. If you need the agent to access files outside the workspace, mount or symlink those directories into the workspace instead of disabling this restriction.
For a full picture of what AutoGPT can do with your files, check our AutoGPT file system operations guide.
6. BROWSE_CHUNK_MAX_LENGTH
BROWSE_CHUNK_MAX_LENGTH=3000
When AutoGPT browses a web page, it chunks the content and summarizes each chunk before reasoning about it. This variable controls how large those chunks are in characters.
Smaller chunks mean more API calls (more cost, more latency) but better handling on rate-limited models. Larger chunks are more efficient but can exceed context windows on older models.
| Model | Recommended chunk size |
|---|---|
| gpt-3.5-turbo | 2000–3000 |
| gpt-4 | 4000–6000 |
| gpt-4-turbo / gpt-4o | 6000–10000 |
# Conservative (older models or rate limited)
BROWSE_CHUNK_MAX_LENGTH=2000
# Standard
BROWSE_CHUNK_MAX_LENGTH=3000
# Aggressive (GPT-4 Turbo / GPT-4o)
BROWSE_CHUNK_MAX_LENGTH=8000
7. EXECUTE_LOCAL_COMMANDS
EXECUTE_LOCAL_COMMANDS=False
This one deserves its own warning banner. When set to True, AutoGPT can run shell commands on your machine. It can install packages, run scripts, delete files, make network requests, and much more.
This is powerful and dangerous in equal measure. The risk is not just that AutoGPT makes a mistake — it is that a poorly crafted goal can lead the agent to do things you did not intend, including things that cannot be easily undone.
If you need this capability, consider running AutoGPT inside a Docker container with restricted permissions rather than enabling it on your host machine directly.
# Running in Docker with limited permissions
docker run --rm \
-v $(pwd)/workspace:/app/auto_gpt_workspace \
--network bridge \
significantgravitas/auto-gpt
8. USER_AGENT
USER_AGENT="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.97 Safari/537.36"
When AutoGPT browses the web, it identifies itself using this user agent string. Many websites block or serve degraded content to requests that look like bots. Using a realistic browser user agent string helps the agent get useful responses.
You can update this to match a more recent browser version. The key is that it should look like a real browser, not an automated tool.
# Chrome 120 on Windows
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
9. TEMPERATURE
TEMPERATURE=0
Temperature controls how "creative" or random the LLM's outputs are. At 0, the model is fully deterministic and picks the highest-probability token every time. At 1.0, responses are more varied.
For autonomous agents, lower temperatures are almost always better. An agent that gives consistent, predictable responses is far easier to debug and trust than one that varies its behavior between runs.
# Fully deterministic (recommended for agents)
TEMPERATURE=0
# Slight variation (useful for creative tasks)
TEMPERATURE=0.3
# High variation (not recommended for autonomous agents)
TEMPERATURE=0.8
If you are building conversational agents where some personality variation is desirable, see how AI agents and multi-turn conversations handle this differently.
10. GitHub and Search API Keys (Optional but Important)
GITHUB_API_KEY=ghp_xxxxxxxxxxxx
GITHUB_USERNAME=yourusername
GOOGLE_API_KEY=AIzaSy_xxxxxxxxxxxx
CUSTOM_SEARCH_ENGINE_ID=xxxxxxxxxxxx
These are optional but dramatically expand what AutoGPT can do. The GitHub integration lets the agent read and write to repositories. The Google Search integration gives it real web search capability rather than relying on Bing or DuckDuckGo fallbacks.
For GitHub:
- Go to github.com/settings/tokens
- Generate a token with
reposcope - Paste it into
GITHUB_API_KEY
For Google Custom Search:
- Create a project in Google Cloud Console
- Enable the Custom Search API
- Create a Custom Search Engine at cse.google.com
- Copy both the API key and the Search Engine ID
# Google search setup
GOOGLE_API_KEY=AIzaSy_your_key_here
CUSTOM_SEARCH_ENGINE_ID=your_engine_id_here
Putting It All Together: A Production .env Template
Here is a recommended starting configuration for a real AutoGPT deployment:
# === Core API ===
OPENAI_API_KEY=sk-proj-your-key-here
OPENAI_API_BUDGET=10.0
# === Models ===
SMART_LLM=gpt-4-turbo
FAST_LLM=gpt-3.5-turbo
TEMPERATURE=0
# === Memory ===
MEMORY_BACKEND=redis
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_PASSWORD=
# === Security ===
RESTRICT_TO_WORKSPACE=True
EXECUTE_LOCAL_COMMANDS=False
# === Browsing ===
BROWSE_CHUNK_MAX_LENGTH=5000
USER_AGENT="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
# === Optional Integrations ===
GITHUB_API_KEY=ghp_your_token
GITHUB_USERNAME=your_username
GOOGLE_API_KEY=AIzaSy_your_key
CUSTOM_SEARCH_ENGINE_ID=your_engine_id
# === Logging ===
LOG_LEVEL=INFO
PLAIN_OUTPUT=False
Validating Your Configuration
Before you run a real task, verify your setup with:
python -m autogpt --ai-name "TestBot" \
--ai-role "A helpful test assistant" \
--ai-goal "List the 3 largest files in the workspace directory" \
--ai-goal "Report the total size in bytes" \
--continuous-limit 5
The --continuous-limit 5 flag means the agent will run at most 5 steps before stopping, preventing any runaway behavior on your first test. Watch the output carefully — you should see model calls, memory operations, and tool use all logged to the terminal.
If you see errors about context length, reduce BROWSE_CHUNK_MAX_LENGTH. If you see budget exceeded errors immediately, check that OPENAI_API_BUDGET is set to a reasonable number. If you see memory errors, verify your Redis connection.
Common Configuration Mistakes
The most common mistake is leaving OPENAI_API_BUDGET=0.0 and not noticing the agent loop in a reasoning spiral. The second most common is using both SMART_LLM and FAST_LLM set to GPT-4 without any budget guard.
Third is enabling EXECUTE_LOCAL_COMMANDS=True without a sandboxed environment. Even if you trust your goal definition, one hallucinated command can cause real damage.
If you are planning to run AutoGPT continuously on a server, our guide on running AutoGPT on a VPS for 24/7 operation covers the additional environment and service configuration you will need.
What Comes Next
Once your environment is configured correctly, the next frontier is prompt strategy. A well-configured agent with a poorly defined goal still produces poor results. For that, read our AutoGPT prompt strategies guide which covers 10 techniques for writing goals that actually decompose cleanly into executable steps.
For context on how AutoGPT compares to other autonomous agent frameworks on the AI landscape, AI agents explained gives a solid baseline.
Frequently Asked Questions
Where is the AutoGPT .env file located? The .env file lives in the root of your AutoGPT project directory, next to main.py. Copy .env.template to .env before editing. Never commit this file to version control.
Can I switch AutoGPT to use GPT-3.5 instead of GPT-4? Yes. Set SMART_LLM=gpt-3.5-turbo and FAST_LLM=gpt-3.5-turbo in your .env file. This reduces cost significantly but may affect task quality for complex reasoning.
How do I limit AutoGPT's API spending? Set OPENAI_API_BUDGET to a dollar value like 5.0. AutoGPT will stop and prompt you when that budget is exhausted. Also set RESTRICT_TO_WORKSPACE=True to prevent file writes outside the workspace.
Frequently Asked Questions
AiTechWorlds Team
✓ Verified WriterThe AiTechWorlds team is passionate about AI, technology, and education. We create high-quality, research-backed content to help you learn, grow, and succeed in the modern digital world.
Related Articles
5 AutoGen Human Input Modes (Always, Never, Sometimes)
Master AutoGen's human input modes for hybrid autonomy. Learn when to use ALWAYS, NEVER, and TERMINATE with real code examples and a comparison table.
How to Use AutoGen with Tools (Web Scraper, Calculator, File)
Learn how to equip AutoGen agents with custom tools like web scrapers, calculators, and file handlers using register_for_llm and register_for_execution.
10 AutoGPT Command Line Arguments (Continuous Mode, Speak)
Complete reference for AutoGPT's 10 most powerful CLI arguments. Master continuous mode, headless operation, and CI/CD integration for automated agent workflows.
10 AutoGPT Configuration Tweaks for Better Performance
10 proven AutoGPT configuration tweaks to improve speed, cut costs, and boost task success. Model selection, temperature, token limits, and workspace settings.