sandbox.code_interpreter runs notebook-style code in persistent kernel
contexts. Use it when the workload is cells, rich outputs, packages, or
artifacts rather than shell commands.
Execution
| Method | Use |
|---|---|
run_code(code, language="python", context=None, envs=None, timeout=None, on_stdout=None, on_stderr=None, on_result=None, on_artifact=None) | Execute a code cell and collect logs, results, artifacts, and errors. |
install_packages(packages) | Install packages into the code interpreter environment. |
Contexts
| Method | Use |
|---|---|
create_code_context(language="python") | Create a persistent kernel context. |
list_code_contexts() | List contexts. |
restart_code_context(context) | Restart a kernel context. |
interrupt_code_context(context) | Interrupt running code. |
remove_code_context(context) | Delete a context. |
Runs And Artifacts
| Method | Use |
|---|---|
list_runs(...) | Inspect async run records. |
list_artifacts(run_id=None, context_id=None) | List produced artifacts. |
get_artifact(id) | Inspect artifact metadata. |
download_artifact(id) / preview_artifact(id) | Fetch artifact bytes. |
delete_artifact(id) | Delete an artifact. |