{"id":1607,"date":"2024-10-12T13:25:42","date_gmt":"2024-10-12T13:25:42","guid":{"rendered":"https:\/\/algocademy.com\/blog\/stackblitz-revolutionizing-ai-programming-in-the-cloud\/"},"modified":"2026-10-15T10:34:50","modified_gmt":"2026-10-15T10:34:50","slug":"stackblitz-revolutionizing-ai-programming-in-the-cloud","status":"publish","type":"post","link":"https:\/\/algocademy.com\/blog\/stackblitz-revolutionizing-ai-programming-in-the-cloud\/","title":{"rendered":"StackBlitz for AI Programming: What It Can and Can&#8217;t Do"},"content":{"rendered":"<p>StackBlitz is a browser-based editor that runs Node.js inside your browser tab, so you can try JavaScript machine-learning libraries such as TensorFlow.js without installing anything. It is good for small experiments, demos and learning. It is not a place to train large models, and it does not use &#8220;cloud computing power&#8221; the way the older version of this post claimed: the code runs on your own machine, in the browser. This guide shows what that means in practice, with an example that runs.<\/p>\n<h2>What StackBlitz is, and how it runs code<\/h2>\n<p>StackBlitz gives you a VS Code-style editor in the browser, with a file tree, a terminal, npm, and a live preview of your app. The technology underneath is <strong>WebContainers<\/strong>: according to the <a href=\"https:\/\/developer.stackblitz.com\/platform\/api\/webcontainer-api\">StackBlitz docs<\/a>, it is a browser-based runtime for executing Node.js applications and operating-system commands that runs entirely inside the browser tab.<\/p>\n<p>That has three consequences for AI work:<\/p>\n<ul>\n<li><strong>Startup is fast.<\/strong> There is no remote machine to boot, so a project opens in seconds and <code>npm install<\/code> works in the tab.<\/li>\n<li><strong>Your computer does the work.<\/strong> A TensorFlow.js model trains using your CPU, or your GPU through the browser&#8217;s WebGL support. A weak laptop means slow training.<\/li>\n<li><strong>The browser sets the limits.<\/strong> Chromium-based browsers are fully supported, Firefox is listed as alpha and Safari as beta in the <a href=\"https:\/\/webcontainers.io\/guides\/browser-support\">WebContainers browser-support notes<\/a>. Features such as native Node add-ons or arbitrary system tools are not available the way they are on a real server.<\/li>\n<\/ul>\n<p>The free personal plan covers public projects, and StackBlitz&#8217;s pricing page says you need a GitHub account to save work. Paid team plans add private repositories. Check <a href=\"https:\/\/stackblitz.com\/pricing\">the pricing page<\/a> for current terms.<\/p>\n<h2>Two different things people mean by &#8220;AI on StackBlitz&#8221;<\/h2>\n<p><strong>1. Writing AI code in the editor.<\/strong> You install a JavaScript ML library such as TensorFlow.js or Brain.js and run small models in the page. This is what the rest of this post covers.<\/p>\n<p><strong>2. Using Bolt.new.<\/strong> Bolt is StackBlitz&#8217;s AI app builder: you describe an app in chat and it generates, runs and previews a full web app in the browser, with options for hosting and a database. It is a code generator built on the same browser runtime, not a machine-learning environment. Plans, models and limits change often, so read <a href=\"https:\/\/bolt.new\">bolt.new<\/a> for what is available now.<\/p>\n<h2>Example: train a tiny model with TensorFlow.js<\/h2>\n<p>The classic first model is linear regression: learn the rule <code>y = 2x - 1<\/code> from six examples. In StackBlitz, create a new project from a Vite vanilla JavaScript template, open the terminal, and run <code>npm install @tensorflow\/tfjs<\/code>. Pin the version rather than loading a &#8220;latest&#8221; script from a CDN, so the example does not break when the library changes. Then replace the contents of <code>main.js<\/code> with:<\/p>\n<pre><code class=\"language-javascript\">import * as tf from '@tensorflow\/tfjs';\n\nasync function main() {\n  const model = tf.sequential();\n  model.add(tf.layers.dense({ units: 1, inputShape: [1] }));\n  model.compile({ loss: 'meanSquaredError', optimizer: tf.train.sgd(0.01) });\n\n  const xs = tf.tensor2d([-1, 0, 1, 2, 3, 4], [6, 1]);\n  const ys = tf.tensor2d([-3, -1, 1, 3, 5, 7], [6, 1]);\n\n  await model.fit(xs, ys, { epochs: 250, verbose: 0 });\n\n  const prediction = model.predict(tf.tensor2d([10], [1, 1]));\n  console.log(prediction.dataSync()[0].toFixed(2));\n}\n\nmain();\n<\/code><\/pre>\n<p>Run in Node with <code>@tensorflow\/tfjs<\/code> 4.22.0, this code printed <code>18.70<\/code>. (The browser should give a similar value.) The exact number changes from run to run because the weights start random, and it is close to the true answer of 19, not equal to it. More epochs or a different learning rate get you closer. Open the browser console (or the preview&#8217;s console) to see the output.<\/p>\n<p>Two details that trip people up: <code>fit<\/code> returns a promise, so use <code>await<\/code> or <code>.then<\/code> before predicting; and the optimizer needs a sensible learning rate. The string <code>'sgd'<\/code> also works and gave 18.78 in the same test.<\/p>\n<h2>What to build on StackBlitz<\/h2>\n<ul>\n<li><strong>Pre-trained models in a web page.<\/strong> TensorFlow.js has packaged models for image classification, object detection and text, which you load and call from JavaScript. Inference on a single image is light enough for a browser.<\/li>\n<li><strong>Small training demos.<\/strong> Linear regression, a tiny classifier on a few hundred rows, or a visualisation of how a loss curve falls. These make good teaching material because anyone can open the link.<\/li>\n<li><strong>Front ends for models that live elsewhere.<\/strong> Build the UI in StackBlitz and call an API that hosts the heavy model. Note that outbound network access is subject to browser rules such as CORS.<\/li>\n<li><strong>Bug reports and sharing.<\/strong> A reproducible project link is a good way to show a maintainer a problem.<\/li>\n<\/ul>\n<h2>Where it stops<\/h2>\n<ul>\n<li><strong>Large training jobs.<\/strong> There is no managed GPU, and tabs have memory limits. Train big models in a notebook service or on a GPU machine and load the result in the browser.<\/li>\n<li><strong>The Python ML stack.<\/strong> NumPy, PyTorch, scikit-learn and most data-science work live in Python. WebContainers are built around Node.js, so for Python ML use a local setup or a hosted notebook.<\/li>\n<li><strong>Private data.<\/strong> Project files are stored by the service. Do not put customer data or secrets in a public project.<\/li>\n<li><strong>Offline work and browser variation.<\/strong> It needs a supported browser and a connection, and behaviour can differ outside Chromium.<\/li>\n<\/ul>\n<h2>Habits that help<\/h2>\n<ol>\n<li>Pin dependency versions in <code>package.json<\/code>.<\/li>\n<li>Keep models and data small. Downsample first, scale up locally.<\/li>\n<li>Run long work in a Web Worker so the page stays responsive.<\/li>\n<li>Free memory: call <code>tensor.dispose()<\/code> or wrap code in <code>tf.tidy()<\/code> so tensors do not pile up.<\/li>\n<li>Do not copy generated code you cannot explain. An AI builder will happily produce a working demo with a wrong idea inside it.<\/li>\n<\/ol>\n<h2>Where to go next<\/h2>\n<p>If the browser editor appeals to you, compare it with a local setup in <a href=\"https:\/\/algocademy.com\/blog\/mastering-visual-studio-code-a-comprehensive-guide-for-developers\/\">this guide to Visual Studio Code<\/a>, and with AI assistants inside your editor in <a href=\"https:\/\/algocademy.com\/blog\/cline-vs-aidr-vs-continue-comparing-top-ai-coding-assistants\/\">this comparison of Cline, Aider and Continue<\/a>. Machine learning also rests on ordinary programming skill; if that part is shaky, <a href=\"https:\/\/app.algocademy.com\/\">AlgoCademy<\/a> has interactive lessons that build it step by step.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>How to use StackBlitz for AI programming: run TensorFlow.js in the browser, what Bolt.new adds, and the limits that matter. Includes a tested example.<\/p>\n","protected":false},"author":1,"featured_media":1606,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[],"class_list":["post-1607","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-problem-solving"],"_links":{"self":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts\/1607"}],"collection":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/comments?post=1607"}],"version-history":[{"count":1,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts\/1607\/revisions"}],"predecessor-version":[{"id":8736,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/posts\/1607\/revisions\/8736"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/media\/1606"}],"wp:attachment":[{"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/media?parent=1607"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/categories?post=1607"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/algocademy.com\/blog\/wp-json\/wp\/v2\/tags?post=1607"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}