forevervm

forevervm

Securely run AI-generated code in stateful sandboxes that run forever.

Stars: 132

Visit
 screenshot

foreverVM is a tool that provides an API for running arbitrary, stateful Python code securely. It revolves around the concepts of machines and instructions, where machines represent stateful Python processes and instructions are Python statements and expressions that can be executed on these machines. Users can interact with machines, run instructions, and receive results. The tool ensures that machines are managed efficiently by automatically swapping them from memory to disk when idle and back when needed, allowing for running REPLs 'forever'. Users can easily get started with foreverVM using the CLI and an API token, and can leverage the SDK for more advanced functionalities.

README:

GitHub Repo stars Chat on Discord

repo version
cli npm
sdk npm

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 [email protected]).

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)

For Tasks:

Click tags to check more tools for each tasks

For Jobs:

Alternative AI tools for forevervm

Similar Open Source Tools

For similar tasks

For similar jobs