Get Started
Before You Begin
You need a terminal, Node.js, and an API key for your chosen AI model provider. Add optional services (Docker, Telegram, search) only when you need them.
How Sun2Agent works
Sun2Agent operates as a lightweight, 100% local ReAct (Reasoning + Acting) agent harness directly inside your terminal. It connects your local workspace context and tools to any OpenAI-compatible LLM endpoint using standard Chat Completions function calling. The agent evaluates goals, requests tools, runs them on your machine with 5-layer guardrails and Human-in-the-Loop approval, and feeds results back until your task is finished.
Prerequisites
- Node.js 20 or 22+ and npm. Verify with
node --version. - A model API key: built-in NVIDIA NIM, or an API key and base URL for any OpenAI-compatible provider (OpenAI, Groq, OpenRouter, local Ollama).
- Internet access for installing packages and communicating with your model provider endpoint.
/browser, Docker daemon for container sandboxing, and a Telegram bot for mobile chat and scheduled reminders. Host desktop control with /computer requires an interactive display session.Get Started
Install & Setup Sun2Agent
Sun2Agent runs natively on macOS, Linux, and Windows. Choose the installation method that fits your workflow.
How workspace execution works
Sun2Agent binds its filesystem tools and execution context strictly to the folder from which you launch it. That directory becomes your active workspace root: file reads, edits, and tests are restricted inside it, preventing unintended modifications to other parts of your computer.
1. Install globally (recommended for everyday use)
Install Sun2Agent globally so the sun2agent command is instantly available in any terminal window or project folder:
npm install -g sun2agent
cd /path/to/your/project
sun2agentTo update an existing global installation to the latest version at any time, run npm install -g sun2agent@latest.
2. Or try immediately with npx (zero installation)
If you prefer to try Sun2Agent immediately without installing anything globally on your machine, launch it in any project folder using npx:
cd /path/to/your/project
npx sun2agent3. Developer install guide (run from source & contribute)
For contributors, hackers, or developers who want to modify the source code, run tests, or build custom integrations:
git clone https://github.com/snowhypers/Sun2Agent.git
cd Sun2Agent
npm install
npm test
npm startTo link your local development build globally across your system so typing sun2agent executes your cloned repository code, run npm link inside the cloned directory.
cd into your project repository before starting Sun2Agent so file modifications, searches, and test runners target the correct codebase.Get Started
First Run & Configuration
On your first launch, Sun2Agent guides you through an interactive setup menu to connect your model and preferences.
How configuration works
All configuration is stored locally in ~/.sun2agent/config.json with owner-only file permissions (0600). Credentials are kept on your machine and never synced to external servers or telemetry services. You can re-open configuration at any time by typing /config.
How to configure
- Provider and model: Select built-in NVIDIA NIM or add a custom OpenAI-compatible provider (e.g., OpenAI, Groq, OpenRouter, or local Ollama).
- API key: Paste your provider API key into the secure, hidden input. When updating later, press Enter to keep your saved key.
- Model ID: Pick a listed model or type the exact model identifier supported by your endpoint (e.g.,
meta/llama-3.3-70b-instruct,gpt-4o,llama3.2). - Optional services: Separately toggle Tavily web search, persistent memory, LangSmith tracing, or Telegram integration.
- Done: Select Done to save changes and enter the interactive terminal agent loop.
› Explain this project's structure and suggest the first test to run.Core Features
Workspace Files
File tools are available automatically. There is no setup command needed: launch Sun2Agent from your project folder and describe your goal in natural language.
“Read src/auth/service.js, add a unit test for password hashing, and verify that the test suite passes.”
How workspace tools work
- Autonomous file management: The agent automatically calls
read_file,write_file,replace_file_content, andlist_dirto inspect code and apply targeted edits. - Path sandboxing & security: File access is strictly locked to your workspace root directory.
filesystemGuardblocks directory traversal attacks and prevents reading sensitive files like.envor SSH private keys. - Human-in-the-Loop policy: Read-only operations run automatically. File creations and edits request approval for routine modifications per prompt; destructive deletions always require explicit fresh confirmation.
How Maven test verification works
For Java codebases, Sun2Agent provides an automated test-verification cycle:
- Authoring tests: Ask the agent to generate JUnit or TestNG tests under
src/test/java. - Fresh approval execution: The agent requests human approval to execute
mvn testwithin your workspace. - Autonomous diagnosis: If assertions fail or compilation errors arise, the agent inspects the failure stack trace, applies code fixes, and asks for approval to re-test.
- Verification report: Unverified work or failing assertions are clearly reported until the build passes cleanly.
Project conventions with AGENT.md
Store project conventions, lint rules, and architectural guidelines in an AGENT.md file at your workspace root. Type /agent in chat to view or create it.
Core Features
AGENT.md Instructions
AGENT.md provides repository-specific guidelines, architectural rules, coding conventions, and test requirements that Sun2Agent automatically follows whenever operating in your codebase.
Type /agent in chat to open or create ./AGENT.md directly in your terminal text editor.
How AGENT.md works
- Workspace scoping: Sun2Agent automatically searches for
AGENT.mdin the directory from which you launch it. Each repository maintains its own isolated rules. - System prompt injection: Instructions from
AGENT.mdare injected into the model's system prompt underRepository Instructions (from AGENT.md)on every turn. - Cached with instant reload: Rules are cached in memory for zero-latency execution. Running
/agentreloads the file from disk immediately so edits take effect on the very next turn. - Safety priority: Instructions in
AGENT.mdare advisory; they enforce team conventions and style guides, but cannot bypass 5-layer guardrails, override approvals, or breach Docker boundaries.
Example AGENT.md template
# Project Guidelines
## Tech Stack & Standards
- Node.js 22, ESM modules, strict TypeScript
- Formatting: 2 spaces, single quotes, no semicolons
## Testing & Verification
- Run tests via `npm test` after modifying any file in src/
- Always verify all assertions pass before reporting completion
## Workflows & Git
- Do not commit directly to `main`
- Keep changes minimal and focused strictly on the requested taskHow to use AGENT.md
- Type
/agentin the Sun2Agent prompt to open./AGENT.mdin your editor. - Add or modify conventions, style guidelines, and build commands.
- Save and close the file, then press Enter in the terminal. Sun2Agent confirms:
✔ AGENT.md reloaded. Its instructions are now active.
Core Features
Sessions & Memory
Manage active conversation context, restore interrupted workflows, and save persistent preferences locally.
How session and memory management works
Conversation snapshots
/new clears the active chat. /continue resumes an interrupted task from the automatic local session snapshot.
Task summaries
/save drafts a concise task summary; nothing is stored until you approve it in ~/.sun2agent/saved-sessions.json.
Persistent memory
Enable memory in /config. Preferences live in ~/.sun2agent/memory.md and are matched against user prompt keywords with zero cloud sync.
Project conventions
AGENT.md holds repository instructions. The agent follows conventions and rules automatically on every turn.
How the /save command works
While Sun2Agent automatically checkpoints raw session state to allow /continue resumption, the /save command lets you summarize and persist intentional workspace memories.
- Automatic multi-turn summary: Analyzes recent conversation turns and drafts a structured summary detailing your goal, key technical decisions, and modified files.
- Zero secret leakage: Summaries pass through
guardrails.sanitizeOutputto guarantee no API keys, tokens, or private credentials are saved. - Workspace scoping: Memories are stored in
~/.sun2agent/saved-sessions.jsonkeyed specifically to your project's directory path. - Human confirmation: Displays the draft summary and requires confirmation (
Save this session memory?) before writing to disk.
Which conversations you should save to memory
Not every trivial prompt needs to be saved. Use /save for high-value conversations that will help the agent understand the project in future sessions:
- 1. Complex debugging breakthroughs: When you spend multiple turns diagnosing an obscure bug, race condition, or subtle dependency conflict, run
/saveso the agent remembers the root cause and why specific fixes were made. - 2. Architectural & schema milestones: After completing a major feature slice—such as designing a new database schema, establishing an API contract, or refactoring an authentication flow—run
/saveso the agent retains the design rationale. - 3. Project convention decisions: When you and the agent agree on specific coding conventions, tool preferences, or library choices that are not yet codified in
AGENT.md, run/saveto persist that context. - 4. End-of-session checkpoints: Before exiting the terminal at the end of a work session, run
/saveto record current task progress so the next session can resume with full context.
How to use sessions & memory
- Resume an interrupted turn: Type
/continueto pick up directly from the last snapshot without re-prompting. - Start fresh: Type
/newto wipe chat history and reset token retention. - Edit your developer preferences: Type
/memoryto open and edit~/.sun2agent/memory.md(e.g. "prefer functional style", "use pytest"). - Save session highlights: Type
/saveto review and approve an exportable task summary.
Core Features
Skills (skills.md)
Skills are reusable instruction blocks—such as code review checklists, test templates, and framework guidelines—that you can attach to any conversation on demand.
› [Skill: Code Review] [Skill: Jest Testing] Review the PR diff and add unit tests.
How Skills work
- Central definition: Saved in
~/.sun2agent/skills.md. Each skill is formatted with a markdown heading and actionable instructions. - Dynamic prompt injection: When a skill is selected, Sun2Agent injects its guidelines into the model's system prompt for that turn, ensuring adherence to your checklist.
- Visual indicator: Active skills display in brackets directly above the prompt input (e.g.
[Skill: Code Review]). - Quick dismiss: Pressing
Escon an empty input line instantly clears all active skills for the current prompt.
How to use Skills
- Type
/skillsto view and toggle available skills or editskills.md. - Select one or more skills from your list to activate them for your next task.
- Type your request naturally—the model automatically follows the active skill instructions.
- Press
Escon an empty input box anytime to clear active skills.
Core Features
Self-Improvement
When an action encounters an error, a Java test fails, or a desktop outcome is left unverified, Sun2Agent analyzes what went wrong and proposes an advisory operational lesson.
“After editing Java tests, run Maven tests and report the result before claiming success.”
How self-improvement works
- Failure detection: Identifies tool errors, failed test assertions, or unverified desktop outcomes after a turn.
- User consent required: Prompts you with Discard as the default choice. Nothing is saved without explicit approval.
- Strict local storage: Approved lessons are saved in
~/.sun2agent/lessons.jsonwith 0600 file permissions and zero external telemetry. - Safety & secret screening: Every lesson passes through
inputGuard,outputGuard, and secret redaction to ensure no credentials or prompt injections are stored. - Keyword-relevant retrieval: Future tasks with matching keywords load up to one relevant lesson into the context prompt to prevent recurring mistakes.
Session Memory (/save) vs. Self-Improvement (lessons.json)
Sun2Agent uses two complementary local learning mechanisms that serve distinct purposes:
- Session Memory (
/save) captures what went right: Preserves features built, architectural choices, and project milestones keyed to the current workspace. - Self-Improvement (
lessons.json) captures what went wrong: Triggers after failed tool executions, broken builds, or unverified desktop actions, proposing defensive operational habits so the agent never repeats past mistakes.
Both systems are 100% local, require explicit user approval (defaulting to Discard / No), and include secret redaction.
How to use it
When a lesson is suggested after a failed action, choose Keep to save it or Discard to skip. Approved lessons apply automatically to future relevant prompts.
Tools & Integrations
Web Search
Live web search gives the agent access to real-time facts, documentation, and release notes without manual browsing.
“Find the latest Node.js LTS release from official release notes. Include its date and source URL.”
How web search works
- Tavily search API: Queries the live web for authoritative developer documentation and facts when tool calling is needed.
- Indirect prompt injection defense: Web result snippets are wrapped inside strict
<<<UNTRUSTED_WEB_DATA>>>boundary delimiters. - Input guardrail screening: Every search snippet passes through
guardrails.inputGuardbefore entering the model context, blocking hidden instructions or jailbreak attempts. - Zero authority over workspace: Untrusted web content cannot override your project instructions (
AGENT.md), bypass guardrails, or approve actions.
How to use it
- In Sun2Agent, type
/configand select Web Search. - Enable Tavily and paste your API key. Select Done.
- Ask current-events or documentation questions naturally in your chat.
Tools & Integrations
Browser Automation
Automate isolated web navigation, documentation scraping, and web application testing using Playwright.
/browser
› Open nodejs.org and show me the latest release notes.How browser automation works
- Isolated Chrome profile: Spawns a dedicated Playwright Chromium browser session on demand. Disconnected by default to save resources.
- Profile separation: Runs independently of your personal browser data and cookies; you stay protected from credential exposure.
- Human-in-the-Loop protection: Navigating and viewing pages proceed automatically; clicking, typing, submitting forms, and key presses request confirmation.
How to use it
- Type
/browserin the prompt to launch and connect the isolated browser. - Give instructions in plain English (e.g. “Navigate to example.com and extract header links”).
- Press
Escon an empty input or type/browser disconnectto close the browser session.
/browser controls an isolated web browser window. It cannot interact with your other desktop apps or host files.Tools & Integrations
Computer Control
Control your native desktop environment—inspect application windows, click UI elements, send keystrokes, and automate desktop workflows.
How computer control works
- Native OS automation: Dispatches mouse and keyboard events and inspects active windows using host accessibility APIs on macOS, Linux, and Windows.
- Fine-grained approval: Inspecting window titles and application state is read-only. Activating an app shares one approval per prompt; clicks, typing, and system scripts require explicit individual approval.
- Host isolation guard: Computer control operates on your host desktop and is intentionally disabled inside Docker sandbox containers to prevent host-escape vectors.
How to use it
- Type
/computerand confirm desktop access. - Choose image support if your configured model supports vision/multimodal input.
- Review the permission report. On macOS, grant Accessibility and Screen Recording permissions in System Settings if prompted.
- Prompt the agent with a focused desktop task, for example: “Open VS Code and bring the project window to the front.”
- Press
Escor type/computer disconnectanytime to release desktop control.
Tools & Integrations
MCP Servers
Extend Sun2Agent with any tool ecosystem using the Model Context Protocol (MCP)—from databases to developer tools.
How MCP integration works
- Multi-transport support: Natively connects to local processes via
stdio, remote servers overhttp(Streamable HTTP), andsse(Server-Sent Events). - Dynamic schema discovery: Automatically discovers tool schemas and arguments, exposing them as function calls to your active LLM.
- Security boundaries: Dangerous commands or unknown tools always trigger Human-in-the-Loop confirmations before execution.
How to use it
Use /mcp in chat to manage servers interactively, or configure them directly in ~/.sun2agent/mcp.json:
{
"mcpServers": {
"research": {
"type": "http",
"url": "https://your-server.example.com/mcp",
"telegramTools": ["search"]
}
}
}The optional telegramTools property allowlists specific remote read-only tools for Telegram. Local MCP servers, browser automation, and computer control tools are never exposed over Telegram.
Tools & Integrations
Telegram
Connect your running Sun2Agent terminal to a private Telegram bot to query projects, execute research, and receive updates on mobile or desktop.
How Telegram integration works
- Direct long-polling: Sun2Agent connects directly to the Telegram Bot API from your machine. No webhooks or public ports needed.
- Strict user authorization: Every incoming message is checked against your configured numeric Telegram user ID. Unrecognized messages are silently ignored.
- Live streaming replies: Message text updates dynamically as the LLM generates tokens.
- Host security restrictions: Local filesystem tools, browser automation, and host desktop control are restricted from Telegram execution for safety.
How to use it
- In Telegram, open @BotFather, send
/newbot, choose a name and username, and copy your bot token. - Open your newly created bot and send
/start. - Find your numeric Telegram user ID (inspect your bot’s
getUpdatesresponse or use an ID bot). - In Sun2Agent, run
/config→ Telegram, answer Yes to Connect Telegram?, and paste your bot token and chat ID. Select Done. - Keep Sun2Agent running in your terminal and message your bot anytime.
/start help/new fresh chat/stop abort current replyAutomation
Scheduled Tasks
Automate recurring background research, system checks, and reminders delivered directly to your Telegram chat.
› Every day at 9 PM, summarize today's AI news and send it to Telegram.› Remind me in 30 minutes to run the production test suite.How scheduled tasks work
- Natural language schedule parsing: Automatically detects intent, interval (daily, recurring, or one-time), and execution time aligned with your local machine's timezone.
- Unattended background execution: Runs read-only queries in the background and delivers results directly to your authorized Telegram chat.
- CLI dependency: Scheduled tasks require the Sun2Agent terminal process to remain running on your machine.
How to use it
Specify three details in your prompt: what to do, when, and once or daily. Type /schedule anytime in chat to inspect, pause, or remove scheduled jobs.
Security & Sandboxing
Approvals & Guardrails
Every tool call passes through five synchronized security guard layers before execution—sub-millisecond regex validation with zero extra LLM overhead.
How the 5-layer guardrails work
| Guard Layer | What it blocks & protects |
|---|---|
inputGuard | Prompt injection attacks, jailbreaks, and system-prompt extraction attempts. |
commandGuard | Destructive commands (rm -rf, sudo, mkfs, fork bombs, curl | sh, git push --force). |
networkGuard | Data exfiltration vectors (e.g. cat .env | curl, uploads via scp, nc, curl -d). |
filesystemGuard | Access to sensitive files (.env, .ssh, .aws, id_rsa, *.pem) and path traversal outside the project root. |
outputGuard | Masks API keys, AWS/GitHub/Slack tokens, JWTs, and private keys before tool outputs appear in chat or LLM context. |
How Human-in-the-Loop approvals work
- Read-only checks: Listing files, reading code, and inspecting windows proceed immediately without prompting.
- Routine modifications: File edits and writes share a single approval decision for that MCP server and prompt.
- High-risk actions: Deletions, shell commands, and external messages always require a fresh, explicit decision.
How to use approvals
When an action requires confirmation, Sun2Agent displays the server name, tool, arguments, and risk level. Type y to approve or n to decline.
Security & Sandboxing
Docker Sandbox
Run the entire agent runtime inside an isolated Docker container to protect your host system during untrusted code execution.
sun2agent sandbox enable
sun2agent sandbox status
sun2agent sandbox disableHow the Docker sandbox works
- Containerized runtime: Mounts your project directory into an isolated container. The agent cannot modify files outside the mounted project.
- Automatic session resume: If Docker restarts mid-session, Sun2Agent pauses and resumes automatically without loss of context.
- Desktop isolation: Host desktop control (
/computer) is intentionally disabled inside Docker to maintain strict isolation boundaries.
How to use it
Ensure Docker Desktop or daemon is running, then run sun2agent sandbox enable before starting your session.
Monitoring & Troubleshooting
Observability & LangSmith
Track LLM calls, tool execution times, latency, token consumption, and errors with production-grade observability via LangSmith—with privacy guardrails baked in.
All prompts, messages, tool arguments, and results are screened through outputGuard before leaving your machine. API keys, tokens, and secrets are automatically redacted.
How LangSmith observability works
- Zero telemetry by default: Sun2Agent sends zero data to external monitoring servers unless you explicitly opt in via
/config. - Dual-layer tracing: Creates nested runs for both model API calls (
traceLLM) and MCP tool executions (traceTool) using the officialRunTreeSDK. - Automatic secret redaction: Prompts, completions, tool inputs, and tool outputs pass through
outputGuardbefore dispatch to LangSmith. Bearer tokens, private keys, and API secrets are masked. - Screenshots omitted: Binary screenshots from
/browseror/computerare replaced with[Screenshot omitted from trace]placeholders to prevent data leakage. - Non-blocking fire-and-forget: Tracing runs asynchronously in the background. Network lag or LangSmith service outages never freeze the terminal or interrupt your workflow.
How to configure and use LangSmith
- Sign up at smith.langchain.com and generate a LangSmith API key.
- In Sun2Agent, type
/configand select LangSmith observability. - Choose Yes to enable tracing, then paste your LangSmith API key into the secure prompt.
- (Optional) Specify a custom project name (defaults to
sun2agent). - Select Done. All subsequent LLM queries and tool executions in that session will stream traces to your LangSmith project dashboard.
/config → LangSmith observability and select No. Stored keys are preserved but tracing is immediately deactivated.Monitoring & Troubleshooting
Troubleshooting FAQ
The agent answers but does not call tools
Check that your selected model supports OpenAI-compatible tool/function calling. Confirm the relevant integration is connected (/browser, /computer, or /mcp). Try a precise prompt that explicitly names the desired action.
The model returns HTTP 429
The provider is rate-limiting your requests. Wait for its cooldown period, reduce repeated prompts or tool loops, or switch models in /config. Sun2Agent retries transient model errors once; it does not override provider Retry-After headers.
Telegram reports a getUpdates conflict
Two running processes are polling the same bot token simultaneously. Stop the other Sun2Agent instance or kill lingering processes, then restart one copy.
Browser or computer cannot connect
For /browser, verify Chrome is installed. For /computer, check system permissions (macOS Accessibility and Screen Recording) and note that desktop control is not supported inside Docker containers.
Scheduled message did not arrive
Keep the Sun2Agent terminal process open, verify Telegram is connected, inspect saved jobs with /schedule, and check the displayed machine timezone. A job cannot trigger if the CLI is closed.
Maven test verification reports unverified work
If Java test assertions fail or mvn test errors out, Sun2Agent reports the work as unverified. Check the failure stack trace in chat, approve fixes, and let the agent re-run tests until all pass.
CLI Reference
Command Reference
Quick lookup table for all built-in slash commands and keyboard shortcuts.
| Command | What it does |
|---|---|
/config | Choose provider and model; configure optional services (search, memory, Telegram) |
/mcp | Manage, connect, or disconnect Model Context Protocol servers |
/browser | Connect isolated Playwright browser automation tools |
/computer | Connect real desktop control (mouse, keyboard, window inspection) |
/computer disconnect | Disconnect desktop control |
/agent | Open or create the workspace's AGENT.md conventions file |
/skills | Edit and select reusable Skills from skills.md |
/memory | Open local preference memory in ~/.sun2agent/memory.md |
/new | Start a fresh conversation and reset chat tokens |
/continue | Resume an interrupted task from the latest session snapshot |
/save | Review and optionally save a task summary to disk |
/schedule | List, inspect, or delete scheduled Telegram jobs |
/help | Display built-in CLI help and tips |
/exit | Quit Sun2Agent safely |
Keybindings & Shortcuts
| Key | Action |
|---|---|
Ctrl+C | Abort active model generation or pending search turn |
Esc *(during turn)* | Stop the current tool or model turn |
Esc *(empty box)* | Disconnect active MCP/browser or clear selected Skills |