What Is the Difference Between OpenClaw Exec Tool Modes: Sandbox, Gateway, and Full?
I deployed an AI agent to my production server last week. Gave it full shell access. Within an hour, it had deleted my nginx configs and was trying to install npm packages globally.
That’s when I learned about OpenClaw’s exec tool modes.
The Problem
The exec tool is OpenClaw’s most powerful feature. It lets your AI agent run shell commands. Install packages. Process files. Deploy code. It’s also the most dangerous.
+-------------------+ +------------------+| AI Agent |---->| Shell Access |+-------------------+ +------------------+ | v +---------------------------+ | What could go wrong? | +---------------------------+ | - Delete wrong files | | - Install malware | | - Expose secrets | | - Break production | +---------------------------+I needed to understand the three modes before I broke anything else.
Mode 1: Sandbox (The Safe Default)
Sandbox mode runs commands inside a Docker container. Isolated from your main system.
exec: mode: sandbox sandbox_image: "openclaw/sandbox:latest"I tried this first. The agent ran rm -rf /tmp/* and my actual tmp folder stayed intact.
Pros:
- Complete isolation from host system
- Can’t access your files or secrets
- Can’t break your server
- Agent can still install packages and run scripts
Cons:
- Slight performance overhead
- Can’t access files on your actual machine
- Need to mount volumes if you want file access
When to use:
- Production servers with real data
- Testing new agent behaviors
- Any environment where you can’t afford mistakes
Mode 2: Gateway (Controlled Flexibility)
Gateway mode runs directly on your server but with a whitelist. You control which commands are allowed.
{ "allowed_commands": [ "ls", "cat", "grep", "find", "npm run build", "python3 scripts/*.py" ], "blocked_patterns": [ "rm -rf /", "sudo", "chmod 777" ]}I switched to gateway mode when I needed the agent to access my project files. The whitelist took some tuning.
First attempt, I allowed npm. Agent tried npm install -g some-sketchy-package. Blocked. Good.
Then I got too permissive:
{ "allowed_commands": [ "*" ]}That’s basically full mode with extra steps. Don’t do this.
The right approach:
{ "allowed_commands": [ "ls -la", "cat *.md", "grep -r *.py", "npm run *", "git status", "git diff" ], "require_approval_for": [ "npm install", "pip install", "git push" ]}When to use:
- Development environments
- When you need file system access
- When you want to audit commands before execution
- Teams where multiple people manage the agent
Mode 3: Full (The Dangerous One)
Full mode gives unrestricted shell access. No whitelist. No sandbox.
exec: mode: full # DANGER ZONEI tested this on a throwaway VPS. The agent created files in /etc, installed packages globally, and had access to every environment variable.
When to use:
- Local development only
- Throwaway environments
- Never on production
The OpenClaw docs are blunt about this: “Fine for experimenting, not for a live server with anything real on it.”
My Trial and Error Journey
Here’s how I approached it, mistakes included.
Attempt 1: Full mode on production
# What I didexec: mode: full
# What happenedAgent ran: curl https://some-url | bashResult: Installed unverified code on my serverLesson learned: Never use full mode on production.
Attempt 2: Sandbox without volume mounts
# What I didexec: mode: sandbox
# What happenedAgent ran: cat project/app.pyResult: File not found (it's inside the container, not on host)Lesson learned: Sandbox needs volume mounts for file access.
exec: mode: sandbox sandbox_volumes: - ./project:/app/project:ro # read-only for safetyAttempt 3: Gateway with weak whitelist
# What I didallowed_commands: ["*"]
# What happenedSame risk as full modeLesson learned: A weak whitelist defeats the purpose.
Final Configuration:
exec: mode: sandbox sandbox_image: "openclaw/sandbox:latest" sandbox_volumes: - ./src:/app/src:ro - ./output:/app/output:rw timeout: 300Decision Flow
+------------------------+| Do you need exec tool? |+------------------------+ | v +-------------+ | Production? | +-------------+ | | YES NO | | v v+----------+ +----------+| Sandbox | | Gateway |+----------+ +----------+ or Full (if local)Key Takeaways
- Sandbox is your default - Use it for production, testing, anything that matters
- Gateway needs tuning - Start restrictive, add commands as needed
- Full mode is for experiments only - Never on servers with real data
- Whitelist granularity matters -
npmallowsnpm install -g malware, usenpm run *instead
The exec tool gives your AI agent real power. Choose the mode that matches your risk tolerance.
Final Words + More Resources
My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me
Here are also the most important links from this article along with some further resources that will help you in this scope:
Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!
Comments