Skip to content

CodeBox: state does not persist between run() calls #234

@yingjunwu

Description

@yingjunwu

Description

The documentation claims state persists between run() calls (code-execution.mdx Step 5, core-concepts.mdx). In practice, each run() call starts a fresh Python process — variables and functions defined in a previous run() are not available.

Reproduction

import asyncio
import boxlite

async def main():
    async with boxlite.CodeBox() as codebox:
        await codebox.run("""
import json

def process(data):
    return {k: v * 2 for k, v in data.items()}
""")
        result = await codebox.run("""
output = process({"a": 1, "b": 2, "c": 3})
print(json.dumps(output))
""")
        print(result)

asyncio.run(main())

Expected

Second run() can access process() and json from the first run(). Output: {"a": 2, "b": 4, "c": 6}

Actual

NameError: name 'process' is not defined

Environment

  • boxlite 0.5.10
  • macOS Apple Silicon
  • Python 3.12

Notes

Files written to disk do persist (same VM), but Python-level state (variables, imports, function definitions) does not carry over between run() calls.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions