---
title: "Bun’s 1M-line AI Rust rewrite has 13,365 unsafe blocks—and it made me glad I chose to learn Deno"
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
source_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
type: freeform
source: "Rene Yibowei"
author: "Rene Yibowei"
published: 2026-05-26T17:26:55.518Z
updated: 2026-05-26T18:34:01.441Z
tags: ["security", "javascript", "rust", "deno", "bun"]
reading_time: 6
upvotes: 37
comments: 14
language: 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** · 15 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** · 4 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.

**@theacademe** · 3 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.

**@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. 😉

**@baptistecrouzet** · 1 upvotes

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

---

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)
