Quickstart
Get started with InstaVM in under 5 minutes. InstaVM allows you to spin up virtual machines in under 200ms and execute code securely in isolated environments.
What is InstaVM?
InstaVM is an infrastructure platform designed for rapid VM provisioning and secure code execution. Perfect for:
- 🤖 LLM-generated code execution - Run AI-generated code safely
- 📊 Data visualization - Generate charts and graphs in isolated environments
- 🛠️ Package installation - Install tools like ffmpeg, d3, matplotlib without affecting your system
- ⚡ Real-time processing - Process files and streams with sub-second latency
Get your API Key
- Sign up at InstaVM Dashboard
- Navigate to API Keys section
- Create a new API key
- Copy your API key (starts with
sk_instavm_...)
Installation
- Python
- JavaScript/Node.js
pip install instavm
npm install instavm
Your First VM
- Python
- JavaScript/Node.js
from instavm import InstaVM
# Initialize with your API key - grab yours from the dashboard for free credits
vm = InstaVM('sk_instavm_xxxxxxxxxxxxxxxx')
# Execute code on a virtual machine
result = vm.execute("""
print("Hello from InstaVM! 🚀")
print(f"2 + 2 = {2 + 2}")
""")
print(result)
# Output: {'output': 'Hello from InstaVM! 🚀\n2 + 2 = 4\n', 'execution_time': 0.123}
const { InstaVM } = require('instavm');
// Initialize with your API key
const vm = new InstaVM('api_key');
// Execute code on a virtual machine
vm.execute(`
print("Hello from InstaVM! 🚀");
`).then(result => {
console.log(result);
// Output: { output: 'Hello from InstaVM! 🚀\n', success: true, executionTime: 0.558 }
});
Context Manager (Recommended)
For automatic session cleanup, use context managers:
- Python
- JavaScript/Node.js
from instavm import InstaVM
# Automatic session cleanup - grab your API key from the dashboard for free credits
with InstaVM('your_api_key') as vm:
result = vm.execute("print('Hello from InstaVM!')")
print(result)
# Session automatically closed
const { InstaVM } = require('instavm');
async function example() {
const vm = new InstaVM('your_api_key'); // grab yours from the dashboard for free credits
const result = await vm.execute("print('Hello from InstaVM!')");
console.log(result);
}
example();
Real-world Example: Data Visualization
Here's a complete example of generating a data visualization with matplotlib:
- Python
- JavaScript/Node.js
import os
from instavm import InstaVM
with InstaVM('your_api_key') as vm: # grab yours from the dashboard for free credits
# Install matplotlib and generate a plot
result = vm.execute("""
import subprocess
import sys
# Install matplotlib
subprocess.check_call([sys.executable, "-m", "pip", "install", "matplotlib"])
import matplotlib.pyplot as plt
import numpy as np
# Generate data
x = np.linspace(0, 10, 100)
y = np.sin(x)
# Create plot
plt.figure(figsize=(10, 6))
plt.plot(x, y, 'b-', linewidth=2, label='sin(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Sine Wave Generated on InstaVM')
plt.legend()
plt.grid(True, alpha=0.3)
# Save plot
plt.savefig('sine_wave.png', dpi=150, bbox_inches='tight')
print("Plot saved as sine_wave.png")
""")
print(result)
# Download the sine plot from VM
local_path = "sine_wave_downloaded.png"
download_result = vm.download_file("sine_wave.png", local_path=local_path)
if os.path.exists(local_path):
file_size = os.path.getsize(local_path)
print(f"Successfully downloaded sine_wave.png ({file_size} bytes) to {local_path}")
// InstaVM JavaScript SDK - D3 Visualization Quickstart
// Generate an SVG sine wave using D3.js
const { InstaVM } = require('instavm');
const fs = require('fs');
async function generateD3Visualization() {
const vm = new InstaVM('your_api_key'); // grab yours for free in the dashboard
try {
console.log('Setting up Node.js environment...');
// Install Node.js in the VM
await vm.execute(`%%bash
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - > /dev/null 2>&1
apt-get install -y nodejs > /dev/null 2>&1
echo "Node.js installed"
`, { timeout: 180000 });
console.log('Installing D3 and generating visualization...');
// You can also run Python code here using vm.execute() with Python syntax.
// The VM supports multiple languages - just change the code you pass to execute().
// Install D3 and generate SVG
const result = await vm.execute(`%%bash
# Install D3 dependencies
npm install d3-node canvas --silent
# Create visualization script
cat > generate_svg.js << 'SCRIPT'
const { D3Node } = require('d3-node');
const fs = require('fs');
// Create D3 SVG
const d3n = new D3Node();
const svg = d3n.createSVG(500, 300);
// Generate sine wave data
const data = Array.from({length: 50}, (_, i) => ({
x: i * 10,
y: 150 + Math.sin(i * 0.1) * 100
}));
// Create line path
const d3 = d3n.d3;
const line = d3.line()
.x(d => d.x)
.y(d => d.y);
svg.append('path')
.datum(data)
.attr('fill', 'none')
.attr('stroke', '#6772e5')
.attr('stroke-width', 2)
.attr('d', line);
// Save SVG
const svgString = d3n.svgString();
fs.writeFileSync('sine_wave.svg', svgString);
console.log('SVG Generated:', svgString);
SCRIPT
# Run the script
node generate_svg.js
`);
console.log(result.output);
// Download the SVG
console.log('Downloading visualization...');
const download = await vm.download('sine_wave.svg');
// Save locally
fs.writeFileSync('sine_wave.svg', download.content);
console.log(`✓ Downloaded ${download.size} bytes to sine_wave.svg`);
} catch (error) {
console.error('Error:', error.message);
}
}
generateD3Visualization();