Skip to content

Quickstart

Terminal window
pip install synapserun

Set your API key as an environment variable:

Terminal window
export SYNAPSE_API_KEY="cell_sk_live_..."
  1. Create a sandbox

    from synapse import Cell
    cell = Cell() # or Cell(api_key="...", template="python3")
  2. Execute code

    result = cell.run("x = 42")
    result = cell.run("print(x * 2)")
    print(result.stdout) # "84"
  3. Work with files

    cell.write_file("hello.txt", "Hello from Synapse!")
    content = cell.read_file("hello.txt")
    print(content) # "Hello from Synapse!"
  4. Run shell commands

    result = cell.command("ls -la /data/")
    print(result.stdout)
  5. Clean up

    cell.kill()

Every execution returns a cryptographic receipt — a SHA-256 hash of the code, result, and timestamp:

result = cell.run("print(2 + 2)")
print(result.receipt)
# {
# "execution_id": "exec_a1b2c3...",
# "code_hash": "sha256:e3b0c44...",
# "result_hash": "sha256:4f3c2b1...",
# "template": "python3",
# "timestamp": 1715702400000
# }

For long-running code, stream stdout/stderr in real-time:

result = cell.run(
"import time\nfor i in range(5):\n print(f'Step {i}')\n time.sleep(1)",
on_stdout=lambda line: print(f"[live] {line}"),
on_stderr=lambda line: print(f"[err] {line}"),
)