exec
Execute Sage/Python code in a persistent kernel session and return stdout plus the last expression's repr, enabling stateful computations and manageable long-running jobs.
Instructions
Run Sage/Python in the long-lived kernel: stdout, then the repr of the last expression (or '(no output)'). Code runs on the kernel's main thread, one job at a time, so cysignals Sage code works; state persists per session. timeout_s is NOT a computation limit: on expiry you get the partial output and a job id, and the job keeps running (collect it with poll). timeout_s=0 returns at once. A submitted job waits behind the running one ("[queued: another job is running]"); if that one holds the GIL the submit itself is refused after ~10 s ("[kernel busy ...]", the job was not submitted) -- check status or interrupt, then retry.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Code to execute. | |
| session | No | Namespace to run in. State persists per session between exec calls. | default |
| preparse | No | Apply the Sage preparser (2^10 -> 1024, R.<x> = ...). false runs raw Python (2^10 is XOR). | |
| timeout_s | No | Seconds to wait for the result; 0 = return at once. Never cancels the job. |