Skip to content
sistemo.io beta
GitHub Docs Quickstart

Examples (Python)

Run AI-generated code

The headline use case: an LLM writes code, you run it in an isolated VM you don't trust.

from sistemo import Sandbox

code = ask_the_llm("write python that computes fibonacci(30)")  # your LLM call

with Sandbox(stack="python") as sb:
    result = sb.run(f"python3 -c {shlex.quote(code)}")
    if result.ok:
        feed_back_to_llm(result.stdout)
    else:
        feed_back_to_llm(f"Error:\n{result.stderr}")

The sandbox doesn't know an AI wrote the code — it just runs it, isolated, then is destroyed.

Install dependencies, then run

with Sandbox(stack="python") as sb:
    sb.run("pip install numpy")
    print(sb.run("python3 -c 'import numpy; print(numpy.__version__)'").stdout)

Write a file, then execute it

script = "print('from a file')"
with Sandbox() as sb:
    sb.run(f"cat > /tmp/run.py <<'EOF'\n{script}\nEOF")
    print(sb.run("python3 /tmp/run.py").stdout)

Inspect the environment

with Sandbox() as sb:
    print(sb.run("uname -a").stdout)
    print(sb.run("cat /etc/os-release").stdout)
    print(sb.run("nproc; free -m").stdout)

Keep the disk after destroy

sb = Sandbox()
sb.run("echo important > /root/state.txt")
sb.close(preserve_storage=True)   # disk kept as a volume for later reuse

Point at a self-hosted server

sb = Sandbox(
    base_url="https://your-own-host:8000",
    api_key="sk_live_your_self_hosted_key",
)

Or set SISTEMO_BASE_URL once in the environment and use Sandbox() unchanged.