Skills Development Managing WebContainer Resource Limits

Managing WebContainer Resource Limits

v20260423
stackblitz-rate-limits
This guide provides essential knowledge on resource limitations within WebContainer environments (such as memory, CPU, file system size, and process count). It is crucial for developers utilizing the WebContainers API or StackBlitz SDK to understand these constraints. Learn best practices for monitoring memory usage, optimizing mounted file systems by excluding unnecessary assets (like test or documentation folders), and managing dependencies to prevent common issues like Out-Of-Memory (OOM) crashes and slow build times.
Get Skill
428 downloads
Overview

StackBlitz Rate Limits

Overview

WebContainer resource limits: memory, CPU, file system size, process count.

Instructions

Step 1: WebContainer Resource Limits

ResourceLimitNotes
Memory~2GBShared with browser tab
File systemEphemeral, in-memoryLost on page refresh
ProcessesMultiple concurrentEach consumes memory
NetworkHTTP onlyNo raw TCP/UDP sockets
npm packagesMost workNative addons not supported

Step 2: Handle Memory Pressure

// Monitor memory usage inside WebContainer
const proc = await wc.spawn('node', ['-e', `
  setInterval(() => {
    const mem = process.memoryUsage();
    const mbUsed = Math.round(mem.heapUsed / 1024 / 1024);
    if (mbUsed > 500) console.warn('High memory: ' + mbUsed + 'MB');
  }, 5000);
`]);

Step 3: Optimize File System Size

// Mount only essential files -- skip test files, docs, etc.
const productionFiles: FileSystemTree = {
  'package.json': { file: { contents: minimalPackageJson } },
  src: { directory: { /* only source files */ } },
  // Skip: tests/, docs/, .git/, large assets
};
await wc.mount(productionFiles);

Error Handling

IssueCauseSolution
Tab crashesOOMReduce mounted files, fewer deps
Slow npm installLarge depsUse --prefer-offline, fewer packages
Process killedMemory limitMonitor with memoryUsage()

Resources

Next Steps

For security, see stackblitz-security-basics.

Info
Category Development
Name stackblitz-rate-limits
Version v20260423
Size 1.99KB
Updated At 2026-04-28
Language