Why the biggest AI companies are moving to Rust
OpenAI, Anthropic, Meta, Microsoft, NVIDIA and xAI all run Rust in the systems around their models. What it gives them over Python, why they didn't pick Java or C++, and where it still loses.
On 25 November Anthropic published how it moved the Messages API, the service every Claude request goes through, from Python to Rust. The new version uses about 70% less CPU per request and cut median time to first token by about 20%.1
In September OpenAI described doing the same with Habitat, the storage service behind ChatGPT. The Rust version is 6x more CPU efficient and 15x more memory efficient than the Python one.2 Five days later GitHub described moving the Copilot agent runtime from TypeScript to 832,378 lines of Rust.3
Every time a post like this goes up, the replies ask the same things. Why not just make the Python faster? Why not C++? Why not Java? So I read the engineering posts behind each move, the security data, and what well-known engineers have said for and against Rust. This is what I found, kept as simple as I could make it.
What actually moved
An AI product is a stack of software. At the top, researchers write models in Python. At the bottom, GPUs run kernels written in CUDA and C++. In between sits a lot of ordinary software that runs on CPUs: the API that takes your request, the tokenizer, the router that picks a GPU, the storage that holds your chats, the CLI on your laptop, and the sandbox that runs an agent's code.
That middle part is where Rust is landing.
The top and bottom rows haven't moved. PyTorch is built on ATen, a tensor library written in C++,4 and the main PyTorch repository has no Rust in it at all.5 So when people say AI is moving to Rust, they mean the software around the model. The model itself is still Python on top of C++ and CUDA.
A slow start, then a rush
Rust in AI isn't new. OpenAI's tokenizer library, tiktoken, has had a Rust core since it came out in December 2022.6 When xAI announced Grok in 2023, it said its training and inference stack was built on Kubernetes, Rust and JAX, and that Rust prevents most of the bugs you'd usually find in a distributed system.7
What changed is the pace. Most of the big moves happened in the last eighteen months.
What Rust gives over Python
Python is the right language for research. It's quick to write, and the whole ML ecosystem lives in it. The trouble starts when the same code has to serve millions of requests a second.
Python pays for every request in CPU
Python is interpreted, so the same work takes more CPU than it would in a compiled language. In a prototype that doesn't matter. At ChatGPT's scale it does. Habitat served more than 20 million requests a second on Python at its peak, and it was the second largest service at OpenAI by core count before the rewrite.2
Cloudflare gave the same reason for building its own inference engine, Infire, in Rust instead of running vLLM. Its engineers wrote that going through layers of Python libraries wasted CPU, purely because Python is interpreted, and that the Rust engine stopped taking resources away from Cloudflare's other services.8
Anthropic's post shows how that work adds up. By late 2025, every Messages API request had to be validated, turned into a prompt, tokenized and screened by safety classifiers. Every reply had to be sorted into text, thinking and tool calls as it streamed back.1 None of that runs on a GPU.
Faster GPUs made the CPU the bottleneck
This was the part I didn't expect. In April 2026 the vLLM team wrote that as GPUs get faster and more requests run at once, the CPU side of the system has become a bottleneck again. The usual spot is the frontend process, where Python's event loop can't keep up.9 They named garbage collection and the GIL as the root problems and started an experimental Rust frontend.
Other serving projects got there earlier. In 2024 SGLang replaced its Python router with a Rust one that was about 2x faster.10 NVIDIA describes Dynamo, its framework for serving models across a data center, as built in Rust for performance and Python for extensibility.11
Threads that actually run in parallel
Standard Python has a global interpreter lock, the GIL. Only one thread runs Python code at a time, so a 64-core server sits mostly idle unless you start many separate processes. That was vLLM's workaround, extra API server processes, and its RFC calls the pattern a source of significant complexity.9
Since Python 3.13 there's an optional free-threaded build without the GIL. Python's own docs warn that some packages with extension modules aren't ready for it yet and will turn the GIL back on.12 Rust threads run in parallel by default, and the compiler refuses code where two threads could change the same data at the same time.
Python stays on top
This is what makes Rust easy to adopt. Nobody has to give up Python. A binding library called PyO3 lets you write the slow part in Rust and ship it as a normal Python package. Users run pip install and never notice. When Charlie Marsh released Ruff, the Rust-based Python linter, it installed with a plain pip install ruff and was about 150x faster than Flake8.13
A lot of the Python AI stack already works this way:
- Pydantic, the validation library, rebuilt its core in Rust for V2. Its author measured it at 4x to 50x faster than V1 while building it,14 and V2 shipped in June 2023.15
- tiktoken, OpenAI's tokenizer, is 3x to 6x faster than a comparable open-source tokenizer.6
- Hugging Face tokenizers takes less than 20 seconds to tokenize a GB of text on a server CPU.16
- Pyrefly, Meta's Python type checker, is written in Rust.17 Google adopted it in October 2026 after finding it an order of magnitude faster than its old checker.18
- rustbpe is Andrej Karpathy's BPE tokenizer trainer, written in Rust with Python bindings. He wrote it because his earlier Python version wasn't built for speed.19
OpenAI went a step further and agreed in March 2026 to buy Astral, the company behind Ruff and the uv package manager.20 David Hewitt, who maintains PyO3, estimated at the 2025 Python Language Summit that between a quarter and a third of all native code uploaded to PyPI for new projects now uses Rust.21
Why not C++?
C++ is as fast as Rust. When WhatsApp replaced 160,000 lines of C++ with 90,000 lines of Rust (and the Rust count includes tests), the Rust version came out ahead on both performance and memory use.22 What C++ can't give you is memory safety.
Most serious security bugs are memory bugs
In C and C++ the programmer manages memory by hand. Free something too early and the program may later read memory that now holds something else. Forget to free it and memory leaks. Mistakes like these are easy to make and hard to catch in review, and attackers use them to take over programs.
Chromium found that around 70% of its serious security bugs are memory safety problems.23 Microsoft reported the same share for the vulnerabilities it assigns a CVE each year.24 Both numbers are a few years old, which is why Google's newer Android data matters.
Rust checks who owns each piece of memory when it compiles. If code could use memory after it's freed, or if two threads could write the same data at once, it doesn't compile. You still get native speed, and there's no garbage collector.
What Google measured in Android
Google started moving new Android code to memory-safe languages around 2019. Over six years, memory safety bugs fell from 76% of Android's vulnerabilities to 24%.25 In 2025 they dropped below 20% for the first time.26 Some of that comes from Java and Kotlin, which are memory safe too.
For Rust on its own, Google estimates a 1000x lower density of memory safety vulnerabilities than in Android's C and C++. The bigger surprise was speed of delivery. Rust changes had a 4x lower rollback rate and spent 25% less time in code review. In Google's words, "the safer path is now also the faster one."26
Why this matters more for AI
AI companies now ship software that handles untrusted input all day. An agent reads web pages, opens files and runs commands it didn't write. When OpenAI explained its Rust rewrite of Codex CLI, native security bindings were one of the four reasons, since it already used Rust for sandboxing on Linux.27
The sandboxes are often Rust too. Firecracker, the mostly Rust virtual machine monitor AWS built for Lambda,28 now also runs AWS Lambda MicroVMs, which are made for running user and AI-generated code in isolation.29 Agent sandbox companies like E2B build on it as well.30
Reliability matters as much as security. xAI compared LLM training to a freight train: if one car derails, the whole train comes off the tracks. It credited Rust with high performance and with preventing most of the bugs you'd normally find in a distributed system.7
What the C++ side says
The C++ community doesn't deny the problem. Herb Sutter, the long-time chair of the ISO C++ committee, has argued that cutting C++'s type, bounds, initialization and lifetime bugs by 90% to 98% would end the debate, and that C++ can get there while staying compatible with existing code.31
In February 2025 Bjarne Stroustrup, who created C++, sent an urgent note to the committee. He wrote that C++ was under attack from US and EU regulators, large companies and promoters of other languages, and that the US government wanted a plan for memory safety by 2026. His answer was profiles, a set of safety rules that compilers could enforce.32 US guidance does set a date: CISA and the FBI told software makers to publish a memory safety roadmap by the end of 2025.33
Profiles aren't in the language yet. When Stroustrup made the note public, he added that C++26 will get a hardened standard library and that he was disappointed the committee couldn't focus on profiles.32 For a company writing new systems code in 2026, Rust is the memory-safe option that's ready now.
Mark Russinovich, Azure's CTO, has been blunt about this since 2022. He said it was time to stop starting new projects in C or C++ and to use Rust wherever a language without a garbage collector is needed.34 Not every headline holds up, though. In December 2025 a Microsoft engineer posted a goal of removing every line of C and C++ from Microsoft by 2030 with the help of AI. He later clarified that it was a research project and that Windows is not being rewritten in Rust.35
What Linux decided
The Linux kernel had this argument in public. Greg Kroah-Hartman wrote in February 2025 that most of the kernel bugs he sees come from small C corner cases, like memory overwrites, missed cleanup on error paths, unchecked error values and use-after-free. In Rust those disappear, which is why he wants Rust in the kernel.36 At the December 2025 Maintainers Summit the developers agreed the Rust experiment was a success,37 and a commit removing the "experimental" label followed in January 2026.38
Not everyone liked it. Christoph Hellwig, a long-time kernel maintainer, called a mixed C and Rust codebase a cancer he wanted kept out of core code. A few days later he added that Rust is one of the best new languages and that he encourages people to use it for new projects where it fits.39 His objection was to mixing two languages in one huge codebase, and that's a real cost.
Why not Java?
Java is memory safe and fast once the JIT has warmed up. It still runs huge parts of the data world, like Spark and Elasticsearch, and Elasticsearch's vector search runs on Java's SIMD vector API.40 So why don't AI companies pick it for this work?
It brings a runtime with it
A Java program needs a JVM. That's fine on a server you control. It's a problem for software you ship to other people. The first reason OpenAI gave for rewriting Codex CLI was a zero-dependency install, because requiring Node 22 was a blocker for some users.27 A JVM is the same kind of dependency.
GitHub's Copilot post spells this out. Its SDKs for C#, Python, Go, Java and Rust each paid for a whole second language runtime per client, around 100 MB of memory, for a runtime the app had no other use for. GitHub picked Rust because it compiles to a native library with a C ABI that any language can load into its own process. Running in-process, one test scenario went from 5.25 seconds to 292 milliseconds.3
It doesn't fit inside Python
Most AI code runs inside a Python process. A Rust library becomes an ordinary Python package and runs in that same process with no extra runtime, which is why pip install ruff just works.13 Calling a Java library from Python means starting a JVM inside or next to the Python process, and paying for it on every machine.
Garbage collection is less of a problem than it used to be
To be fair to Java, the old complaint about long GC pauses is mostly solved. Generational ZGC, added in JDK 21, aims to keep pauses under 1 millisecond.41 Netflix switched its default to it, and more than half of its critical streaming services now run on it.42 What's left is the runtime itself and its memory, and those matter most when your code runs inside someone else's process or on their laptop. Russinovich drew the line in the same place: Rust where a language without a garbage collector is needed.34
Where a garbage collector is fine, Go is the usual pick. Microsoft moved the TypeScript compiler to Go and got a 10x speedup.43 At Google, Lars Bergstrom said rewriting services from Go to Rust took about the same size team about the same time, while rewrites from C++ to Rust cut the effort to build and maintain them by more than 2x.44 Armin Ronacher, who created Flask, recommended Go over Rust in 2025 for new backends written with coding agents, partly because agents kept getting cargo test wrong.45
What Rust costs
- Slow builds. In Google's survey of more than 1,000 of its Rust developers, slow builds were by far the top complaint, and only a little over 40% found build speed acceptable.46 In the Rust project's own 2025 survey, about 45% of people who stopped using Rust said long compile times were one of the reasons.47
- A learning curve. The same Google survey found that more than two thirds of developers felt confident contributing to a Rust codebase within two months.46 A small game studio that left Rust after three years said the borrow checker kept forcing refactors that got in the way of fast iteration.48
- Two languages in one codebase. Adding a second language to a project as old as CPython is a lot to ask of its maintainers, so the plan there is careful. Rust would ship as an optional part of Python 3.16 in October 2027, with the C code kept as a fallback, and become required no earlier than Python 3.18 in 2029.49
- Unsafe code doesn't disappear. Rust has an escape hatch,
unsafe, for code the compiler can't check. Bun's port started as a close translation of its Zig code, and the team plans to cut back its unsafe usage after v1.4.50 - GPUs are still out of reach. Chris Lattner's company Modular looked at extending C++, Rust, Julia or Swift for AI hardware. It concluded none of them support the accelerator features it needed, because they were designed for CPUs, and built Mojo instead.51 Lattner has also said that Rust's bigger problem is cultural, with a library ecosystem that leans very low level.52
What changed in 2026: agents write the Rust
The old case against a rewrite was cost. A team that moves a big system to a new language spends a year or more shipping nothing new. In 2026 that cost dropped fast.
- Anthropic says that by May 2026 Claude was writing more than 80% of the code it merged. For the Messages API it ran the Rust version on production traffic, found where it behaved differently, and sent agents to fix each difference.1
- OpenAI rewrote Habitat in one quarter with two engineers, Codex and GPT-5.5.2
- Bun's creator, Jarred Sumner, ported its 535,496 lines of Zig to Rust in 11 days, using about 50 Claude Code workflows running nonstop.50 Bun has been part of Anthropic since December 2025.53
- GitHub says the Copilot port was done mainly by a single developer in a few months, for roughly $120,000 in tokens plus about three weeks of that developer's time.3
Rust's strict compiler suits this way of working. In C++, a use-after-free that an agent writes can compile cleanly and fail much later. In Rust it doesn't compile, and the agent sees the error right away. The Bun post makes this case directly: letting the compiler reject a mistake works better than asking people to follow a style guide.50
The vLLM team made the same point about people. With coding agents, the gap between Python and Rust in how easy it is to contribute mostly goes away.9 Armin Ronacher, who preferred Go for agent work a year earlier, wrote in August 2026 that LLMs have made the choice of language matter far less, and that people who wouldn't have picked Rust before now ship Rust code.54
Python, Java, C++ and Rust side by side
| Python | Java | C++ | Rust | |
|---|---|---|---|---|
| Speed on CPU work | Slow, interpreted | Fast once warmed up | Fastest | Fastest |
| Memory safe | Yes | Yes | No | Yes, checked when compiling |
| Garbage collector | Yes | Yes, with sub-millisecond options | No | No |
| What you ship | An interpreter and packages | A JVM and your code | A native binary | A native binary or library |
| Inside a Python process | It is Python | Needs a JVM | Yes, with care | Yes, through PyO3 |
| Parallel threads | Held back by the GIL by default | Yes | Yes, data races possible | Yes, data races don't compile |
| GPU kernels | Through Triton | Rare | Home of CUDA | Not yet |
| Main cost | CPU and memory at scale | Runtime size and memory | Memory bugs | Build times, learning curve |
So why are the dominant AI companies moving to Rust?
Put all of these posts side by side and the same five reasons keep coming back.
- The CPU around the GPU became the bottleneck. Every request passes through an API, a tokenizer, a router and storage before and after the GPU does its part. With hundreds of millions of users, Python's interpreter, garbage collector and GIL turn into a big bill and slower replies. Rust cut Anthropic's CPU per request by about 70% and made OpenAI's storage 6x more CPU efficient.12
- They ship software to people's machines now. Codex, Claude Code and Copilot run on laptops and inside other people's apps. Rust gives them one native file with no Node or JVM to install, and a library any language can load.273
- Safety became a requirement. Agents handle untrusted input and run untrusted code. Memory bugs are most of the serious vulnerabilities in C and C++ code, and US agencies asked for memory safety roadmaps. Rust gives C++ speed with memory safety checked by the compiler.232633
- It fits under Python. Researchers keep writing Python, and Rust goes underneath as an ordinary Python package. Nobody has to retrain the research team, and the model code doesn't change.21
- AI made the rewrite cheap. Agents now write most of the code, and Rust's compiler checks their work. Ports that used to take a team a year now take days to months.1503
What isn't moving matters just as much. The model code stays in Python. The GPU math stays in C++, CUDA and Triton. Spark and Elasticsearch stay on the JVM, and Go keeps winning where a garbage collector is fine.
So the honest version of the headline is a little narrower, and more useful. The dominant AI companies are moving the CPU side of AI to Rust: the APIs, gateways, tokenizers, storage, agent tools and sandboxes. The model itself stays in Python and CUDA.
If you've watched a team pick Go or C++ over Rust for a new AI service, or move off Rust, I'd like to hear why.
References
- Anthropic, "Migrating our Messages API to Rust" (Nov 2026). anthropic.com/research/migrating-api-to-rust
- J. Lee, C. Yu and B. Ries (OpenAI), "Rapidly scaling online storage to serve over 1 billion ChatGPT users" (Sep 2026). openai.com/index/scaling-storage-one-billion-users-part-one
- S. Toub (GitHub), "Migrating the GitHub Copilot runtime to Rust, using Copilot" (Sep 2026). github.blog/ai-and-ml/generative-ai/migrating-the-github-copilot-runtime-to-rust-using-copilot
- PyTorch documentation, "PyTorch C++ API". docs.pytorch.org/cppdocs
- pytorch/pytorch on GitHub, language breakdown checked 27 Nov 2026. github.com/pytorch/pytorch
- OpenAI, tiktoken repository and README (created Dec 2022). github.com/openai/tiktoken
- xAI, "Announcing Grok" (Nov 2023). x.ai/news/grok
- V. Krasnov and M. Galicer (Cloudflare), "How we built the most efficient inference engine for Cloudflare's network" (Aug 2025). blog.cloudflare.com/cloudflares-most-efficient-ai-inference-engine
- N. Hill, "[RFC]: Rust front-end", vllm-project/vllm issue #40846 (Apr 2026). github.com/vllm-project/vllm/issues/40846
- B. Hsu, "[router] rust-based router", sgl-project/sglang pull request #1790 (Oct 2024). github.com/sgl-project/sglang/pull/1790
- NVIDIA, Dynamo repository and README (created Mar 2025). github.com/ai-dynamo/dynamo
- Python documentation, "Python support for free threading". docs.python.org/3/howto/free-threading-python.html
- C. Marsh, "Python tooling could be much, much faster" (Aug 2022). notes.crmarsh.com/python-tooling-could-be-much-much-faster
- S. Colvin, "Introducing Pydantic v2" (Jul 2022). pydantic.dev/articles/pydantic-v2
- S. Colvin and T. Dorsey, "Announcement: Pydantic V2 Release" (Jun 2023). pydantic.dev/articles/pydantic-v2-final
- Hugging Face, Tokenizers documentation. huggingface.co/docs/tokenizers/index
- Meta, "Open-sourcing Pyrefly: A faster Python type checker written in Rust" (May 2025). engineering.fb.com/2025/05/15/developer-tools/open-sourcing-pyrefly-a-faster-python-type-checker-written-in-rust
- Google Open Source Blog, "Adopting Pyrefly as the Python type checker at Google" (Oct 2026). opensource.googleblog.com/2026/10/adopting-pyrefly-as-the-python-type-checker-at-google.html
- A. Karpathy, rustbpe README. github.com/karpathy/rustbpe
- OpenAI, "OpenAI to acquire Astral" (Mar 2026). openai.com/index/openai-to-acquire-astral
- Python Software Foundation, "The Python Language Summit 2025: What do core developers want from Rust?" (Jun 2025). pyfound.blogspot.com/2025/06/python-language-summit-2025-what-do-core-developers-want-from-rust.html
- Meta, "Rust at Scale: An Added Layer of Security for WhatsApp" (Jan 2026). engineering.fb.com/2026/01/27/security/rust-at-scale-security-whatsapp
- The Chromium Projects, "Memory safety". chromium.org/Home/chromium-security/memory-safety
- Microsoft Security Response Center, "A proactive approach to more secure code" (Jul 2019). microsoft.com/en-us/msrc/blog/2019/07/a-proactive-approach-to-more-secure-code
- J. Vander Stoep and A. Rebert (Google), "Eliminating Memory Safety Vulnerabilities at the Source" (Sep 2024). security.googleblog.com/2024/09/eliminating-memory-safety-vulnerabilities-Android.html
- J. Vander Stoep (Google), "Rust in Android: move fast and fix things" (Nov 2025). security.googleblog.com/2025/11/rust-in-android-move-fast-fix-things.html
- OpenAI, "Codex CLI is Going Native", openai/codex discussion #1174 (May 2025). github.com/openai/codex/discussions/1174
- Firecracker project site and repository. firecracker-microvm.github.io
- AWS, "AWS introduces Lambda MicroVMs for isolated execution of user and AI-generated code" (Jun 2026). aws.amazon.com/about-aws/whats-new/2026/06/aws-lambda-microvms
- E2B runtime repository. github.com/e2b-dev/runtime
- H. Sutter, "C++ safety, in context" (Mar 2024). herbsutter.com/2024/03/11/safety-in-context
- B. Stroustrup, P3651R0, note to the C++ standards committee (written Feb 2025, made public Mar 2025). open-std.org/JTC1/SC22/WG21/docs/papers/2025/p3651r0.pdf
- CISA and FBI, "Product Security Bad Practices" (v2.0, Jan 2025). cisa.gov/resources-tools/resources/product-security-bad-practices
- T. Claburn (The Register), "In Rust We Trust: Microsoft Azure CTO shuns C and C++" (Sep 2022). theregister.com/2022/09/20/rust_microsoft_c
- G. Hunt (Microsoft), LinkedIn post and its clarification (Dec 2025). linkedin.com/posts/galenh_principal-software-engineer-coreai-microsoft-activity-7407863239289729024-WTzf
- G. Kroah-Hartman, "Re: Rust kernel policy", LKML (Feb 2025). lkml.indiana.edu/2502.2/04452.html
- LWN.net, "The state of the kernel Rust experiment" (Dec 2025). lwn.net/Articles/1050174
- M. Ojeda, "rust: conclude the Rust experiment", Linux commit 9fa7153. github.com/torvalds/linux/commit/9fa7153c31a3
- C. Hellwig, "Re: [PATCH v8 2/2] rust: add dma coherent allocator abstraction", LKML (Jan 2025), first message and follow-up.
- C. Hegarty (Elastic), "Accelerating vector search with SIMD instructions" (Jun 2023). elastic.co/blog/accelerating-vector-search-simd-instructions
- OpenJDK, "JEP 439: Generational ZGC". openjdk.org/jeps/439
- Netflix, via inside.java, "Bending Pause Times to Your Will with Generational ZGC" (Mar 2024). inside.java/2024/03/06/generational-zgc-netflix
- A. Hejlsberg (Microsoft), "A 10x Faster TypeScript" (Mar 2025). devblogs.microsoft.com/typescript/typescript-native-port
- T. Claburn (The Register), "Rust developers at Google twice as productive as C++ teams" (Mar 2024). theregister.com/2024/03/31/rust_google_c
- A. Ronacher, "Agentic Coding Recommendations" (Jun 2025). lucumr.pocoo.org/2025/6/12/agentic-coding
- L. Bergstrom and K. Brennan (Google), "Rust fact vs. fiction: 5 Insights from Google's Rust journey in 2022" (Jun 2023). opensource.googleblog.com/2023/06/rust-fact-vs-fiction-5-insights-from-googles-rust-journey-2022.html
- Rust project, "Rust compiler performance survey 2025 results" (Sep 2025). blog.rust-lang.org/2025/09/10/rust-compiler-performance-survey-2025-results
- LogLog Games, "Leaving Rust gamedev after 3 years" (Apr 2024). loglog.games/blog/leaving-rust-gamedev
- Python Insider, "Rust for CPython (Python Language Summit 2026)" (Sep 2026). blog.python.org/2026/09/language-summit-2026-rust-for-cpython
- J. Sumner, "Rewriting Bun in Rust" (Jul 2026). bun.com/blog/bun-in-rust
- Modular, "Mojo vision". docs.modular.com/mojo/vision
- Latent Space, "Doing it the Hard Way: Making the AI engine and language of the future", with C. Lattner (Sep 2023). latent.space/p/modular
- Anthropic, "Anthropic acquires Bun as Claude Code reaches $1B milestone" (Dec 2025). anthropic.com/news/anthropic-acquires-bun-as-claude-code-reaches-usd1b-milestone
- A. Ronacher, "Fast and Hard Code" (Aug 2026). lucumr.pocoo.org/2026/8/22/fast-hard-code