自托管 AI 软件工厂
Building an (almost) fully self-hosted, sandboxed, agentic software factory

原始链接: https://blog.jakesaunders.dev/building-an-almost-fully-self-hosted-sandboxed-agentic-software-factory/

作者成功构建了一个全自动化的“软件工厂”,利用大语言模型(Hermes)管理从编码、测试到持续集成/持续部署(CI/CD)及发布的全生命周期,无需人工干预。 为了解决大模型拥有根权限带来的安全顾虑,作者利用一台专门的备用家用服务器搭建了一个“牺牲型”远程环境。该环境与主网络隔离,并通过 Tailscale 进行安全访问,使用 Coolify 进行平台即服务(PaaS)式的编排。通过利用 DNS-01 ACME 质询,系统能为私有子域名生成有效的 SSL 证书,且无需暴露任何公共 A 记录,确保服务仅能在私有 Tailnet 网络内访问。 技术栈包括: * **Forgejo**:自托管 Git 和 CI。 * **Hermes**:带有 WebUI 和 Telegram 集成的智能代理助手。 * **Firecrawl**:用于网页抓取。 * **Coolify**:用于编排基于 Docker 的部署。 该实验证明了其高效性;只需一个提示词,即可触发一个全栈 SvelteKit 应用的创建,包括数据库配置和自动部署。尽管作者承认智能代理的自主性存在固有风险,但目前的方案通过物理隔离“沙箱”并使基础设施易于重建,成功平衡了便利性与安全性。

这篇 Hacker News 的讨论聚焦于构建“自托管 AI 软件工厂”的实用性。虽然原帖作者提出了一种设置方案,但评论者迅速就“自托管”的定义展开了辩论,并指出真正的本地运行往往缺乏像 Claude 这类前沿模型的强大能力。 用户分享了他们使用本地硬件(如搭载 Ollama 的 RTX 3090 Ti)的经验。大家的共识是,虽然本地模型(如 Qwen 或 Hermes)对于特定的底层任务或节省成本很有用,但它们通常缺乏处理复杂代理工作流所需的智能和速度。一位用户强调了一种混合方案:由“前沿”模型担任协调者,将常规任务委派给本地模型。 讨论帖还谈到了使用流行基础设施工具(如 Tailscale)对项目进行过度工程化的趋势,即便这些工具并非必要。这反映出一种普遍观点:许多现代科技项目是基于流行词而非技术必要性堆砌而成的。总体而言,社区对完全自托管的高级编码解决方案持怀疑态度,更倾向于结合本地硬件和大型供应商 API 的分层模型。
相关文章

原文

tl;dr: It worked! From one prompt it created a repo, wrote the application and tests, got CI green, provisioned Postgres and deployed the finished app behind HTTPS without another message from me.If you just wanna see the outcome you can find a demo video at the bottom

LLMs got fun again! Maybe they always were and I was just stuck in the trough of disillusionment. Lately, whenever I need a little tool, I just build it.

I was in the gym the other day and wanted a weights tracker. The app I had in mind was about as CRUD-y as it gets, but all the app store versions wanted £12 per month, so I just one-shotted one with Claude. Great fun, but giving an LLM root access to my machine in auto mode still doesn’t sit right with me.

So, the challenge: how can I create a fully remote agentic development environment where we structurally contain the LLM rather than just trusting it? I want to give it an instruction and have it autonomously move through the whole SDLC:

  • Researching the right stack and packages to use.
  • Planning and writing the code and tests.
  • Committing to Git, building and running a CI pipeline.
  • Deploying the work to a ‘production’ server with databases, o11y, and a domain with SSL.

All on my home server, without another cloud infrastructure bill. The only ongoing cost specific to this experiment is a £20 Codex sub.

The Server(s)

The servers

Here they are in all their glory.

The one at the bottom is a 2014 dual-core i3 I’ve been running as a homelab for five years. It’s valiantly hosting this blog and about 45 other Docker containers, from Pi-hole to a full Prometheus / Loki / Grafana stack. It also has port 443 forwarded from my router. I’d be miffed if an LLM broke it, so that’s not what we’re using today.

The top one is a 2021 10th-gen i7 with 32GB RAM, bought fresh from eBay with nothing on it. Perfect.

The Stack

The core development stack is self-hosted through Coolify. Inference and integrations like Tailscale, Telegram, DNS and ACME still leave the box. You could host inference too, but I don’t have the hardware and I’d rather OpenAI subsidise my experiments.

