This directory contains comprehensive examples demonstrating how to use the BoxLite Node.js SDK.
If you installed BoxLite via npm:
# Install BoxLite
npm install @boxlite-ai/boxlite
# Run examples directly
node simplebox.js
node codebox.jsIf you're developing BoxLite:
# 1. Build the SDK
cd ../../sdks/node
npm install
npm run build
# 2. Link the package globally
npm link
# 3. Link to examples directory
cd ../../examples/node
npm link boxlite
# 4. Run examples
node simplebox.js# Simple command execution
node simplebox.js
# Python code execution
node codebox.js
# Desktop automation (requires X11)
node computerbox.js
# Browser automation
node browserbox.js
# Interactive terminal session
node interactivebox.jsBasic container usage:
- Creating containers
- Executing commands
- Collecting output
- Handling errors
- Cleanup
Python code execution:
- Running Python code safely
- Installing packages
- Using popular libraries (requests, numpy, etc.)
- Error handling
Desktop automation:
- GUI environment with web access
- Mouse automation (move, click, drag)
- Keyboard automation (type, key combinations)
- Screenshots
- Scrolling
Access the desktop via browser:
- HTTP:
http://localhost:3000 - HTTPS:
https://localhost:3001(self-signed certificate)
Browser automation:
- Starting browsers with remote debugging
- Chrome DevTools Protocol (CDP)
- Integration with Puppeteer/Playwright
Optional: Install Puppeteer for full example:
npm install puppeteer-coreInteractive terminal sessions:
- PTY-based interactive shells
- Real-time I/O forwarding
- Terminal size auto-detection
-
First Run: Image pulls may take time. Subsequent runs are faster.
-
Resource Limits: Adjust
memoryMibandcpusbased on your system:const box = new SimpleBox({ image: 'alpine:latest', memoryMib: 512, // Memory in MiB cpus: 1 // Number of CPU cores });
-
Error Handling: Always use try/finally for cleanup:
const box = new SimpleBox({ image: 'alpine:latest' }); try { await box.exec('echo', 'hello'); } finally { await box.stop(); // Important: cleanup resources }
-
Async Disposal (TypeScript 5.2+):
await using box = new SimpleBox({ image: 'alpine:latest' }); await box.exec('echo', 'hello'); // Automatically cleaned up
"BoxLite native extension not found"
- Run
npm run buildin the parent directory
"Image not found"
- BoxLite will auto-pull images on first use
- Ensure you have internet connectivity
"Permission denied" on Linux
- Check KVM access:
ls -l /dev/kvm - Add user to kvm group:
sudo usermod -aG kvm $USER
- See Node.js SDK README for full API documentation
- Check ../../docs/ for architecture details
- Join our community for support