---
title: "How to add Monaco to a Next.js app and securely run untrusted user code"
description: "A Next.js 14 app can host a browser IDE by embedding the Monaco editor via @monaco-editor/react, then sending the editor contents to server-side API routes that call the Deno Deploy Subhosting API."
url: "https://swe.quest/articles/how-to-add-monaco-to-a-next-js-app-and-securely-run-untrusted-user-code-1a2e3adbb0c82f79"
canonical: "https://deno.com/blog/monaco-nextjs"
source: "Deno"
published: "2024-02-29"
difficulty: "medium"
kind: "How-to"
reading_minutes: 9
tags: ["react","sandboxing","serverless","frontend","javascript"]
---

# How to add Monaco to a Next.js app and securely run untrusted user code

A post on [Deno](https://swe.quest/sources/deno.md), published 2024-02-29, 9 min read, How-to. Original: [https://deno.com/blog/monaco-nextjs](https://deno.com/blog/monaco-nextjs)

## Summary

A Next.js 14 app can host a browser IDE by embedding the Monaco editor via @monaco-editor/react, then sending the editor contents to server-side API routes that call the Deno Deploy Subhosting API. One route creates a uniquely named project, one creates a deployment from the submitted code, and one fetches deployment status. The client polls that status until it leaves 'pending' and, on success, loads the deployment URL in an iframe. Isolation of the untrusted code is handed off to Subhosting rather than implemented in the app. Suggested next steps include persisting projects, adding a filesystem and adding authentication.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [React](https://swe.quest/tags/react.md) (Web & mobile)
- [Sandboxing & isolation](https://swe.quest/tags/sandboxing.md) (Security)
- [Serverless](https://swe.quest/tags/serverless.md) (Backend & APIs)
- [Frontend](https://swe.quest/tags/frontend.md) (Web & mobile)
- [JavaScript](https://swe.quest/tags/javascript.md) (Languages)

## Prerequisites

- React hooks ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- Next.js App Router ([easy posts on React](https://swe.quest/tags/react.md?difficulty=easy))
- REST API routes ([easy posts on API design](https://swe.quest/tags/api-design.md?difficulty=easy))

## Keywords

Monaco, Next.js, Deno Deploy, Subhosting, @monaco-editor/react

## Related posts

- [Build Your Own Cloud IDE with the Subhosting API](https://swe.quest/articles/build-your-own-cloud-ide-with-the-subhosting-api-182e8468c60d1771.md): Deno · 2024-01-16 · Medium · 10 min read · Serverless, TypeScript, Developer tools, API design
  A cloud IDE can be built on the Deno Subhosting API, which programmatically deploys user code to Deno Deploy's global V8 isolate cloud within seconds.
- [Use One-Click Deploys for Secure Online VS Code](https://swe.quest/articles/use-one-click-deploys-for-secure-online-vs-code-7d82fbb266e3409d.md): Render · 2021-11-18 · Medium · 6 min read · Infrastructure as code, Deployment, Developer tools, Cloud platforms
  OpenVSCode Server can be deployed on Render by forking Gitpod's repo, adding a minimal Dockerfile that pulls the published image, and defining a persistent disk mount in a render.yaml Blueprint.
- [A Whole Website in a Single JavaScript File](https://swe.quest/articles/a-whole-website-in-a-single-javascript-file-71d46431d0988f5b.md): Deno · 2022-04-05 · Medium · 2 min read · JavaScript, Serverless, CDN & edge, Frontend, TypeScript
  A demo multi-page website fits entirely in one JavaScript file and is server-rendered on demand at the edge with Deno.
- [You Don't Need a Build Step](https://swe.quest/articles/you-don-t-need-a-build-step-dd1afe17f034274b.md): Deno · 2023-03-01 · Medium · 13 min read · Build systems, JavaScript, Frontend, Web performance
  Modern JavaScript build steps exist largely because Node's server-side JavaScript diverged from browser JavaScript, forcing compilation, minification, bundling and code-splitting before code can run in the browser.
- [Build and Ship Astro Sites with Deno and Deno Deploy](https://swe.quest/articles/build-and-ship-astro-sites-with-deno-and-deno-deploy-3be8936cebaf2b24.md): Deno · 2023-07-21 · Medium · 12 min read · Frontend, Serverless, Deployment, TypeScript
  Astro sites can be built with the Deno runtime and hosted on Deno Deploy in two modes.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