ComponentNotes
Pi-holeLocal DNS rules, with the side benefit of seeing less shitty advertising.
TailscaleMakes my home network follow me around.
CoolifyA self-hosted, Heroku-style PaaS built on Docker.
Forgejo (with runners)Self-hosted Git and CI.
Hermes (with WebUI)An OpenClaw-style virtual assistant, using Codex for inference.
TelegramTalk to the agent from the toilet or wherever.
Firecrawl (self-hosted)A scraping / translation layer between the agent and the web.
Porkbun (Registrar) & Let’s EncryptA domain and on-the-fly SSL certificates.
Whatever elsePostgres, Redis, whatever your apps need. It’s just Docker under the hood, innit?

Sources

This isn’t a full how-to guide. I could probably write an Ansible one-shot script to set it all up; leave an issue on the GitHub repo below if you’d like one. If you’ve read this far, though, you can probably figure it out.

Networking

The first guardrail is obvious: it’s on its own metal. Hermes could rm -rf / and at worst it would cost me a couple of hours rebuilding it.

The next layer of bombproofing is the network. My older server has port 443 forwarded from the router; this one doesn’t. There’s no external ingress, cutting out a huge attack surface and all the internet background radiation from people speculatively probing /wp-admin on every DNS A record I set up.

But, if there’s no ingress, how do I:

  • Get access to all our cool new apps on my phone?
  • Generate an SSL cert at a vanity URL so I can access https://cool-new-app.internal.jakeshomelab.me?

I have Tailscale set up with my older server as an exit node. When I’m away from home, selecting it routes my traffic through that server and Pi-hole, which I’m using for custom DNS. Pi-hole lets you add dnsmasq rules like this:

address=/internal.jakeshomelab.me/192.168.1.201

Anything requesting *.internal.jakeshomelab.me now resolves to my new server, where Coolify’s reverse proxy picks it up and serves my shiny new services.

SSL Certs

With Caddy or Traefik and Docker labels, you can serve port 3000 on container X from https://my-service.internal.jakeshomelab.me. Point an A record at the server and it’ll contact Let’s Encrypt, complete an ACME challenge and get an SSL cert. I learned this three years ago and it still seems like magic.

The problem is the A record. I don’t want to publicly associate my-service.internal.jakeshomelab.me with my IP, whether people can access it or not. I want an SSL cert for a ghost service.

To solve this problem, I turned to DNS-01. I’ll be honest this is new to me, but here’s how it works:

  • Buy a domain (in this case from Porkbun).
  • Generate Porkbun API keys and add them to Coolify’s environment with write access to the domain.
  • Modify Coolify’s Docker Compose file to use lego and the Porkbun API:
      - '--certificatesresolvers.letsencrypt.acme.dnschallenge=true'
      - '--certificatesresolvers.letsencrypt.acme.dnschallenge.provider=porkbun'
      - '--log.level=INFO'

Then, when I register a new URL, Traefik / Coolify:

  • Uses the Porkbun API to create a new TXT record at _acme-challenge.my-service.internal.jakeshomelab.me.
  • Let’s Encrypt validates the challenge and issues a valid SSL cert.
  • Traefik deletes it.

That’s it! You now have a valid HTTPS URL, reachable within your tailnet, with no public A or AAAA record pointing to the service. The hostname may still appear in public certificate-transparency logs, but the service is only reachable from the tailnet.

The best bit is that Coolify does this on the fly. Our agent can create a service at any subdomain and it’ll ✨magically✨ sort itself out.

So, glue all this together and you get the following:

Networking diagram (A bit AI slop sorry!)

The same setup covers the tooling, so Coolify, Hermes, Forgejo and Firecrawl all live on their own local subdomains.

Development Stack & MCPs

Now we have an isolated(ish) box, let’s move on to the tooling. The tools are well known; gluing them together is the fun part.

Forgejo

We need somewhere durable to store code and run CI. I decided not to use GitHub because:

  • Giving the box my GitHub token rather undermines the isolation. Also, it’s not self-hosted.
  • Its API and CI minute limits won’t work at the scale of our new software factory.
  • It’s down most of the time these days anyway.

Forgejo is a great self-hosted alternative. The Docker Compose file linked above sets up Forgejo and its runners; registering yourself and the runner takes a little extra work, but it’s well documented.

I’ve also included a Compose file for syncing projects back to GitHub. That puts your GH token in the environment, but the trade-off is yours to make.

The Forgejo Hermes skill linked above gives the agent full control of the instance.

Hermes

