Back to Articles
Tutorial

How to Build Your Own AI Agent Without OpenClaw Security Risks

Step-by-step guide to building secure AI agents with proper isolation, permissions, and monitoring.

Serenities Team
Cover image for How to Build Your Own AI Agent Without OpenClaw Security Risks

How to Build Your Own AI Agent Without OpenClaw's Security Risks

\n\nOpenClaw is making headlines, but do you really want to give an AI agent full access to your computer? Here's how to build safer alternatives.\n\n
\n\nPublished: January 31, 2026 \nCategory: AI Development | Tutorial \nKeyword: build ai agent tutorial \nWord Count: 1,700+\n\n
\n\n

The OpenClaw Phenomenon—And Its Problems

\n\n

OpenClaw (formerly Clawdbot, then Moltbot) just went viral. Over 60,000 GitHub stars. Celebrity endorsements from Andrej Karpathy and David Sacks. Headlines everywhere.

\n\n

The appeal is obvious: an AI assistant that actually does things on your computer—sending emails, managing calendars, filling forms, automating workflows. All through a simple text interface in WhatsApp or Telegram.

\n\n

But here's what the hype cycle isn't telling you:

\n\n
    \n
  • Full system access means full system risk
  • \n
  • API costs can spiral into hundreds of dollars per month
  • \n
  • Security incidents have already plagued the project
  • \n
  • Dedicated hardware (like a Mac Mini) is often recommended
  • \n
\n

What if you could build AI agent capabilities without these tradeoffs?

\n\n

What You'll Learn in This Tutorial

\n\n

This guide walks you through building AI agents that are:

\n\n
    \n
  1. Sandboxed - Limited to specific capabilities you define
  2. \n
  3. Cost-controlled - Using efficient architectures and subscription-based models
  4. \n
  5. Secure - No full system access required
  6. \n
  7. Practical - Solving real problems without the Mac Mini tax
  8. \n
\n

We'll cover both no-code and code-based approaches, from beginner-friendly to advanced.

\n\n
\n\n

Understanding AI Agents: The Basics

\n\n

Before building, let's clarify what an AI agent actually is.

\n\n

The Three Components

\n\n

Every AI agent has three core parts:

\n\n
    \n
  1. Brain - The LLM that reasons and makes decisions (Claude, GPT-4, Gemini)
  2. \n
  3. Tools - The capabilities the agent can invoke (send email, search web, read files)
  4. \n
  5. Memory - Context that persists across conversations (user preferences, past interactions)
  6. \n
\n

OpenClaw bundles all three with extensive system-level permissions. We're going to be more surgical.

\n\n

The Agentic Loop

\n\n

Here's how agents work under the hood:

\n\n
User Message → LLM Processes → Tool Call Decision → Execute Tool → \n

LLM Processes Result → More Tools? → Final Response

\n\n

This loop continues until the agent has enough information to respond—or hits a safety limit.

\n\n
\n\n

Method 1: No-Code Agent Building (Beginner)

\n\n

If you've never built an agent before, start here.

\n\n

Option A: N8N Workflows

\n\nN8N is an open-source workflow automation platform that's become the darling of the AI agent community.\n\nWhy N8N?\n
    \n
  • Visual, drag-and-drop interface
  • \n
  • Self-hostable (free) or cloud version (0/month)
  • \n
  • Hundreds of pre-built integrations
  • \n
  • Native AI nodes for major LLM providers
  • \n
\nBasic Agent Setup:\n\n
    \n
  1. Create a Trigger - How does your agent receive input? (Webhook, schedule, email)
  2. \n
  3. Add AI Node - Connect to Claude, GPT-4, or Gemini
  4. \n
  5. Define Tools - Add nodes for actions (send email, update spreadsheet, post to Slack)
  6. \n
  7. Loop Logic - Use N8N's IF nodes to let the AI decide next steps
  8. \n
\nSample Workflow: Email Triage Agent\n\n
Email Trigger → AI Analyzes Email → \n

IF Urgent → Forward to phone

\n

IF Newsletter → Archive

\n

IF Needs Response → Draft reply → Wait for approval → Send

\n\n

Total setup time: ~30 minutes. Total code: zero lines.

\n\n

Option B: Make.com (Formerly Integromat)

\n\n

Similar to N8N but fully managed. Better for non-technical users who want zero maintenance.

\n\nPricing: Free tier available, paid starts at /month.\n\n
\n\n

Method 2: Low-Code Agent Frameworks (Intermediate)

\n\n

Ready for more control? These frameworks let you define agents with minimal code.

\n\n

