商业产业 Hacker News Show HN AI 2026-09-16T13:23 正文 ok 497 words

Show HN:Legion——让 AI Agent 在 Elixir 应用内编写沙箱化 Lua 代码

英文标题:🔶 Show HN: Legion – AI agents that write sandboxed Lua inside your Elixir app

Legion 是一个开源 Elixir 运行时,用于将能够编写并执行代码的 AI Agent 嵌入应用程序。它允许 Agent 通过经审核的 Lua 或 Elixir 代码组合工具,而非仅进行一次性的工具调用,并可通过沙箱限制时间、内存和 CPU 使用。开发者可直接将普通模块声明为工具,并基于已登录用户的上下文对所有调用进行权限约束。Legion 还提供 Postgres 持久化、限流、Telemetry 事件和 LiveView 可观测性仪表盘,适用于聊天界面、Claude 或 Cursor 的 MCP 服务及后台任务等场景。
打开原文相关 3 · 机会 1
media1.5 KB media351 B media504 B media6.3 KB media6.6 KB media157.4 KB

中文

由 创建的开源 Elixir 库

这个页面里有一个 Agent。请给它一条指令。

Legion 是一个面向 AI Agent 的 Elixir 运行时,这些 Agent 可驻留在你的应用中,并通过编写代码完成任务。

目前尚未绘制任何内容。请让它向你展示其工作方式。

简单来说

将 AI Agent 集成到应用中的最简单方式。

一个真正能做事的 Agent

不同于只会对话的聊天机器人,Legion Agent 能够进入你的应用并执行操作:查找记录、运行报告、更改设置、创建工单。你可以决定它能够调用哪些函数。

聊天只是其中最小的一部分

同一个 Agent 可以位于聊天窗口之后,为 Claude 或 Cursor 提供 MCP 服务器能力,或作为后台 Worker 在夜间清理队列。一个运行时,多种形态。

生产环境必备能力开箱即用

每项操作都会在具有时间和内存限制的沙箱中运行;对话保存在你自己的数据库中;仪表盘可准确展示 Agent 做了什么以及原因。无需额外购买或运维任何组件。

F-01

TOOL CALLING LEGION 5 HOPS 1 PASS

用代码替代一次性工具调用

Agent 可以运行经过审核的 Lua(或 Elixir)代码,将你的工具组合起来,以近乎零配置完成过去无法完成的任务。

F-02

SANDBOX YOUR TOOLS TIMEOUT · MEMORY · CPU

默认采用沙箱机制

每次求值都会在受监控的进程中运行,并受到超时、内存和 CPU 预算的约束。Lua 完全无法访问宿主 BEAM;唯一能够离开沙箱的方式,是调用你注册的工具。

F-03

PostsTool use Legion.Tool AGENT ANY MODULE

工具就是普通模块

在任何模块中使用 use Legion.Tool,Agent 就能读取其源码并直接调用其中的函数。无需额外定义,也无需在应用变化时维护同步。

F-04

AUTH BOUNDARY AGENT TOOLS 42 USER CONTEXT

受限于已登录用户

在 Agent 启动前设置认证上下文,并在运行时于工具内部读取它。Agent 发起的每次调用都会限定在该用户的权限范围内,生成的代码也永远无法看到凭证。

F-05

Agent 就是 BEAM 进程

启动一个 Agent,让它持续运行,并像操作 GenServer 一样向它发送消息。监督树、连接池,以及委派任务给其他 Agent 的 Agent,都会按你预期的方式工作。

F-06

NODE A DEPLOY NODE B USER_42:CHAT_7

由你的 Postgres 提供支持

将 Legion 指向你的 Repo,即可为 Agent 获得持久化和限流能力。

F-07

TRACE · USER_42:CHAT_7 LIVE · LEGION_WEB AGENT MESSAGE ITERATION LLM SANDBOX

内置可观测性

在每个层级都提供 Telemetry 事件——Agent、消息、迭代、LLM 调用、沙箱求值;legion_web LiveView 仪表盘则展示实时对话,以及 Agent 编写的每一行代码。

我们是 Software Mansion

你或许通过 Elixir Stream Week、Global Elixir Meetups,或者 Popcorn 和 Membrane 等项目认识我们。但我们的工作不止于此。

我们帮助团队打造卓越的软件——从开发者工具到可用于生产环境的应用程序。让我们聊聊如何支持你的下一个项目。

English / 原文

Open source Elixir library created by

This page has an agent inside it. Give it an instruction.

Legion is an Elixir runtime for AI agents that live inside your application and get things done by writing code.

Nothing drawn yet. Ask it to show you how it works.

In plain words

The easiest way to put AI agents inside your app.

An agent that actually does things

Instead of a chatbot that only talks, a Legion agent reaches into your application and acts: finds records, runs reports, changes settings, files the ticket. You decide which functions it may touch.

Chat is the least of it

The same agent can sit behind a chat window, power an MCP server for Claude or Cursor, or run as a background worker that clears a queue overnight. One runtime, many shapes.

Production essentials come in the box

Every action runs in a sandbox with time and memory limits, conversations are saved in your own database, and a dashboard shows exactly what the agent did and why. Nothing extra to buy or operate.

F-01

TOOL CALLING LEGION 5 HOPS 1 PASS

Code instead of one-off tool calls

Agents can run vetted Lua (or Elixir) code that composes your tools to achieve things that were impossible before - with near zero configuration.

F-02

SANDBOX YOUR TOOLS TIMEOUT · MEMORY · CPU

Sandboxed by default

Every evaluation runs in a monitored process with timeout, memory, and CPU budgets. Lua can't reach the host BEAM at all - the only way out is the tools you registered.

F-03

PostsTool use Legion.Tool AGENT ANY MODULE

Tools are plain modules

use Legion.Tool on any module and the agent reads its source and calls its functions directly. Nothing to define, nothing to keep in sync as your app changes.

F-04

AUTH BOUNDARY AGENT TOOLS 42 USER CONTEXT

Scoped to the signed-in user

Set auth context before the agent starts and read it inside your tools at runtime. Every call the agent makes is scoped to that user, and the generated code never sees the credentials.

F-05

Agents are BEAM processes

Start one, keep it around, message it like a GenServer. Supervision trees, pools, and agents that delegate to other agents all work the way you expect.

F-06

NODE A DEPLOY NODE B USER_42:CHAT_7

Backed by your Postgres

Point Legion at your Repo and you'll have persistence and rate limiting for your agents.

F-07

TRACE · USER_42:CHAT_7 LIVE · LEGION_WEB AGENT MESSAGE ITERATION LLM SANDBOX

Observability is included

Telemetry events at every level - agent, message, iteration, LLM call, sandbox eval - and the legion_web LiveView dashboard shows live conversations and every line of code an agent writes.

We are Software Mansion

You might know us from Elixir Stream Week, Global Elixir Meetups, or from projects like Popcorn and Membrane. But that’s not all we do.

We help teams build exceptional software - from developer tools to production-ready applications. Let’s talk about how we can support your next project.