<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/bun-s-1m-line-ai-rust-rewrite-has-13-365-unsafe-blocks-and-it-made-me-glad-i-chose-to-learn-deno-wcwwgbdqp" -->

---
title: Bun’s 1M-line AI Rust rewrite has 13,365 unsafe...
description: A student developer shares their reaction to Bun's AI-assisted rewrite of its codebase from Zig to Rust — a nearly 1-million-line port executed by Claude...
canonical: https://daily.dev/posts/bun-s-1m-line-ai-rust-rewrite-has-13-365-unsafe-blocks-and-it-made-me-glad-i-chose-to-learn-deno-wcwwgbdqp
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Bun’s 1M-line AI Rust rewrite has 13,365 unsafe blocks—and it made me glad I chose to learn Deno | daily.dev
og:description: A student developer shares their reaction to Bun's AI-assisted rewrite of its codebase from Zig to Rust — a nearly 1-million-line port executed by Claude...
og:url: https://daily.dev/posts/bun-s-1m-line-ai-rust-rewrite-has-13-365-unsafe-blocks-and-it-made-me-glad-i-chose-to-learn-deno-wcwwgbdqp
og:image: https://api.daily.dev/og/posts/WcWWgBdQp.png
og:image:alt: Bun’s 1M-line AI Rust rewrite has 13,365 unsafe blocks—and it made me glad I chose to learn Deno
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Bun’s 1M-line AI Rust rewrite has 13,365 unsafe blocks—and it made me glad I chose to learn Deno

