cover of episode CodeSandbox with Ives van Hoorne

CodeSandbox with Ives van Hoorne

2024/12/4
logo of podcast Software Engineering Daily

Software Engineering Daily

People
I
Ives van Hoorne
Topics
Ives van Hoorne: CodeSandbox 是一个在线开发环境,允许开发者在浏览器中进行完整的 Web 开发项目工作。它类似于 Google Docs 和 Microsoft Word 的协作理念,旨在简化代码共享和协作。其核心功能是代码编辑器和预览窗口,将代码编辑器(左侧)的输入转换为预览窗口(右侧)的输出。CodeSandbox 的发展始于作者在团队协作中共享 React 代码的困难,以及对类似 Figma 和 Google Docs 的在线协作工具的启发。最初版本使用 JavaScript、Create React App、Elixir 后端、Postgres 数据库和 Redis 缓存。为了支持大型项目,CodeSandbox 推出了 DevBoxes 功能,使用虚拟机运行项目,并通过 WebSockets 连接进行文件检索。为了提高 DevBoxes 的性能和可扩展性,CodeSandbox 使用了 Firecracker 虚拟机技术,该技术允许暂停和恢复虚拟机,并从快照中创建新的虚拟机。为了解决安全问题,CodeSandbox 通过多种方法来确保 DevBoxes 的安全性,包括使用 Unix 用户、jailer 和检测算法来防止滥用,例如加密货币挖掘和网络钓鱼。为了应对网络钓鱼攻击,CodeSandbox 在预览页面添加了警告信息,提醒用户注意潜在风险。CodeSandbox 的前端使用 iframe 来渲染预览部分,以隔离用户应用并提高安全性。它通过解析代码、转换代码和使用 eval 函数来执行代码。为了优化用户体验,CodeSandbox 提供了安装依赖项的建议,并对一些常见错误进行了处理。CodeSandbox 的依赖项安装通过 AWS Lambda 服务处理,并对下载过程进行了优化。CodeSandbox 的代码编辑器最初使用 CodeMirror,后来迁移到 Monaco(VS Code 的代码编辑器),并通过模拟 Node.js 环境来支持扩展。为了实现类型信息的显示,CodeSandbox 在浏览器中运行 VS Code 扩展程序,并模拟 Node.js 环境和文件系统。CodeSandbox 现在直接从 NPM 注册表下载 tar 文件来获取类型文件,以降低带宽成本。未来 CodeSandbox 可能转向使用 ES 模块和 Service Worker 来改进打包和执行代码的方式。CodeSandbox 的 Firecracker 虚拟机技术具有广泛的应用潜力,可以扩展到 CI/CD 系统和其它领域。 Josh Goldberg: 主要参与访谈,提出问题,引导 Ives van Hoorne 讲解 CodeSandbox 的技术细节。

Deep Dive

Key Insights

What is CodeSandbox and how does it compare to traditional development tools?

CodeSandbox is an online development environment that allows users to start web development projects directly in the browser. It is similar to Google Docs, where users can share a link to a live, editable environment, eliminating the need for local setups.

Why did Ives van Hoorne start coding?

Ives started coding at around 10 years old to create a program that translated a secret language he and his friend used to write letters in class. This was his first interaction with programming, using Visual Basic to create a simple translator.

How did Ives van Hoorne's early coding experience influence his later work?

Ives' first coding project involved creating a program with input on the left and output on the right, a concept that mirrors the core functionality of CodeSandbox, where users write code on the left and see the result on the right.

What challenges did Ives face when transitioning from graphic design to coding?

Ives initially disliked graphic design because it was too subjective, with clients often requesting designs he didn't agree with. He found coding more appealing as it felt like solving puzzles with clear solutions, though he later realized coding also has subjective elements.

How did Ives van Hoorne's experience at his first job influence the creation of CodeSandbox?

At his first job, Ives struggled with sharing React code snippets over Slack, as it was difficult to debug errors without a live environment. This frustration led him to envision an online code environment where users could share running code easily, similar to Google Docs.

What was the initial tech stack of CodeSandbox when it launched in 2017?

