docs(code-interpreter): add runtime pip install shell examples#287
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5dd41980a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Address review feedback: - Simplify command to plain 'pip install' (per maintainer request) - Remove broken PYTHON_VERSION variable expansion example - Remove misleading /bin/sh fallback guidance - Update both English and Chinese READMEs
hittyt
left a comment
There was a problem hiding this comment.
Change summary: Add documentation for runtime Python package installation.
While the intent is good, the simplified command documented here is likely to fail in the opensandbox/code-interpreter:v1.0.1 environment for two reasons:
- It doesn't load the managed environment via a login shell, which was specifically requested in #272.
- It misses the PEP 668 related flag required for the Debian-based image.
I recommend reverting to a more robust shell wrapper or explicitly mentioning these requirements.
|
|
||
| You can install packages directly via `sandbox.commands.run(...)`: | ||
|
|
||
| ```python |
There was a problem hiding this comment.
[P1] Environment isolation and PEP 668 issues
In opensandbox/code-interpreter, the runtime environment is managed via /opt/opensandbox/code-interpreter-env.sh, which is sourced in .bashrc. Since sandbox.commands.run executes in a non-interactive shell by default, it will not load this environment, potentially leading to 'command not found' or installing into the wrong Python version (e.g., system python instead of the one specified in PYTHON_VERSION).
Additionally, the base image (Debian 12) enforces PEP 668, requiring --break-system-packages for system-wide installs if not using a virtual environment.
| ```python | |
| execution = await sandbox.commands.run("bash -lc 'python3 -m pip install pandas numpy --break-system-packages'") |
| 可以直接通过 `sandbox.commands.run(...)` 安装依赖: | ||
|
|
||
| ```python | ||
| execution = await sandbox.commands.run("pip install pandas numpy") |
There was a problem hiding this comment.
[P1] 环境隔离与 PEP 668 问题
在 opensandbox/code-interpreter 镜像中,运行时环境通过 /opt/opensandbox/code-interpreter-env.sh 管理(通常在 .bashrc 中加载)。由于 sandbox.commands.run 默认在非交互式 shell 中运行,它不会加载这些环境配置,可能导致找不到命令或安装到了错误的 Python 版本。
此外,底层镜像(Debian 12)强制执行 PEP 668,系统级安装需要 --break-system-packages 参数。
| execution = await sandbox.commands.run("pip install pandas numpy") | |
| execution = await sandbox.commands.run("bash -lc 'python3 -m pip install pandas numpy --break-system-packages'") |
Summary
sandbox.commands.run("bash -lc ...")examples withpython3 -m ensurepipandpython3 -m pipbash(/bin/sh -lc)Why
Issue #272 asks how to run pip installation in
opensandbox/code-interpreter:v1.0.1from SDK code. This PR documents a direct, copy-pasteable workflow.Closes #272
Validation