File size: 2,033 Bytes
b6145fb
 
 
 
 
 
 
 
 
 
 
 
 
 
5b1a5a3
 
 
 
19499ad
 
 
 
 
b6145fb
 
19499ad
b6145fb
 
 
 
5b1a5a3
 
b6145fb
 
df58e57
 
 
 
 
5b1a5a3
 
0c96373
5b1a5a3
 
df58e57
b6145fb
 
5b1a5a3
b6145fb
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Codex-as-API on a Hugging Face Docker Space.
# Wraps the OpenAI Codex CLI (authed via your ChatGPT login) behind an
# OpenAI-compatible HTTP API. Auth + sessions persist in the /data bucket.

FROM node:20-bookworm-slim

# Python (for the FastAPI wrapper) + git (Codex expects a git context) + ca-certs.
RUN apt-get update && apt-get install -y --no-install-recommends \
        python3 python3-pip python3-venv git ca-certificates tini \
    && rm -rf /var/lib/apt/lists/*

# Install the Codex CLI globally.
RUN npm install -g @openai/codex && codex --version

# HF Spaces run as uid 1000. The node base image already ships a `node` user at
# uid 1000, so reuse it instead of creating a duplicate.
ENV HOME=/home/node \
    PATH=/home/node/.local/bin:$PATH \
    # CODEX_HOME on FAST LOCAL disk (Codex's SQLite I/O on a network bucket is the
    # main latency killer). Use /tmp — always writable on HF Spaces regardless of
    # the runtime user. auth.json is seeded from / synced back to the bucket.
    CODEX_HOME=/tmp/.codex \
    AUTH_PERSIST_DIR=/data/.codex \
    # Defaults (override via Space variables/secrets).
    CODEX_SANDBOX=workspace-write \
    CODEX_EFFORT=low \
    PORT=7860

WORKDIR /app

# Python deps (installed system-wide so the node user can run uvicorn).
COPY --chown=node requirements.txt /app/requirements.txt
RUN pip3 install --no-cache-dir --break-system-packages -r /app/requirements.txt

# Data-analysis libraries available to the agent's Python (headless plotting).
RUN pip3 install --no-cache-dir --break-system-packages \
        pandas numpy matplotlib scikit-learn
ENV MPLBACKEND=Agg

COPY --chown=node app.py /app/app.py
COPY --chown=node codex_engine.py /app/codex_engine.py
COPY --chown=node codex_pool.py /app/codex_pool.py
COPY --chown=node start.sh /app/start.sh
COPY --chown=node AGENTS.global.md /app/AGENTS.global.md
COPY --chown=node global_system.md /app/global_system.md
RUN chmod +x /app/start.sh

USER node
EXPOSE 7860

ENTRYPOINT ["/usr/bin/tini", "--"]
CMD ["/app/start.sh"]