ForeverVM
Visit ProjectRun Python safely in a code sandbox via ForeverVM.
Visit ProjectCategory
Tags
what is ForeverVM?
ForeverVM is a secure code execution environment that allows you to run arbitrary, stateful Python code in an isolated sandbox. It provides an API for convenient access, making it ideal for safe code execution and experimentation.
How to use ForeverVM?
Using ForeverVM involves interacting with machines and instructions via the CLI or SDK:
CLI Usage:
- Log in:
npx forevervm login
- Start a REPL session:
npx forevervm repl
- Reconnect to a machine:
npx forevervm repl [machine_name]
- List machines:
npx forevervm machine list
SDK Usage (TypeScript/JavaScript):
- Initialize ForeverVM:
const fvm = new ForeverVM({ token: 'YOUR_API_TOKEN' })
- Connect to a REPL:
const repl = fvm.repl()
- Execute code:
let execResult = await repl.exec('4 + 4') console.log(execResult.result)
- Stream output:
for await (const output of execResult.output) { console.log(output.stream, output.data) }
Key features of ForeverVM?
- Secure Python Execution: Run Python in sandboxed environments.
- Stateful Machines: Machines retain state between executions.
- Memory Management: Automatically swaps idle machines to disk.
- Tag-based Organization: Machines can be tagged for filtering.
- API & CLI Access: Integration-friendly interfaces.
Use cases of ForeverVM?
- Educational Coding Platforms: Safe execution of student-submitted code.
- Function-as-a-Service Workloads: Isolated Python function execution.
- Prototype Development: Securely test Python code in production-like environments.
- Data Science Sandboxes: Isolated execution of exploratory code.
FAQ from ForeverVM?
-
How do I get an API token?
Reach out to paul@jamsocket.com.
-
Can I run persistent processes?
Yes, machines retain state; foreverVM handles memory swapping for idle machines.
-
Is there a memory limit?
Yes, you can specify
memory_mb
when creating a machine (default is unspecified). -
Can I filter machines by tags?
Yes, use the
listMachines
method with tag filters.
foreverVM
repo | version |
---|---|
cli | |
sdk |
foreverVM provides an API for running arbitrary, stateful Python code securely.
The core concepts in foreverVM are machines and instructions.
Machines represent a stateful Python process. You interact with a machine by running instructions (Python statements and expressions) on it, and receiving the results. A machine processes one instruction at a time.
Getting started
You will need an API token (if you need one, reach out to paul@jamsocket.com).
The easiest way to try out foreverVM is using the CLI. First, you will need to log in:
npx forevervm login
Once logged in, you can open a REPL interface with a new machine:
npx forevervm repl
When foreverVM starts your machine, it gives it an ID that you can later use to reconnect to it. You can reconnect to a machine like this:
npx forevervm repl [machine_name]
You can list your machines (in reverse order of creation) like this:
npx forevervm machine list
You don't need to terminate machines -- foreverVM will automatically swap them from memory to disk when they are idle, and then automatically swap them back when needed. This is what allows foreverVM to run repls “forever”.
Using the API
import { ForeverVM } from '@forevervm/sdk'
const token = process.env.FOREVERVM_TOKEN
if (!token) {
throw new Error('FOREVERVM_TOKEN is not set')
}
// Initialize foreverVM
const fvm = new ForeverVM({ token })
// Connect to a new machine.
const repl = fvm.repl()
// Execute some code
let execResult = repl.exec('4 + 4')
// Get the result
console.log('result:', await execResult.result)
// We can also print stdout and stderr
execResult = repl.exec('for i in range(10):\n print(i)')
for await (const output of execResult.output) {
console.log(output.stream, output.data)
}
process.exit(0)
Working with Tags
You can create machines with tags and filter machines by tags:
import { ForeverVM } from '@forevervm/sdk'
const fvm = new ForeverVM({ token: process.env.FOREVERVM_TOKEN })
// Create a machine with tags
const machineResponse = await fvm.createMachine({
tags: {
env: 'production',
owner: 'user123',
project: 'demo'
}
})
// List machines filtered by tags
const productionMachines = await fvm.listMachines({
tags: { env: 'production' }
})
Memory Limits
You can create machines with memory limits by specifying the memory size in megabytes:
// Create a machine with 512MB memory limit
const machineResponse = await fvm.createMachine({
memory_mb: 512,
})