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
Iben...
)
Installation
- Python
- JavaScript/Node.js
- Go
pip install instavm
npm install instavm
go get github.com/instavm/instavm-go
Your First VM
- Python
- JavaScript/Node.js
- Go
from instavm import InstaVM
# Initialize with your API key
vm = InstaVM('Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE')
# 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('Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE');
// Execute code on a virtual machine
vm.execute(`
console.log("Hello from InstaVM! 🚀");
console.log(\`2 + 2 = \${2 + 2}\`);
`).then(result => {
console.log(result);
// Output: { output: 'Hello from InstaVM! 🚀\n2 + 2 = 4\n', execution_time: 0.123 }
});
package main
import (
"fmt"
"github.com/instavm/instavm-go"
)
func main() {
// Initialize with your API key
vm := instavm.New("Ibenx6XQetSm8Nvcngy3H18nyAwqKM8RtFDhHUid7aE")
// Execute code on a virtual machine
result, err := vm.Execute(`
fmt.Println("Hello from InstaVM! 🚀")
fmt.Printf("2 + 2 = %d\n", 2+2)
`)
if err != nil {
panic(err)
}
fmt.Println(result)
// Output: {Output: "Hello from InstaVM! 🚀\n2 + 2 = 4\n", ExecutionTime: 0.123}
}
Context Manager (Recommended)
For automatic session cleanup, use context managers:
- Python
- JavaScript/Node.js
- Go
from instavm import InstaVM
# Automatic session cleanup
with InstaVM('your_api_key') as vm:
result = vm.execute("print('Hello from InstaVM!')")
print(result)
# Session automatically closed
const { InstaVM } = require('instavm');
// Using async/await with automatic cleanup
async function example() {
const vm = new InstaVM('your_api_key');
try {
const result = await vm.execute("console.log('Hello from InstaVM!')");
console.log(result);
} finally {
await vm.close();
}
}
package main
import (
"context"
"github.com/instavm/instavm-go"
)
func main() {
ctx := context.Background()
vm := instavm.New("your_api_key")
defer vm.Close() // Automatic cleanup
result, err := vm.Execute(ctx, "fmt.Println(\"Hello from InstaVM!\")")
if err != nil {
panic(err)
}
fmt.Println(result)
}
Real-world Example: Data Visualization
Here's a complete example of generating a data visualization with matplotlib:
- Python
- JavaScript/Node.js
from instavm import InstaVM
with InstaVM('your_api_key') as vm:
# 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)
const InstaVM = require('instavm');
async function generateVisualization() {
const vm = new InstaVM('your_api_key');
try {
// Install D3 and generate SVG visualization
const result = await vm.execute(`
const { execSync } = require('child_process');
// Install D3
execSync('npm install d3-node canvas');
const D3Node = require('d3-node');
// Create SVG visualization
const d3n = new D3Node();
const d3 = d3n.d3;
const svg = d3n.createSVG(500, 300);
// Generate data
const data = Array.from({length: 50}, (_, i) => ({
x: i * 10,
y: 150 + Math.sin(i * 0.1) * 100
}));
// Create line path
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);
console.log('SVG Generated:', d3n.svgString());
`);
console.log(result);
} finally {
await vm.close();
}
}
generateVisualization();