- Welcome to my dev notes - Adam Strojek/
- Blog/
- Why Rust Is Becoming the Language AI Agents Write Code In/
Why Rust Is Becoming the Language AI Agents Write Code In

Table of Contents
Lately a simple idea has been spreading across the developer internet: Rust is an ideal language for AI agents to program in. I think the real reason has less to do with raw speed and more to do with trust. When an agent writes Rust, everything around it works in its favor. The type system, the borrow checker and the compiler act as a built-in reviewer that checks every step the agent takes.
That idea is exactly why I built AgentAI, a Rust library for creating AI agents that anyone can use. Today I am happy to announce AgentAI 0.4.0, and to point out that the library comes with a ready-made chat interface in a separate crate, egui-agent-chat.
A language that keeps agents honest #
Language models make mistakes. They invent functions that do not exist, mix up types, and sometimes take a shortcut just to make a result look correct. In dynamic languages many of those problems surface only at runtime, or never. Rust moves them to compile time:
- Strong static typing. A made-up function, a wrong argument or a mismatched type simply does not compile.
- Ownership and the borrow checker. Whole classes of memory errors and data races are rejected before the code ever runs.
- No null. The absence of a value has to be handled explicitly through
Option. - Explicit error handling. Failures come back as
Resultvalues that are hard to ignore quietly. - Visible danger. Anything the compiler cannot verify must sit inside an explicit
unsafeblock, which stands out in review.
For an agent, this changes the game. It cannot paper over a problem to force a result through, because the compiler refuses to build the lie, and it explains why. Daniel Szoke of Sentry made a similar case in a talk on AI-assisted coding: strictness makes the first attempt harder for a model, but the precise compiler errors give it a fast feedback loop to correct itself, instead of failures discovered at runtime. Another engineer puts it as the compiler raising the ceiling of what agents deliver.
The flagship example: OpenAI’s Codex CLI #
The clearest sign of the shift came in 2025, when OpenAI announced it was rewriting Codex CLI in Rust. The tool had started as TypeScript on Node.js, and the team named several reasons for the move (InfoQ has a good summary):
- No Node dependency. Installing and running a native binary is simpler than requiring a JavaScript runtime, which DevClass notes could be frustrating or a blocker for some users.
- Native sandboxing. The Rust version applies sandboxing with Apple’s
sandbox-execon macOS and Landlock on Linux. - Lower, more predictable resource use. With no garbage collector, memory usage is lower and performance more predictable.
- An extensible protocol. A “wire protocol” lets developers extend the agent from other languages such as JavaScript and Python.
- MCP in Rust. An existing Rust implementation of the Model Context Protocol lets Codex act as both an MCP client and an MCP server.
It was not a short-lived experiment. One architecture write-up from March 2026 describes the repository as roughly 95.7% Rust, with the npm package reduced to a thin wrapper that downloads the Rust binary, and a reusable codex-core crate that holds the agent loop. When one of the best-resourced AI labs picks Rust for the heart of its agent, other builders notice.
The whole industry is moving this way #
Codex is not an isolated case. The OSS Insight analysis of GitHub’s fastest-growing AI agent repositories found that in early 2026 the layers where agents actually execute things (command-line tools, runtimes and sandboxes) were consolidating around Rust, and it names memory safety for agents that run commands and touch files as one of the main reasons. Microsoft, as InfoQ notes, already requires Rust for new development that does not need garbage collection. The signal from big labs, big vendors and open source is consistent.
AgentAI 0.4.0: build agents in Rust, today #
This is where AgentAI comes in. It is a Rust library designed to make creating AI agents simple, and it is available to everyone. The main ideas, as described in the crate documentation:
- Connect to any major provider. OpenAI, Anthropic, Gemini, Ollama and other OpenAI-compatible APIs work through one interface.
- Use the right model for each job. Pick the model best suited to each step of your agent’s workflow.
- Build custom tools with ease. Define your own tools with the
ToolBoxand the#[toolbox]macro. - MCP server support. Reuse existing Model Context Protocol servers instead of writing every tool from scratch.
You get strong static typing and robust error handling from the first line, which is the same safety net this whole article is about. Version 0.4.0 is out now:
cargo add agentai
AgentAI is no longer an experiment. The library has matured, and I use it myself in my own products, so I have every reason to keep it reliable and to keep improving it.
egui-agent-chat: a ready-made start for your agent UI #
If you want to add agents to your own program, you usually have to build a chat interface first. With egui-agent-chat, a crate built on egui, that part is already done: you get a ready-made widget, connect it to your agent and have a working foundation from day one. Want to take it further? Extend it however your product needs.
Everything is released under the MIT license, so you can use and modify it in all your products without worry. And because it is Rust from the model call to the window on the screen, there is no web front end and no second toolchain to maintain.
Try it and tell me what you build #
Agents that write and run code deserve a language that checks their work. If you want to build them in Rust, AgentAI 0.4.0 and egui-agent-chat are ready for you: install them, put them through their paces, and open an issue or a pull request with what you find.
Sources #
- OpenAI rewrites AI coding tool in Rust, DevClass
- Another Rust Rewrite: OpenAI’s Codex CLI Goes Native, InfoQ
- The codex-rs Architecture, Daniel Vaughan
- The Rust Shift: How GitHub’s AI Agent Infrastructure Changed Languages, OSS Insight, April 2026
- Rust: The Ideal Language for Vibe-Coding?, StartupHub.ai
- Why High-Level Rust Wins for Agentic Engineering, hamy.xyz
- agentai crate documentation, docs.rs