**[Rene Yibowei](https://daily.dev/sources/atul3chxfypngktbogisl)** · [@qwertydiy](https://daily.dev/qwertydiy) · 6 min read · 37 upvotes · 14 comments

## Summary

A student developer shares their reaction to Bun's AI-assisted rewrite of its codebase from Zig to Rust — a nearly 1-million-line port executed by Claude agents in six days. The rewrite introduced 13,365 unsafe blocks, giving Bun an unsafe density of 13.7 per 1,000 lines, nearly double Deno's 8.4. Five functions with real undefined behavior were flagged in the pre-release audit. The author argues the deeper problem is that no human fully understands the new codebase, raising concerns about hidden bugs, security vulnerabilities in a privileged runtime environment, and compounding technical debt. They conclude that Deno's hand-crafted, human-audited Rust codebase is the safer choice for backend development.

## Content

I’m a student learning to become a full-stack web developer. I don’t know Rust, I don’t write low-level systems code. When I’m building a backend, I want a runtime that works out of the box, doesn’t crash on deployment, and doesn’t require an ungodly amount of configuration.

Like most people, I watched the Bun hype cycle unfold over the last couple of years. It was flashy, it blew past Node in hello-world benchmarks, and it promised to be a drop-in replacement.

But the massive news this month completely changed my perspective. Following Bun’s acquisition by Anthropic, the team merged [PR #30412](https://github.com/oven-sh/bun/pull/30412)—a nearly 1-million-line codebase translation from Zig to Rust executed almost entirely by automated Claude AI agents over six days, replacing the whole codebase. To be clear, the sheer technical feat of an automated port at that scale is genuinely impressive. The team used a detailed 300-rule guide to map Zig idioms to Rust, and the initial test pass rate hit 99.8%.

That said, when I dug into the details, what I found made me pretty uneasy, to put it lightly.

The pre-release audit reports that the AI generated 13,365 `unsafe` blocks to get the port to compile. Here’s how that unsafe density per 1,000 lines compares to other runtimes, using numbers from [Bun’s own public audit](https://bun.com/bun-unsafe-audit):

| Runtime / Project | Unsafe Blocks | Total Lines | Unsafe per 1k lines |

|-------------------|---------------|-------------|---------------------|

| Deno (incl. rusty_v8) | 4,852 | 577k | 8.4 |

| Tokio (async runtime) | 1,133 | 174k | 6.5 |

| Bun (new Rust port) | 13,365 | 978k | 13.7 |

To be fair, about 29.8% of those (3,986) are standard FFI boundaries into JavaScriptCore and BoringSSL—that’s normal for any runtime. Another 33.9% (4,530) are Zig-era ownership patterns carried across. But the reality remains: Bun’s unsafe density is nearly double Deno’s, even after Deno’s number includes its full V8 binding layer.

More importantly, the audit has already flagged **five functions that are unsound today**—real undefined behavior reachable from safe Rust, not part of the 13,365 count. Those are bugs that exist _right now_ in the pre-release.

**The iceberg beneath the **`unsafe`** count.**

The number of unsafe blocks is only the surface problem. The deeper issue is that a million lines of AI-translated systems code arrived with no human mental model attached.

When an LLM translates line-by-line, it doesn’t preserve _why_ a particular memory ordering or error path exists. It produces a statistically plausible imitation that compiles but may violate the original design in ways that only surface under specific, hard-to-reproduce conditions. Observers of the PR raised concerns that some tests appeared modified for the Rust version rather than faithfully translated from the Zig originals—making the 99.8% pass rate less reassuring than it sounds. That’s not a port; that’s a patchwork.

No single human on the Bun team fully understands this new codebase. They’ll spend months to years auditing, learning, and fixing the AI’s mistakes—time that won’t go toward performance or features. And future contributors (and AI tools) will now learn from this code as if it were canonical, compounding the technical debt.

**The vulnerability profile no one’s talking about.**

As you should know, Bun isn’t a frontend library. It’s a runtime that typically runs with filesystem access, environment secrets, and network privileges. In production deployments, it’s often PID 1 in a container—meaning it is one container breakout away from the host, one lateral movement from your Kubernetes cluster, and one cloud metadata endpoint call from your entire cloud account. Container breakouts are real: CVEs like the NVIDIA Container Toolkit vulnerability exposed 37% of cloud environments, and research has demonstrated LLMs breaking out of Docker and K8s sandboxes.

Inject a million lines of AI-generated code with thousands of `unsafe` blocks into that trust boundary, and you’ve massively expanded the attack surface with code no human has fully reviewed. We’ve seen meticulously audited runtimes ship critical CVEs for years. How long until someone finds the first RCE in an AI-hallucinated piece of code?

**Why I’m sticking with Deno.**

I chose to learn Deno early on, and I haven’t looked back. Deno’s approach—years of hand-crafted, idiomatic, memory-safe Rust—looks incredibly vindicated right now. They didn’t dump a million lines of AI-generated code overnight to escape a language crisis. The Demo team built a runtime that’s predictable, secure by default, and boring in the best way.

Deno has had its own CVEs, of course—no runtime is flawless. But the process is transparent, the code is human-audited, and the architecture hasn’t been fundamentally rewritten by an LLM between releases.

I know the immediate pushback: “But npm.” I get it—I was there too. Moving to pnpm felt like one more thing to learn, but it was genuinely painless. And after the Shai Hulud attack that compromised 300+ packages and stole cloud keys from orgs like OpenAI, Mistral, and Grafana Labs, I’m glad I’m not relying on npm’s default behavior anymore. Deno’s first-class npm compatibility means I can still pull in any package I need; I just don’t have to live inside npm’s increasingly problematic ecosystem to do it.

I love pushing boundaries, but for core backend infrastructure, “boring and predictable” wins. Are any other full-stack devs re-evaluating their runtime choices after this, or are people still planning to ride the Bun hype train through an AI transition that nobody fully understands?

---

**Sources:**

- Bun PR #30412 (Rewrite Bun in Rust): [github.com/oven-sh/bun/pull/30412](https://github.com/oven-sh/bun/pull/30412)
- Bun's official Rust port audit (13,365 unsafe blocks, five unsound functions, density comparison): [bun.com/bun-unsafe-audit](https://bun.com/bun-unsafe-audit)
- WebProNews coverage (six days, 99.8% pass rate, 300-rule PORTING.md, GitHub flagged deletion as "AI slop"): [webpronews.com](https://www.webpronews.com/anthropics-ai-agents-rewrite-bun-in-rust-one-million-lines-merged-in-days/)
- CVE-2025-23266 — NVIDIA Container Toolkit flaw exposing 37% of cloud environments: [thehackernews.com](https://thehackernews.com/2025/07/critical-nvidia-container-toolkit-flaw.html)
- SANDBOXESCAPEBENCH — LLM Container Sandbox Escape (arXiv, March 2026): [arxiv.org/abs/2603.02277](https://arxiv.org/abs/2603.02277)
- Shai-Hulud npm supply chain attack — 300+ packages: [jswx.gov.cn](https://jswx.gov.cn/anquan/zixun/202605/t20260525_1332455.shtml)
- Mini Shai-Hulud campaign — OpenAI, Mistral, Grafana Labs affected: [cisowhisperer.com](https://cisowhisperer.com/over-320-npm-packages-hit-by-fresh-mini-shai-hulud-supply-chain-attack/)
- Deno security advisories (2025–2026): [cybersecurity-help.cz](https://www.cybersecurity-help.cz/vdb/SB20260423126)

**EDIT:** To clarify a point raised in the comments: the Rust rewrite has been merged to Bun's `main` branch and is available via `bun upgrade --canary`, but the current stable release (v1.3.x) still ships from the original Zig codebase. This article discusses the pre-release code as audited by the Bun team themselves.

## Community discussion

Top comments from developers on daily.dev.

**@duckduckquaquack** · 14 upvotes

> I know you said you're a student so I'll add nuance to everything you said
>
> 1. Rewrites don't always happen from scratch. These days people prefer to shift from language a to b step by step. The first step is just converting all your code line by line and making tests pass and the second step would be writing the code in the idiomatic way. They wrote rust in zig, its fine this is step one. They will now write rust the idiomatic way.
> 2. Don't worry about memory safety just yet. Zig is not memory safe, so when they move from Zig to Rust, the unsafe blocks just uncover the unsafe boundaries in...

**@andradei** · 3 upvotes

> They might have good reasons to have decided to switch to Rust using the agent they sell, but it looks like a pet project and an arbitrary decision from the outside.
>
> It might become a good runtime again once the code it re-written to be idiomatic. But it feels unnecessary. Even when they expressed how hard it is to avoid memory safety issues, I thought Zig tests could use debug/test allocators that point out memory leaks at least.

**@petermrozek** · 2 upvotes

> "By design" I don't trust anything that's hype-developed or hype-adopted, thus I left out Bun as a curiosity. Now at least I know it was a good decision to hold back and I'll still be holding back a long while. Given the numbers you just posted, there's no way this rewrite is safe.
>
> A big mass of code like that, rewritten by a non-deterministic drawing machine without human supervision? It's a recipe for a disaster. 😉

**@theacademe** · 2 upvotes

> Sounds like we'll all be on 1.3.x for awhile. Let's hope the Rust rewrite is for v2.x, and maybe about 2.4 it'll be stable.

**@baptistecrouzet** · 1 upvotes

> Maybe a good point : Rust seems better known by devs.
>
> Thanks for your post.

## Similar posts on daily.dev

- [Bun rewrite in rust](https://daily.dev/posts/bun-rewrite-in-rust-zff65rp1d) · Medium · 2 upvotes · 1 comments

---

Tags: [#security](https://daily.dev/tags/security), [#javascript](https://daily.dev/tags/javascript), [#rust](https://daily.dev/tags/rust), [#deno](https://daily.dev/tags/deno), [#bun](https://daily.dev/tags/bun)

[View this post on daily.dev](https://daily.dev/posts/bun-s-1m-line-ai-rust-rewrite-has-13-365-unsafe-blocks-and-it-made-me-glad-i-chose-to-learn-deno-wcwwgbdqp)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/bun-s-1m-line-ai-rust-rewrite-has-13-365-unsafe-blocks-and-it-made-me-glad-i-chose-to-learn-deno-wcwwgbdqp","headline":"Bun’s 1M-line AI Rust rewrite has 13,365 unsafe blocks—and it made me glad I chose to learn Deno","text":"A student developer shares their reaction to Bun's AI-assisted rewrite of its codebase from Zig to Rust — a nearly 1-million-line port executed by Claude agents in six days. The rewrite introduced 13,365 unsafe blocks, giving Bun an unsafe density of 13.7 per 1,000 lines, nearly double Deno's 8.4. Five functions with real undefined behavior were flagged in the pre-release audit. The author argues the deeper problem is that no human fully understands the new codebase, raising concerns about hidden bugs, security vulnerabilities in a privileged runtime environment, and compounding technical debt. They conclude that Deno's hand-crafted, human-audited Rust codebase is the safer choice for backend development.","url":"https://daily.dev/posts/bun-s-1m-line-ai-rust-rewrite-has-13-365-unsafe-blocks-and-it-made-me-glad-i-chose-to-learn-deno-wcwwgbdqp","datePublished":"2026-05-26T17:26:55.518Z","dateModified":"2026-05-26T18:34:01.441Z","author":{"@type":"Person","name":"Rene Yibowei","url":"https://daily.dev/qwertydiy","image":"https://media.daily.dev/image/upload/s--QlvtioAW--/f_auto/v1746524446/avatars/avatar_aTUl3chxFyPngKtboGisL","description":"Secondary School Student doing the Full Stack with Linux, currently learning Data Science","interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":19410}},"interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":37},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":14}],"comment":[{"@type":"Comment","text":"I know you said you’re a student so I’ll add nuance to everything you said\n\nRewrites don’t always happen from scratch. These days people prefer to shift from language a to b step by step. The first step is just converting all your code line by line and making tests pass and the second step would be writing the code in the idiomatic way. They wrote rust in zig, its fine this is step one. They will now write rust the idiomatic way.\nDon’t worry about memory safety just yet. Zig is not memory safe, so when they move from Zig to Rust, the unsafe blocks just uncover the unsafe boundaries in Zig. So of course there will be a lot of them. But this is the whole point of the migration isn’t it! That now they can start to redesign around Rust tooling and the compiler to get the guarantees they need so the team can stop spending a lot of time worrying about memory safety.\nThe code is merged but not shipped. This is just part of git and release workflows. It will be shipped when they are done getting it to a good place. Code can exist in git in an imperfect state as teams work on it and get it to the right place\nThis isn’t the first time we have seen something like this. e.g Typescript is moving from Typescript to Go. They basically did the same thing. First they rewrote everything in Go, but in a “Javascriptsonic” way. Then they made the tests pass 70%. Then they made the announcement, and now - for a long time, they have been working in the background to write everything the idiomatic “go” way, and you can see this on their Github.\nThe team is very experienced. I wouldn’t be worried, the port was done well and is really simple to follow. Most of the core Bun developers have also been writing Rust for a long time. Summer himself has been writing Rust longer than he has been writing Zig and the same is true for the rest of the team. The team ships 600k lines of code by hand every year, I would trust them to go through the code and eventually rewrite everything the right way.","datePublished":"2026-05-27T13:48:25.021Z","dateModified":"2026-05-27T13:58:02.935Z","url":"https://daily.dev/posts/WcWWgBdQp#c-k6l147P23","author":{"@type":"Person","name":"dddrew","url":"https://daily.dev/duckduckquaquack","image":"https://lh3.googleusercontent.com/a-/ACNPEu8Ete23R5GmXaxSzwFDueM8STY941qsB7fCOqBEC_Y=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":14}},{"@type":"Comment","text":"They might have good reasons to have decided to switch to Rust using the agent they sell, but it looks like a pet project and an arbitrary decision from the outside.\nIt might become a good runtime again once the code it re-written to be idiomatic. But it feels unnecessary. Even when they expressed how hard it is to avoid memory safety issues, I thought Zig tests could use debug/test allocators that point out memory leaks at least.","datePublished":"2026-05-26T23:44:17.944Z","dateModified":"2026-05-27T13:07:44.997Z","url":"https://daily.dev/posts/WcWWgBdQp#c-DGlpxXj02","author":{"@type":"Person","name":"Isaac de Andrade","url":"https://daily.dev/andradei","image":"https://avatars.githubusercontent.com/u/2653546?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":3}},{"@type":"Comment","text":"“By design” I don’t trust anything that’s hype-developed or hype-adopted, thus I left out Bun as a curiosity. Now at least I know it was a good decision to hold back and I’ll still be holding back a long while. Given the numbers you just posted, there’s no way this rewrite is safe.\nA big mass of code like that, rewritten by a non-deterministic drawing machine without human supervision? It’s a recipe for a disaster. 😉","datePublished":"2026-05-27T15:56:21.181Z","url":"https://daily.dev/posts/WcWWgBdQp#c-eL1aFwDew","author":{"@type":"Person","name":"Peter Mrożek","url":"https://daily.dev/petermrozek","image":"https://media.daily.dev/image/upload/s--pBfYX68K--/f_auto/v1769247960/avatars/avatar_Qz65P1nVw3Bu6C5YwaZgA?_a=BAMAMiiu0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"Sounds like we’ll all be on 1.3.x for awhile. Let’s hope the Rust rewrite is for v2.x, and maybe about 2.4 it’ll be stable.","datePublished":"2026-05-27T05:33:30.888Z","url":"https://daily.dev/posts/WcWWgBdQp#c-u68Vbiqyw","author":{"@type":"Person","name":"theacademe","url":"https://daily.dev/theacademe","image":"https://media.daily.dev/image/upload/s--C29_q-xW--/f_auto/v1756852849/avatars/avatar_wNAjl1VBaVx2CCjbkkb5h?_a=BAMClqZW0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"Maybe a good point : Rust seems better known by devs.\nThanks for your post.","datePublished":"2026-05-27T09:16:08.728Z","url":"https://daily.dev/posts/WcWWgBdQp#c-dBlw8V5NQ","author":{"@type":"Person","name":"Baptiste Crouzet","url":"https://daily.dev/baptistecrouzet","image":"https://avatars0.githubusercontent.com/u/26898487?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":1}}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/sources/atul3chxfypngktbogisl","name":"Rene Yibowei"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"Rene Yibowei","item":"https://daily.dev/sources/atul3chxfypngktbogisl"},{"@type":"ListItem","position":3,"name":"Bun’s 1M-line AI Rust rewrite has 13,365 unsafe blocks—and it made me glad I chose to learn Deno"}]}
```