LangGraph (Recommended)

\n\nLangGraph from LangChain is specifically designed for agent workflows.\n\nWhy LangGraph?\n
    \n
  • Graph-based architecture makes complex flows intuitive
  • \n
  • Built-in state management (memory!)
  • \n
  • Checkpointing for long-running agents
  • \n
  • Human-in-the-loop support
  • \n
\nSimple Agent in 50 Lines:\n\n
from langgraph.graph import StateGraph\n

from langchain_anthropic import ChatAnthropic

\n\n

Define your tools

\n

@tool

\n

def send_email(to: str, subject: str, body: str) -> str:

\n

"""Send an email using your configured SMTP server."""

\n

# Your email logic here

\n

return f"Email sent to {to}"

\n\n

@tool

\n

def search_web(query: str) -> str:

\n

"""Search the web for information."""

\n

# Your search logic here

\n

return "Search results..."

\n\n

Create agent

\n

tools = [send_email, search_web]

\n

llm = ChatAnthropic(model="claude-3-5-sonnet-20241022")

\n

agent = create_react_agent(llm, tools)

\n\n

Run

\n

result = agent.invoke({"messages": ["Send an email to mom wishing her happy birthday"]})

\n\nKey Security Feature: Notice how tools are explicitly defined. The agent can ONLY do what you permit.\n\n

CrewAI for Multi-Agent Systems

\n\n

If you need multiple agents collaborating, CrewAI provides a higher-level abstraction:

\n\n
from crewai import Agent, Task, Crew\n\n

researcher = Agent(

\n

role="Researcher",

\n

goal="Find accurate information on given topics",

\n

tools=[search_web]

\n

)

\n\n

writer = Agent(

\n

role="Writer",

\n

goal="Write compelling content based on research",

\n

tools=[write_document]

\n

)

\n\n

crew = Crew(

\n

agents=[researcher, writer],

\n

tasks=[research_task, writing_task]

\n

)

\n\n

result = crew.kickoff()

\n\n
\n\n

Method 3: Building From Scratch (Advanced)

\n\n

For maximum control and understanding, build your own agent loop.

\n\n

The ReAct Pattern

\n\n

Most agents use the ReAct (Reason + Act) pattern:

\n\n
import anthropic\n\n

client = anthropic.Anthropic()

\n\n

def agent_loop(user_message: str, tools: list, max_iterations: int = 10):

\n

messages = [{"role": "user", "content": user_message}]

\n\n

for _ in range(max_iterations):

\n

response = client.messages.create(

\n

model="claude-3-5-sonnet-20241022",

\n

max_tokens=4096,

\n

tools=tools,

\n

messages=messages

\n

)

\n\n

# Check if we need to call tools

\n

if response.stop_reason == "tool_use":

\n

tool_results = execute_tools(response.content)

\n

messages.append({"role": "assistant", "content": response.content})

\n

messages.append({"role": "user", "content": tool_results})

\n

else:

\n

# Agent is done

\n

return response.content[0].text

\n\n

return "Max iterations reached"

\n\n

Adding Memory

\n\n

Persistent memory is what separates agents from chatbots:

\n\n
from datetime import datetime\n

import json

\n\n

class AgentMemory:

\n

def __init__(self, filepath: str):

\n

self.filepath = filepath

\n

self.load()

\n\n

def load(self):

\n

try:

\n

with open(self.filepath, 'r') as f:

\n

self.data = json.load(f)

\n

except FileNotFoundError:

\n

self.data = {"facts": [], "preferences": {}, "history": []}

\n\n

def save(self):

\n

with open(self.filepath, 'w') as f:

\n

json.dump(self.data, f)

\n\n

def add_fact(self, fact: str):

\n

self.data["facts"].append({

\n

"content": fact,

\n

"timestamp": datetime.now().isoformat()

\n

})

\n

self.save()

\n\n

def get_context(self) -> str:

\n

"""Return memory as context for the LLM."""

\n

return f"Known facts: {self.data['facts']}Preferences: {self.data['preferences']}"

\n\n
\n\n

Security Best Practices

\n\n

This is where we diverge from OpenClaw's approach.

\n\n

Principle of Least Privilege

\n\n

Never give an agent more access than it needs:

\n\n
# BAD: OpenClaw-style full access\n

tools = [execute_shell_command, read_any_file, access_any_api]

\n\n

GOOD: Scoped permissions

\n

tools = [

\n

send_email_to_approved_recipients,

\n

read_files_in_specific_folder,

\n

access_calendar_read_only

\n

]

\n\n

Sandbox Execution

\n\n

