---
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-hm88vuqle
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-hm88vuqle
type: freeform
source: "Javascript "
author: "Rene Yibowei"
published: 2026-05-26T17:31:09.130Z
updated: 2026-05-26T18:34:28.727Z
tags: ["security", "javascript", "rust", "deno", "bun"]
reading_time: 6
upvotes: 0
comments: 0
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

**[Javascript ](https://daily.dev/sources/code_with_js)** · [@qwertydiy](https://daily.dev/qwertydiy) · 6 min read · 0 upvotes · 0 comments

## Summary

A student developer shares their perspective on 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 have already been flagged in the pre-release audit. The author argues the deeper problem is that no human fully understands the new codebase, raising concerns about long-term maintainability, 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. Ryan Dahl and his 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)

---

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-hm88vuqle)