The initial tech stack included Create React App for the frontend, Elixir with the Phoenix framework for the backend, Postgres for the database, and Redis for caching. The entire platform was hosted on a $20 VPS with 2GB of RAM.

How did CodeSandbox scale its database to handle half a billion files?

CodeSandbox stored all files in a Postgres database, with each file represented as a row. Despite handling over 500 million files, the database queries remained efficient, with sandbox loading times under 100 milliseconds due to well-indexed columns in Postgres.

Why did CodeSandbox introduce DevBoxes, and how do they differ from sandboxes?

DevBoxes were introduced to support larger projects that exceeded the 500-file limit of sandboxes. Unlike sandboxes, which run entirely in the browser, DevBoxes run on a server-based VM, allowing for full-scale development with features like lazy file retrieval and VM snapshots.

How does CodeSandbox handle security for its DevBoxes?

DevBoxes use Firecracker, a VM technology developed by AWS, which allows for secure execution of user code. Each VM runs as a separate Unix user, and a jailer ensures code remains within its environment, preventing unauthorized access to the host system.

What challenges does CodeSandbox face with crypto miners and phishing attempts?

Crypto miners often abuse CodeSandbox by running miners on VMs, while phishing attempts involve creating fake login pages. CodeSandbox uses detection heuristics and AI to identify and block malicious activities, though it remains a constant cat-and-mouse game.

How does CodeSandbox execute user code in the browser?

CodeSandbox executes user code by parsing it to create a dependency graph, transpiling the code, and then using JavaScript's eval function to run it. The require function is overridden to handle dynamic imports, creating a loop that allows for efficient code execution.

How does CodeSandbox handle dependency installations for NPM packages?

CodeSandbox uses an AWS Lambda service to install NPM dependencies, creating a dependency graph to determine which files are needed. These files are then bundled and cached in an S3 bucket, allowing for fast retrieval and installation of dependencies.

How does CodeSandbox integrate VS Code into its editor?

CodeSandbox uses the browser version of VS Code, emulating Node.js in the browser to run VS Code extensions. This allows users to have a familiar VS Code experience with features like type information and extensions, all within the browser environment.

What is Ives van Hoorne's vision for the future of CodeSandbox's infrastructure?

Ives envisions generalizing the Firecracker-based infrastructure to support not just development environments, but also CI/CD systems and deployments. This technology could significantly reduce setup times and improve parallelization in CI/CD pipelines.

Why does Ives van Hoorne enjoy playing volleyball?

Ives enjoys volleyball because it allows him to disconnect from work and focus entirely on the game. It is also a highly competitive and physically demanding sport, requiring short bursts of energy and strategic thinking, which he finds both challenging and rewarding.

Chapters
CodeSandbox, founded in 2017, is an online development environment allowing users to work on web development projects directly in their browsers. It's compared to collaborative document editors like Google Docs, enabling easy code sharing and collaboration. The core functionality involves a code editor on the left and a preview on the right, mirroring the input-output process from the founder's early programming experiences.
  • Founded in 2017
  • Cloud-based development environment
  • Allows users to work directly in their browsers
  • Core functionality: code editor on the left, preview on the right

Shownotes Transcript

CodeSandbox) was founded in 2017 and provides cloud based development environments along with other features. It’s quickly become one of the most prominent cloud development platforms.

Ives van Hoorne) is a Co-Founder at CodeSandbox. He joins the show to talk about the platform.

)

Josh Goldberg is an independent full time open source developer in the TypeScript ecosystem. He works on projects that help developers write better TypeScript more easily, most notably on typescript-eslint: the tooling that enables ESLint and Prettier to run on TypeScript code. Josh regularly contributes to open source projects in the ecosystem such as ESLint and TypeScript. Josh is a Microsoft MVP for developer technologies and the author of the acclaimed Learning TypeScript) (O’Reilly), a cherished resource for any developer seeking to learn TypeScript without any prior experience outside of JavaScript. Josh regularly presents talks and workshops at bootcamps, conferences, and meetups to share knowledge on TypeScript, static analysis, open source, and general frontend and web development.

Please click here to see the transcript of this episode.)

Sponsorship inquiries: [email protected])

The post CodeSandbox with Ives van Hoorne) appeared first on Software Engineering Daily).