For any code execution, use containers:

\n\n
import docker\n\n

def safe_execute(code: str) -> str:

\n

client = docker.from_env()

\n

container = client.containers.run(

\n

"python:3.11-slim",

\n

f"python -c '{code}'",

\n

remove=True,

\n

mem_limit="512m",

\n

network_disabled=True, # No network access!

\n

timeout=30

\n

)

\n

return container.decode()

\n\n

Human-in-the-Loop for Sensitive Actions

\n\n

Some actions should always require approval:

\n\n
SENSITIVE_ACTIONS = ["send_email", "post_to_social", "make_payment"]\n\n

def execute_tool(tool_name: str, args: dict) -> str:

\n

if tool_name in SENSITIVE_ACTIONS:

\n

if not await_human_approval(tool_name, args):

\n

return "Action cancelled by user"

\n

return toolstool_name

\n\n
\n\n

Cost Control Strategies

\n\n

OpenClaw users report spending 00-300/month on API costs. Here's how to do better.

\n\n

1. Use Subscriptions, Not APIs

\n\n

AI subscriptions (ChatGPT Plus, Claude Pro) are dramatically cheaper than API pricing for high-usage scenarios:

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Usage LevelAPI CostSubscription Cost
Light (100k tokens/day)5/month0/month
Medium (500k tokens/day)25/month0/month
Heavy (2M tokens/day)00/month0/month (with limits)
\nThe catch: Most subscriptions don't offer API access. This is where platforms like Serenities AI shine—they let you connect your existing subscriptions and use them programmatically, saving 10-25x compared to direct API pricing.\n\n

2. Smart Model Selection

\n\n

Not every request needs Claude 3.5 Sonnet:

\n\n
def select_model(task_complexity: str) -> str:\n

if task_complexity == "simple":

\n

return "claude-3-haiku-20240307" # Fast, cheap

\n

elif task_complexity == "medium":

\n

return "claude-3-5-haiku-20241022" # Good balance

\n

else:

\n

return "claude-3-5-sonnet-20241022" # Full power

\n\n

3. Caching Common Requests

\n\n

Many agent requests are similar. Cache them:

\n\n
import hashlib\n

from functools import lru_cache

\n\n

@lru_cache(maxsize=1000)

\n

def cached_llm_call(prompt_hash: str) -> str:

\n

# Return cached response

\n

pass

\n\n
\n\n

Putting It All Together

\n\n

Here's a complete, secure AI agent you can run today:

\n\n
# Full agent with security, memory, and cost control\n

See our GitHub repo for complete implementation

\n\nWhat this agent can do:\n
    \n
  • Respond via Telegram or WhatsApp
  • \n
  • Manage your calendar (read-only by default)
  • \n
  • Draft emails (requires approval to send)
  • \n
  • Research topics on the web
  • \n
  • Remember your preferences
  • \n
\nWhat it CAN'T do (by design):\n
    \n
  • Access arbitrary files on your system
  • \n
  • Execute arbitrary code
  • \n
  • Send messages without approval
  • \n
  • Make purchases
  • \n
\n

This is the secure alternative to OpenClaw's full-access approach.

\n\n
\n\n

Get Started Today

\n\n

Building AI agents doesn't require buying a Mac Mini or risking your system security.

\n\nFor a complete, integrated solution: Serenities AI provides all the building blocks—Vibe for development, Flow for automation, Base for data, Drive for storage, and MCP for connections—in one platform. With BYOK support, you use your own AI subscriptions at a fraction of API costs.\n\n
    \n
  • Free tier - Perfect for experimentation
  • \n
  • Starter (4/month) - Build your first serious agent
  • \n
  • Builder (9/month) - Multiple agents, advanced tools
  • \n
  • Pro (9/month) - Full platform access
  • \n
\n

👉 Start building at serenitiesai.com

\n\n
\n\n

Conclusion

\n\n

OpenClaw proved there's massive demand for AI agents that actually do things. But you don't need to accept its security tradeoffs or cost structure.

\n\n

By building purpose-specific agents with appropriate sandboxing, you get:

\n
    \n
  • Better security - Agents can only do what you allow
  • \n
  • Lower costs - Subscription-based access, smart model selection
  • \n
  • More control - Every capability is intentional
  • \n
\n

The future of AI isn't handing over your computer to a lobster. It's building focused tools that enhance your workflow—safely.

\n\n
\n\nHave questions about building AI agents? Drop them in the comments or reach out on Twitter @SerenitiesAI.
Share this article

Related Articles

Ready to automate your workflows?

Start building AI-powered automations with Serenities AI today.