Skip to content

Commit 5eb2997

Browse files
feat: Add base image details and Python version management guide (#1114)
## Summary This PR updates the sandbox documentation to address customer support requests about Python version compatibility, specifically for packages like `argis==2.4.0` that require Python 3.12. ## Changes Made ### Base Image Documentation - Added comprehensive "Base Image" section with complete Dockerfile - Documented the Python 3.13 default environment - Listed all available tools and package managers (uv, npm, yarn, pnpm, etc.) - Included Node.js 22.14.0 and essential development tools ### Python Version Management - Added "Working with Different Python Versions" section - Documented three approaches: 1. **pyenv** for multiple Python versions 2. **uv** package manager for version management 3. **Virtual environment best practices** ### Setup Command Examples - Added practical examples for Python version setup - Included commands for creating virtual environments with specific Python versions - Added warnings about activating virtual environments in setup commands ## Customer Impact This directly addresses the support channel question about forcing Python 3.12 for dependencies that aren't compatible with Python 3.13. Users can now: - Understand what's included in the base sandbox image - Set up Python 3.12 environments for compatibility - Use proper virtual environment practices - Configure setup commands for their specific Python version needs ## Related - Addresses customer support request from Slack thread - Follows repo rules for `.mdx` format in `docs/` directory - Updates `docs/sandboxes/setup-commands.mdx` as requested --- [💻 View my work](https://codegen.sh/agent/trace/27229) • [About Codegen](https://codegen.com) --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: KopekC <[email protected]>
1 parent 7bd1f04 commit 5eb2997

File tree

3 files changed

+202
-2
lines changed

3 files changed

+202
-2
lines changed

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"pages": [
4141
"sandboxes/overview",
4242
"sandboxes/setup-commands",
43+
"sandboxes/base-image",
4344
"sandboxes/editor",
4445
"sandboxes/environment-variables",
4546
"sandboxes/web-preview"

docs/sandboxes/base-image.mdx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: "Base Image"
3+
sidebarTitle: "Base Image"
4+
icon: "docker"
5+
---
6+
7+
Codegen sandboxes are built on a custom Docker image that provides a comprehensive development environment. The base image includes:
8+
9+
- **Python 3.13** (via `ghcr.io/astral-sh/uv:python3.13-bookworm`)
10+
- **Node.js 22.14.0** (managed via NVM)
11+
- **Essential development tools**: git, curl, ripgrep, fd-find, gh (GitHub CLI)
12+
- **Package managers**: uv, npm, yarn, pnpm
13+
- **Editors**: nano, vim
14+
- **System utilities**: tmux, supervisor, nginx
15+
16+
## Dockerfile
17+
18+
```dockerfile
19+
ARG TARGETPLATFORM=linux/amd64
20+
FROM --platform=$TARGETPLATFORM ghcr.io/astral-sh/uv:python3.13-bookworm
21+
22+
# Set environment variables to prevent interactive prompts during installation
23+
ENV NVM_DIR=/usr/local/nvm \
24+
NODE_VERSION=22.14.0 \
25+
DEBIAN_FRONTEND=noninteractive \
26+
NODE_OPTIONS="--max-old-space-size=8192" \
27+
PYTHONUNBUFFERED=1 \
28+
COREPACK_ENABLE_DOWNLOAD_PROMPT=0 \
29+
PYTHONPATH="/usr/local/lib/python3.13/site-packages" \
30+
IS_SANDBOX=True
31+
32+
ENV PATH=$NVM_DIR/versions/node/$NODE_VERSION/bin:/usr/local/nvm:/usr/local/bin:$PATH
33+
34+
ARG INVALIDATE_FILES_LAYER=1
35+
# Copy configuration files and set permissions
36+
COPY sshd_config /etc/ssh/sshd_config
37+
COPY ssh_config /etc/ssh/ssh_config
38+
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
39+
COPY start.sh /usr/local/bin/start.sh
40+
COPY setup_ssh_user.sh /usr/local/bin/setup_ssh_user.sh
41+
COPY setup_ssh_keys.sh /usr/local/bin/setup_ssh_keys.sh
42+
COPY nginx.conf /etc/nginx/nginx.conf
43+
COPY error.html /usr/share/nginx/html/error.html
44+
COPY tmux_output_script.sh /usr/local/bin/tmux_output_script.sh
45+
46+
# Install dependencies and set up environment in a single layer
47+
RUN apt-get update && apt-get install -y -o Dpkg::Options::="--force-confold" \
48+
git \
49+
curl \
50+
fd-find \
51+
gh \
52+
lsof \
53+
ripgrep \
54+
openssh-server \
55+
nginx-full \
56+
fcgiwrap \
57+
tmux \
58+
nano \
59+
vim \
60+
supervisor \
61+
netcat-openbsd \
62+
&& rm -rf /var/lib/apt/lists/* \
63+
&& mkdir -p -m 755 /etc/apt/keyrings \
64+
&& wget -nv -O- https://cli.github.com/packages/githubcli-archive-keyring.gpg | tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
65+
&& chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
66+
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
67+
# Set up environment variables and save it to /etc/profile.d/nvm.sh
68+
&& echo "export NVM_DIR=\"$NVM_DIR\"" >> /etc/profile.d/nvm.sh \
69+
&& echo "[ -s \"$NVM_DIR/nvm.sh\" ] && \. \"$NVM_DIR/nvm.sh\"" >> /etc/profile.d/nvm.sh \
70+
&& echo "export PATH=\"$NVM_DIR/versions/node/$NODE_VERSION/bin:\$PATH\"" >> /etc/profile.d/nvm.sh \
71+
&& echo "export NVM_BIN=\"$NVM_DIR/versions/node/$NODE_VERSION/bin\"" >> /etc/profile.d/nvm.sh \
72+
&& echo "export NODE_VERSION=\"$NODE_VERSION\"" >> /etc/profile.d/nvm.sh \
73+
&& echo "export NODE_OPTIONS=\"--max-old-space-size=8192\"" >> /etc/profile.d/nvm.sh \
74+
&& echo "export DEBIAN_FRONTEND=noninteractive" >> /etc/profile.d/nvm.sh \
75+
&& echo "export PYTHONUNBUFFERED=1" >> /etc/profile.d/nvm.sh \
76+
&& echo "export COREPACK_ENABLE_DOWNLOAD_PROMPT=0" >> /etc/profile.d/nvm.sh \
77+
&& echo "export PYTHONPATH=\"/usr/local/lib/python3.13/site-packages\"" >> /etc/profile.d/nvm.sh \
78+
&& echo "export IS_SANDBOX=true" >> /etc/profile.d/nvm.sh \
79+
&& echo "export NPM_CONFIG_YES=true" >> /etc/profile.d/nvm.sh \
80+
&& echo "export PIP_NO_INPUT=1" >> /etc/profile.d/nvm.sh \
81+
&& echo "export YARN_ENABLE_IMMUTABLE_INSTALLS=false" >> /etc/profile.d/nvm.sh \
82+
&& chmod +x /etc/profile.d/nvm.sh \
83+
# Run the SSH setup script
84+
&& /usr/local/bin/setup_ssh_user.sh \
85+
# Install nvm, Node.js, and code-server
86+
&& mkdir -p $NVM_DIR \
87+
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash \
88+
&& . $NVM_DIR/nvm.sh \
89+
&& nvm install $NODE_VERSION \
90+
&& nvm use $NODE_VERSION \
91+
&& npm install -g yarn pnpm \
92+
&& corepack enable \
93+
&& corepack prepare yarn@stable --activate \
94+
&& corepack prepare pnpm@latest --activate \
95+
&& curl -fsSL https://raw.githubusercontent.com/coder/code-server/refs/tags/v4.99.1/install.sh | sh \
96+
&& uv tool install uvicorn[standard]
97+
98+
ENTRYPOINT ["/usr/local/bin/start.sh"]
99+
```
100+
101+
## Key Features
102+
103+
### Multi-Language Support
104+
The base image supports both Python and Node.js development out of the box, making it suitable for full-stack applications and polyglot projects.
105+
106+
### Development Tools
107+
Essential development tools are pre-installed, including:
108+
- **Git** for version control
109+
- **GitHub CLI** for GitHub integration
110+
- **ripgrep** and **fd-find** for fast file searching
111+
- **tmux** for terminal multiplexing
112+
- **nginx** for web server capabilities
113+
114+
### Package Managers
115+
Multiple package managers are available:
116+
- **uv** for Python package management
117+
- **npm**, **yarn**, and **pnpm** for Node.js packages
118+
- **corepack** for managing package manager versions
119+
120+
### SSH and Remote Access
121+
The image includes SSH server configuration for remote access and development, with proper user setup and key management.

docs/sandboxes/setup-commands.mdx

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ Codegen lets you configure custom setup commands that run once when initializing
1111
`npm install`
1212
</Tip>
1313

14+
## Base Image
15+
16+
Codegen sandboxes are built on a custom Docker image that provides a comprehensive development environment. For detailed information about the base image, including the complete Dockerfile and available tools, see the [Base Image](/sandboxes/base-image) documentation.
17+
1418
## Accessing Setup Commands
1519

1620
To configure setup commands for a repository:
1721

1822
1. Navigate to [codegen.com/repos](https://codegen.com/repos).
1923
2. Click on the desired repository from the list.
20-
3. You will be taken to the repository's settings page. The setup commands can be found at a URL similar to `https://codegen.com/{your_org}/{repo_name}/settings/setup-commands` (the exact URL structure might vary slightly, look for a "Setup Commands" or "Sandbox Configuration" section).
24+
3. You will be taken to the repository's settings page. The setup commands can be found at a URL similar to `https://www.codegen.com/repos/{arepo_name}/setup-commands`
2125

2226
<Frame caption="Set setup commands at codegen.com/repos">
2327
<img src="/images/setup-commands-ui.png" alt="Setup Commands UI" />
@@ -48,7 +52,11 @@ npm install
4852
```
4953

5054
```bash
51-
# Install Python dependencies
55+
# Setup with specific Python version for compatibility
56+
pyenv install 3.12.0
57+
pyenv local 3.12.0
58+
python -m venv venv
59+
source venv/bin/activate
5260
pip install -r requirements.txt
5361
```
5462

@@ -59,6 +67,75 @@ npm ci
5967
npm run build
6068
```
6169

70+
### Working with Different Python Versions
71+
72+
The sandbox comes with Python 3.13 by default, but some packages may not yet be compatible with this version. Here are strategies for handling different Python versions:
73+
74+
#### Using pyenv for Multiple Python Versions
75+
76+
If you need to work with a different Python version, you can install and use `pyenv`:
77+
78+
```bash
79+
# Install pyenv
80+
curl https://pyenv.run | bash
81+
82+
# Add pyenv to PATH (for current session)
83+
export PATH="$HOME/.pyenv/bin:$PATH"
84+
eval "$(pyenv init -)"
85+
eval "$(pyenv virtualenv-init -)"
86+
87+
# Install Python 3.12 (or your desired version)
88+
pyenv install 3.12.0
89+
90+
# Set Python 3.12 as the local version for your project
91+
pyenv local 3.12.0
92+
93+
# Create a virtual environment with Python 3.12
94+
python -m venv venv
95+
source venv/bin/activate
96+
97+
# Install your dependencies
98+
pip install -r requirements.txt
99+
```
100+
101+
#### Using uv with Specific Python Versions
102+
103+
The `uv` package manager (already installed) can also manage Python versions:
104+
105+
```bash
106+
# Install Python 3.12 and create a virtual environment
107+
uv venv --python=3.12
108+
109+
# Activate the virtual environment
110+
source .venv/bin/activate
111+
112+
# Install dependencies
113+
uv pip install -r requirements.txt --refresh --upgrade
114+
```
115+
116+
#### Virtual Environment Best Practices
117+
118+
When working with packages that require older Python versions:
119+
120+
```bash
121+
# Create a virtual environment with a specific Python version
122+
python3.12 -m venv venv_312
123+
source venv_312/bin/activate
124+
125+
# Verify the Python version
126+
python --version
127+
128+
# Install packages that require Python 3.12
129+
pip install argis==2.4.0 # Example package that needs older Python
130+
131+
# Deactivate when done
132+
deactivate
133+
```
134+
135+
<Warning>
136+
Remember to activate your virtual environment in your setup commands if you need specific Python versions for your project dependencies.
137+
</Warning>
138+
62139
<Note>
63140
Ensure your setup commands are non-interactive and can run to completion
64141
without user input.
@@ -67,3 +144,4 @@ npm run build
67144
The environment variables listed in the "Env Variables" section are available
68145
during the execution of these setup commands.
69146
</Tip>
147+

0 commit comments

Comments
 (0)