Skip to content

Commit 22cdd3a

Browse files
m-messerclaude
andcommitted
python: ship nsjail so shimmy's --sandbox works
shimmy provides the --sandbox (nsjail) feature and its own runtime image builds nsjail from source into /usr/sbin/nsjail. This base image copies only the shimmy binary (`COPY --from=shimmy /shimmy`), not nsjail or its shared libraries, so any evaluation function that sets SANDBOX_ENABLED=true has shimmy fail at startup (os.Stat("/usr/sbin/nsjail") -> not found). Add a nsjail-builder stage that builds nsjail 3.4 from source on the same python:<ver>-slim-bookworm image used at runtime, so the glibc / libstdc++ / libprotobuf ABIs match (a binary copied from shimmy's ubuntu:24.04 image would link against a newer glibc than bookworm provides). Copy the binary in and install its three runtime libs (libcap2, libnl-route-3-200, libprotobuf32). A build-time `ldd` check fails the build if a lib is missing. nsjail is dormant unless a function opts into --sandbox, so behaviour is unchanged for every existing image consumer. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RYbUtnGroazAj1fNjXQmV7
1 parent 338e326 commit 22cdd3a

1 file changed

Lines changed: 26 additions & 1 deletion

File tree

python/Dockerfile

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,21 @@ RUN apt-get update && apt-get install -y \
1515
curl \
1616
&& rm -rf /var/lib/apt/lists/*
1717

18+
# Build nsjail from source, on the same Debian release as the runtime image so
19+
# the glibc / libstdc++ / libprotobuf ABIs match. shimmy ships the --sandbox
20+
# feature but not the nsjail binary, so without this SANDBOX_ENABLED=true makes
21+
# shimmy fail at startup (missing /usr/sbin/nsjail). Mirrors shimmy's own
22+
# nsjail-builder stage. Dormant unless a function opts into --sandbox.
23+
FROM python:${PYTHON_VERSION}-slim-${DEBIAN_VERSION} AS nsjail-builder
24+
RUN apt-get update && apt-get install -y --no-install-recommends \
25+
autoconf bison flex g++ gcc git libtool make pkg-config \
26+
libcap-dev libnl-route-3-dev libprotobuf-dev protobuf-compiler \
27+
&& rm -rf /var/lib/apt/lists/*
28+
ARG NSJAIL_VERSION=3.4
29+
RUN git clone --branch "${NSJAIL_VERSION}" --recurse-submodules --depth=1 \
30+
https://github.com/google/nsjail.git /nsjail-src \
31+
&& make -C /nsjail-src -j"$(nproc)"
32+
1833
FROM base AS lambda-rie
1934

2035
# Install the AWS Lambda Runtime Interface Emulator
@@ -27,22 +42,32 @@ RUN case $(uname -m) in \
2742

2843
FROM base
2944

30-
# Install git so we can install python packages from git repositories
45+
# git: install python packages from git repositories.
46+
# libcap2 / libnl-route-3-200 / libprotobuf32: nsjail's runtime shared libraries.
3147
RUN apt-get update && apt-get install -y \
3248
git \
49+
libcap2 \
50+
libnl-route-3-200 \
51+
libprotobuf32 \
3352
&& rm -rf /var/lib/apt/lists/*
3453

3554
ENV LOG_FORMAT="production"
3655

3756
# add shimmy
3857
COPY --from=shimmy /shimmy /usr/local/bin/shimmy
3958

59+
# add nsjail (used by shimmy's --sandbox / SANDBOX_ENABLED)
60+
COPY --from=nsjail-builder /nsjail-src/nsjail /usr/sbin/nsjail
61+
4062
# add aws-lambda-rie
4163
COPY --from=lambda-rie /usr/local/bin/aws-lambda-rie /usr/local/bin/aws-lambda-rie
4264

4365
# Copy the entrypoint script
4466
COPY ./entrypoint.sh /entrypoint.sh
4567

68+
# fail the build if nsjail is missing a shared library
69+
RUN ! ldd /usr/sbin/nsjail | grep -q 'not found'
70+
4671
ENTRYPOINT [ "/entrypoint.sh" ]
4772

4873
CMD [ "shimmy" ]

0 commit comments

Comments
 (0)