Engineering·6 min read

How @lyretoai Runs Code Safely in Group Chat With a Locked Linux Sandbox

How we designed @lyretoai so friends and dev teams can search the web, review GitHub diffs, and execute code snippets right inside a group chat without exposing the server or bypassing human approval.

Bringing an assistant into a shared group chat introduces a completely different set of engineering problems compared to a single-user chat window. In a group, multiple people ask questions at the same time, someone might paste a snippet of Python or TypeScript to test an idea, and a developer might want the assistant to inspect a GitHub repository and open a pull request. If the assistant can execute code or touch external services, one careless shortcut can turn a fun chat helper into a serious security hole.

When we upgraded @lyretoai to support live web search, GitHub pull requests, and real code execution, we built the entire system around two rules: every write action requires an explicit human approval card, and every line of executed code runs inside a locked, network-less Linux sandbox completely outside the chat server.

Web Search With Real Citations

When someone mentions @lyretoai with a question about current events, documentation, or a library update, it does not guess from stale training text. It runs live web queries, reads the returned snippets and pages through an SSRF-guarded fetcher (which blocks private networks and internal metadata addresses), and cites the exact result URLs it read. If a multi-step question hits its step budget, the assistant synthesizes an answer from what it actually observed rather than stalling out.

GitHub Without Blind Trust: Read Freely, Write Behind Approve Cards

Small teams use Lyreto group chats to coordinate code every day. With @lyretoai, anyone in a group can point to a public GitHub repository by owner/name or link—or connect a private repo in Group settings → Lyreto AI → Connections—and ask it to list files, search code with grep or glob patterns, read specific line ranges, inspect commit diffs, or summarize open issues and pull requests.

Reads happen right away because they cannot mutate anything. Writes follow a strict approval model:

  • Diff-previewed proposals: When asked to fix a bug or draft a change, @lyretoai prepares structured file edits (capped in file count and total changed lines per proposal) and posts an interactive Approve card in chat showing exactly which files change and the diff stats.
  • Branch and pull request only: Clicking Approve creates a fresh lyreto-ai/ branch (or fork when the token cannot push directly), commits the exact reviewed diff, and opens a pull request. The assistant never pushes straight to a default branch, never deletes repositories, and never changes repository visibility.
  • Owner and admin control: Group owners decide who can approve actions and can turn web access, code execution, or external connectors on or off per group at any time.

Inside the Locked Linux Sandbox

Letting chat members ask an assistant to run Python, Node.js, shell scripts, or TypeScript type-checks is hugely practical—you can verify math, parse JSON, test a regex, or check whether a function compiles without leaving the conversation. Running untrusted code on the same machine as a live chat server, however, demands defense in depth.

Rather than calling eval or spawning child processes inside the Lyreto web server, we moved code execution into a separate minimal daemon (lyreto-sbx) running under its own unprivileged OS user in an isolated system service. When @lyretoai invokes the sandbox, the chat server sends a single JSON request over a local Unix socket, and the daemon launches the snippet inside a bubblewrap (bwrap) Linux namespace jail with tightly constrained boundaries:

  • Zero network access: Every run executes with --unshare-all in its own network namespace with no outbound sockets. Code inside the jail cannot scan the local network, talk to internal services, or exfiltrate anything to the internet.
  • Read-only minimal filesystem: Only read-only system runtime binaries (such as Python and Node under /usr) are mounted inside the jail. The application directory, SQLite database, uploads, configuration files, and host secrets do not exist inside the namespace at all.
  • Clean environment and dropped capabilities: The jail starts with --clearenv and dropped Linux capabilities so no host environment variables, API tokens, or credentials ever leak into child processes.
  • Ephemeral tmpfs workspace: Each execution gets a fresh, size-limited in-memory /work and /tmp directory. The moment the process exits, the workspace is wiped completely.
  • Hard resource caps: Per-run Linux cgroups and rlimits enforce strict limits on memory, process/PID count (stopping fork bombs immediately), CPU time, open files, file size, output volume (automatically killing runs that flood stdout/stderr past 10 MB), and wall-clock runtime (default 12 seconds).

Rate Limits, Concurrency Caps, and Group Switches

Isolation protects data, while quotas protect responsiveness for everyone else on the platform. The sandbox daemon caps simultaneous executions, checks available host memory before admitting a new run, and enforces per-user and per-group rolling rate limits (such as 6 runs per user and 15 per group per five-minute window). If a group chat does not want code execution enabled at all, an admin can flip it off in group settings without disabling normal Q&A or search.

Per-Group Memory Without Cross-Leakage

Finally, @lyretoai keeps its memory strictly scoped to the group where a note was saved. Group admins can inspect, edit, or clear stored group notes whenever they want, and nothing learned in one group chat ever crosses into another server or DM. Combined with Approve cards and the bubblewrap jail, teams get real technical utility right in chat while keeping clear boundaries around their code and privacy.

Curious what else shipped in the latest @lyretoai release? Check the Lyreto changelog or see how teams pair @lyretoai with live game editors in our Studio Link and Game Bridge guide.

More from the Lyreto Blog

Ready to try Lyreto?

Free chat, voice, 100 MB uploads, and Lyreto Studio on the web, phones, and desktop.