AI EngineerGuide

How to get preview URL for Upstash Box Sandbox

by Ashik Nesin Ashik Nesin

Upstash Box allows you to execute dynamic code on the fly. It is really useful when running AI generated code securely.

And one interesting thing is that you can expose your server or something that you’ve created using it with it’s preview url feature.

Here is an example on how to run a demo server and get a preview link for it.

import { Box } from "@upstash/box";
const box = await Box.create({
  runtime: "node",
  apiKey: process.env.UPSTASH_BOX_API_KEY,
});

await box.exec.command("npm install express");

await box.files.write({
  path: "server.js",
  content: `
 const express = require("express");
const app = express();
app.get("/", (req,res)=> {
res.send("It works!")
})
app.listen(3000)
  `,
});

const previewUrl = await box.getPreviewUrl(3000);

console.log(previewUrl);

await box.exec.command("node server.js");

2026-03-25-at-23.24.402x.png

2026-03-25-at-23.20.292x.png

Reference

#Upstash-Box

Stay Updated

Get the latest AI engineering insights delivered to your inbox.

No spam. Unsubscribe at any time.