Dev.to AI 🤖 Ai 👁 1 📖 3 min read

13-Hour Limit-Breaking Development: I Built an AI Agent with "Watchdog" and "Shadow Sandbox" on an Android Phone Using AI

When running an AI Agent on a mobile phone, the biggest fear is that a single wrong line of code can crash the system completely, with no way to recover it. That was the original motivation behind this project.   I. P

When running an AI Agent on a mobile phone, the biggest fear is that a single wrong line of code can crash the system completely, with no way to recover it.

That was the original motivation behind this project.

 

I. Project Introduction: Z-Agent-Termux

This is a self-evolving AI Agent that runs in the Termux environment on Android phones. Its core mission is singular: no matter how the code is modified, the system must never crash.

To achieve this "invincibility", I designed a dual-insurance architecture for it:

1. Watchdog (boot_guard): Automatically performs AST, symbol, and smoke self-tests before the program starts. If the startup succeeds, it automatically generates a "last_good" snapshot; if the startup fails, it automatically loads the most recent snapshot and performs an atomic rollback.
2. Shadow Sandbox (shadow_test): Before the code is actually replaced, it runs the full set of logic driven by a "mock LLM" in an isolated sandbox environment. Only when all assertions pass and there are no runtime invariant errors is the "gene write-to-disk" permitted.

In addition, I implemented physical isolation in its architecture (separating the zcore tool library from the zguard defense system), ensuring that the watchdog cannot be corrupted by the main program.

 

II. The 13-Hour Extreme "Creator" Journey

This project wasn't built step-by-step in a routine way. It was the result of 13 straight hours of work, from 9 a.m. to 10 p.m. today.

  • 9:00 – 12:00 AM: Pitfalls and Crashes At the beginning, I was tinkering with API interfaces and ran into 401 (invalid key), 503 (server overload), and even accidentally deleted critical source code in the nano editor. Through repeated crashes and recovery attempts, I realized: the mobile environment is far too fragile, and a "self-healing" mechanism is essential.
  • 12:00 – 4:00 PM: Refactoring and Integration With the intellectual support of an external large model (GLM-5.3), we began refactoring the source code. The original 2000+ line single-file monolith was split into zcore and zguard. During this process, the watchdog (boot_guard) and shadow sandbox (shadow_test) were introduced.
  • 4:00 – 6:00 PM: Security Cleanup and Documentation To prevent API key leaks, I audited and sanitized all log and configuration files. Then I wrote an extremely detailed Chinese deployment and user manual from scratch.
  • 6:00 – 8:00 PM: Promotion and Outreach I set up a QQ group for discussion, wrote promotional copy, posted updates on Bilibili, and simultaneously published open-source articles on Juejin and Zhihu.
  • 8:00 – 10:00 PM: Git Sync and Release This was the most challenging step. There were conflicts between the local code and the remote GitHub repository ( ! [rejected] ). After multiple rounds of back-and-forth with  git pull --allow-unrelated-histories  and  git push , I finally successfully pushed all the code, README, badges, quick-start tutorial, and  llms.txt  to GitHub.

 

III. Project Highlights and Known Limitations

  • Highlights: The system has a built-in self-healing loop. Even if you break the source code, it will automatically roll back to a bootable version on restart. This means you can experiment freely with Agents on your phone.
  • Known Limitations: It guards against "false completion" but not "low-quality completion"; the shadow sandbox currently only falsifies the first output; it cannot simulate a real network environment.

 

IV. How to Try It?

The project is fully open source on GitHub, with a complete set of Chinese documentation. Anyone interested is welcome to try it out, and feel free to open Issues for discussion.

👉 GitHub repository: https://github.com/zxxzxx1314/Z-agent-termux
💬 QQ discussion group: 1072611451

If you are also interested in on-device AI Agents, or are looking for a lightweight experimental framework with a security sandbox, feel free to give it a Star as encouragement. Open source is not easy, thank you for your support!

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.