Code cells
Scholar Lens can run Python to compute a result, check a formula or draw a plot. The code runs in a sandbox: a separate container with no internet and no access to your files. This page explains when code runs and how to run your own.
The server needs the sandbox set up (see Stack services). Without it, answers never run code.
When an answer runs code
If your question needs a calculation, a numeric check or a small demonstration, the answer writes a Python cell and runs it. The answer says where it used the result ("see the computation in the Code section below").
Every cell is written to be read:
- It opens with comments: its Purpose, the part of the Answer it supports, and its Method.
- All imports are in one block at the top. Before the cell runs, Scholar Lens removes unused imports and functions and merges duplicates, in code rather than by asking the model.
- Its output reads as a short report: the inputs, each step of the method, the results with labels, and what they mean for your question.
- Code is shown with Python syntax highlighting, in the coding font you chose in Reading settings.
If the cell fails, the answer reads the error and fixes the code, up to 3 times. The final code and its output become evidence, cited as "Python (sandbox)".
The Space's Running code policy decides what happens:
- Run it (the answer shows the code and its output): the cell runs without asking.
- Ask me first, showing the code: the answer pauses with a card, The answer wants to run this code. You can edit the code, then select Run it or skip it.
- Never run code: the step is skipped.
Equation checks in Academic answers
An Academic answer with equations gets an extra step when the policy is Run it. Scholar Lens writes a SymPy check of the answer's equations, with a numeric example, and runs it. The Steps tab shows the result, for example "3 of 4 equation checks passed", and the cell's output lists each check as "✓ passed" or "✗ failed" with what it tested. The checks' helpers (check, skew, rotation) come from a small module the cell imports, scholarlens_checks, so the cell shows only its own code. A failed check sends the answer back for a revision. An answer whose checks still fail is never above Medium confidence.
Run your own cells
Open the Code tab of the run panel.

- Type Python in the box at the bottom.
- Press Ctrl+Enter, or select Run.
Each chat has its own Python kernel, so variables stay between cells, including cells an answer wrote. Cells are labelled Written by an answer or Typed by you. A cell's menu can Edit, Run again or delete it. Restarting the kernel forgets the variables but keeps the cells and their output.
What a cell can use
- Python 3.13 with NumPy, SciPy, SymPy, Matplotlib, OpenCV, scikit-image, pandas and NetworkX.
- A plot shows under the cell.
- A cell may run for 30 seconds by default. The admin can change this up to the sandbox's own limit of 120 seconds.
- No internet, no access to the server's files, a 1 GB scratch folder that is cleared when the sandbox restarts.
A runaway cell (for example a fork bomb or a memory hog) is stopped without harming other chats. See The code sandbox for how.