Hermes is an OpenClaw-style personal assistant with agentic capabilities. I never got in on the OpenClaw hype, so I can’t compare the two, but Hermes has a few features I’ve found handy:

  • Web UI: A standard ChatGPT-esque interface for working from my laptop and managing skills.
  • Shared filesystem: I’ve mounted its workspace from the Docker host and shared it over Samba. The agent and I can use the same files instead of copy-pasting Markdown and code around.
  • Telegram integration: I can chat to the agent from my phone. Setup took two minutes and required no login details, which suited the sandbox approach.
  • Self-building skills: Hermes can create and register its own skills. I couldn’t find a good Coolify one, so it read the docs, looked at the MCP and built one.
  • Firecrawl: Self-hosted Firecrawl gives the agent much nicer access to SERP data and web scraping at scale.

Getting Hermes and Firecrawl set up with the right keys in the right places is a massive pain in the arse. I’ve added Coolify-friendly Docker Compose files to the repo linked above.

Hermes chugging through building a demo web app for this blog post.

Coolify

Coolify is the glue holding this together: a self-hosted PaaS built on Docker and Compose that comes on in leaps and bounds with every update. If you want Heroku or DigitalOcean App Platform niceties on your own hardware, I’d highly recommend it.

Some of my favourite features are:

  • It’s just Docker under the hood. Existing deployments mostly work, and if Coolify won’t do something weird you can docker exec <whatever> from your laptop. Things are only abstracted away if you want them to be.
  • The SSL / routing stack which I’ve gone into in depth above.
  • Coolify ships with a bunch of pre-made recipes for all the most common apps. Postgres, Redis, Hermes, Forgejo and almost anything else is available to deploy with a single click.
  • Postgres backups to S3 are a three-click job, and env vars and user management are built in.
  • GitHub webhooks give you automatic deploys on push to main.

Here are a couple of screenshots of my Coolify setup in action:

Tooling screen on Coolify

Firecrawl service and Docker Compose

What it actually did

The demo below shows this pretty well, but the starting gun was the following prompt:

Please build me an app for tracking my calorie intake. It should be similar to MyFitnessPal but with a form to
add specific food and meals for quick selection later.

Your task is to build it, commit it to a new repo with tests, test it with CI, and deploy it to
http://calories.internal.jakeshomelab.me.

I’d like it to be a full stack svelte kit app with Drizzle and Postgres for the database layer.
I’d like tailwind for the CSS. It should be mobile first.

For deployment, please use docker and docker compose and deploy your own Postgres instance.

From there, it just got on with it:

  • Created a new Git repo and bootstrapped SvelteKit, Drizzle, Postgres and Tailwind.
  • Wrote the app and its tests, committing the work in sensible stages.
  • Created a CI pipeline.
  • Worked through test failures until CI turned green.
  • Containerised the app and its own Postgres instance with Docker Compose.
  • Deployed the lot to Coolify at its own URL.

All without a single further prompt. No nudging it through failed tests or copying error messages back into the chat. It just kept going until the app was running.

At that point I gave it a whirl and hit a CSRF issue when submitting data. I sent one more prompt; it diagnosed the problem, fixed it, added regression tests and redeployed.

And it worked!

That’s the loop I wanted: prompt, repo, code, tests, CI, deployment, bug fix. It’s not a complicated app, obviously, but it went from a paragraph to tested, deployed software and handled all the boring bits in between. That still feels a bit like witchcraft.

Enough of all that, show me the goods!

I’m no YouTuber, but here you go:

Thoughts on isolation and next steps

There is always a trade-off between fully agentic development and security. This was a fairly contrived example: the app works completely in isolation. Most useful software talks to other software, which means handing over API keys, and every key adds another little hole in the sandbox.

Even in this setup, Hermes can still:

  • Nuke the new server and everything running on it.
  • Delete repos, databases and deployments.
  • Leak or abuse any credentials I’ve given it.
  • Burn through inference tokens like its end-of-year review depends on it.
  • Make rando outbound requests and download whatever rubbish the internet hands it.
  • Poke anything else on my network that the firewall allows it to reach.

So no, it isn’t harmless. What I’ve done is make the machine sacrificial and sharply limit how much stuff I care about is within reach. The failure mode is now “rebuild the eBay box and rotate a handful of keys”, rather than “discover an LLM has enthusiastically reorganised my actual laptop”. That’s better I think, but it isn’t magic.

The obvious next steps are:

  • Put the box on its own VLAN and explicitly block access to the rest of my home network.
  • Scope every credential as narrowly as the provider allows, and rotate them regularly.
  • Automate backups and make rebuilding the whole box a one-shot job.
    • Coolify’s DB backup and my shared Docker compose mounts should make this relatively easy.
  • Require approval before it does anything genuinely public or difficult to undo.

At some point, though, enough approval gates turn your magical autonomous software factory back into a collection of forms you have to fill in. Finding the useful point between “needs me every five minutes” and “has the launch codes” is the next experiment.

联系我们 contact @ memedata.com