Skip to content

docs(code-interpreter): add runtime pip install shell examples#287

Merged
ninan-nn merged 2 commits intoalibaba:mainfrom
liuxiaopai-ai:codex/docs-code-interpreter-pip-shell
Mar 2, 2026
Merged

docs(code-interpreter): add runtime pip install shell examples#287
ninan-nn merged 2 commits intoalibaba:mainfrom
liuxiaopai-ai:codex/docs-code-interpreter-pip-shell

Conversation

@liuxiaopai-ai
Copy link
Contributor

Summary

  • add Python Code Interpreter SDK docs for runtime package installation without interactive shell access
  • provide sandbox.commands.run("bash -lc ...") examples with python3 -m ensurepip and python3 -m pip
  • include fallback guidance for images without bash (/bin/sh -lc)
  • update both English and Chinese docs

Why

Issue #272 asks how to run pip installation in opensandbox/code-interpreter:v1.0.1 from SDK code. This PR documents a direct, copy-pasteable workflow.

Closes #272

Validation

  • documentation-only change

@CLAassistant
Copy link

CLAassistant commented Mar 1, 2026

CLA assistant check
All committers have signed the CLA.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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
@Pangjiping Pangjiping added documentation Improvements or additions to documentation component/code-interpreter labels Mar 2, 2026
Copy link
Collaborator

@ninan-nn ninan-nn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ninan-nn ninan-nn merged commit 5299a7b into alibaba:main Mar 2, 2026
12 of 13 checks passed
Copy link
Collaborator

@hittyt hittyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. It doesn't load the managed environment via a login shell, which was specifically requested in #272.
  2. 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
```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")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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 参数。

Suggested change
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'")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/code-interpreter documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opensandbox/code-interpreter:v1.0.1镜像中,执行pip命令需要先进入bash,代码如何进入bash?

5 participants