diff --git a/agent/sandbox/README.md b/agent/sandbox/README.md index bbd1e5cb65..409341d990 100644 --- a/agent/sandbox/README.md +++ b/agent/sandbox/README.md @@ -192,6 +192,14 @@ Currently, the following languages are officially supported: Pre-installed packages: `requests`, `numpy`, `pandas`, `matplotlib`. > `matplotlib` uses the `Agg` (non-interactive) backend by default in the sandbox (`MPLBACKEND=Agg`). No display server is available, so always save figures to files (e.g. `fig.savefig("artifacts/chart.png")`) rather than calling `plt.show()`. +> +> Tip: if Chinese text renders as missing boxes/squares in `matplotlib`, install Debian package `fonts-noto-cjk` in your custom image. We do not preinstall it by default to keep the base image smaller. The sandbox base image ships a `matplotlibrc` that already lists common CJK fonts in the `font.sans-serif` fallback chain, so no code-level font configuration is needed — just install the font package and rebuild the image. +> +> Example: +> +> ```dockerfile +> RUN apt-get update && apt-get install -y --no-install-recommends fonts-noto-cjk && rm -rf /var/lib/apt/lists/* +> ``` To add more dependencies, edit: diff --git a/agent/sandbox/sandbox_base_image/python/Dockerfile b/agent/sandbox/sandbox_base_image/python/Dockerfile index 93227055f7..410aad8d15 100644 --- a/agent/sandbox/sandbox_base_image/python/Dockerfile +++ b/agent/sandbox/sandbox_base_image/python/Dockerfile @@ -4,8 +4,10 @@ COPY --from=ghcr.io/astral-sh/uv:0.7.5 /uv /uvx /bin/ ENV UV_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple ENV MPLBACKEND=Agg ENV MPLCONFIGDIR=/tmp/matplotlib +ENV MATPLOTLIBRC=/usr/local/etc/matplotlibrc COPY requirements.txt . +COPY matplotlibrc /usr/local/etc/matplotlibrc RUN grep -rl 'deb.debian.org' /etc/apt/ | xargs sed -i 's|http[s]*://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g' && \ apt-get update && \ diff --git a/agent/sandbox/sandbox_base_image/python/matplotlibrc b/agent/sandbox/sandbox_base_image/python/matplotlibrc new file mode 100644 index 0000000000..fe2a1462b7 --- /dev/null +++ b/agent/sandbox/sandbox_base_image/python/matplotlibrc @@ -0,0 +1,11 @@ +## RAGFlow sandbox – matplotlib defaults +## Only overrides are listed; all other settings use matplotlib built-in defaults. + +# Prefer CJK-capable fonts so Chinese / Japanese / Korean text renders correctly. +# matplotlib silently skips fonts that are not installed, falling back to the +# next entry in the list, so this is safe even without any CJK font package. +font.family: sans-serif +font.sans-serif: Noto Sans CJK SC, Noto Sans CJK TC, Noto Sans CJK JP, Noto Sans CJK KR, Source Han Sans SC, Source Han Sans CN, WenQuanYi Zen Hei, Microsoft YaHei, SimHei, PingFang SC, Heiti SC, STHeiti, Arial Unicode MS, DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif + +# Use ASCII hyphen-minus for the minus sign so it renders correctly with any font. +axes.unicode_minus: False