diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml index e2cb64d5..0e8aa482 100644 --- a/.github/workflows/sync-upstream.yml +++ b/.github/workflows/sync-upstream.yml @@ -142,12 +142,13 @@ jobs: echo 'it does **not** mean the BU EKS changes still behave correctly.' echo 'Check these before merging:' echo - echo '- `docker/Dockerfile.worker-sandbox` and `docker/start-direct-sandbox.sh` —' - echo ' these are held byte-identical to upstream ON PURPOSE, so BU images never' - echo ' build from them. If this sync changes either one, port the change by hand' - echo ' into `docker/Dockerfile.bu-sandbox` / `docker/start-direct-sandbox-bu.sh`,' - echo ' which is where the `worker-sandbox-kvm`, `worker-sandbox-nokvm` and' - echo ' `sandbox-lambda-microvm` stages and the aarch64 library-path handling live.' + echo '- `api/Dockerfile` — the `lambda-microvm-runner` target is the image AWS' + echo ' Lambda boots, and its `package-builder` stage is where BU adds R. A sync' + echo ' that touches the R toolchain apt list, `COPY r-packages.txt` or the' + echo ' `which.debianutils` symlink changes what the sandbox can run.' + echo ' (BU no longer forks this file: `docker/Dockerfile.bu-sandbox` and its' + echo ' launcher scripts were retired once the MicroVM moved to the upstream' + echo ' target, so there is nothing to port changes into by hand any more.)' echo '- `api/` and `api/config/sandbox.cfg` — NsJail flags and per-execution limits.' echo '- `launcher/entrypoint.sh` — boot-time resolution of the egress forward target.' echo '- `docker/package-init.sh` and `javascript-packages.txt` — runtime versions' diff --git a/docker/Dockerfile.bu-sandbox b/docker/Dockerfile.bu-sandbox deleted file mode 100644 index bbbe34fd..00000000 --- a/docker/Dockerfile.bu-sandbox +++ /dev/null @@ -1,574 +0,0 @@ -# BU Worker-Sandbox Dockerfile. -# -# This is BU's copy of docker/Dockerfile.worker-sandbox and is the source of -# every sandbox image BU publishes to ECR. Two targets are built from it: -# -# --target worker-sandbox-kvm in-cluster sandbox (amd64, libkrun + NsJail) -# --target sandbox-lambda-microvm AWS Lambda MicroVM sandbox (arm64, NsJail) -# -# WHY A COPY EXISTS -# -# docker/Dockerfile.worker-sandbox and docker/start-direct-sandbox.sh are held -# byte-identical to LibreChat-AI/code-interpreter. Both files carry heavy BU -# changes — the aarch64 no-KVM stage, the Fedora/Debian library-path handling, -# the Lambda MicroVM stage — and upstream edits them often, so keeping the BU -# changes in place made every upstream sync and every release build stop on the -# same two conflicts. -# -# Divergence from upstream is now additions only, which git can never conflict -# on: -# docker/Dockerfile.bu-sandbox (this file) -# docker/start-direct-sandbox-bu.sh -# docker/start-direct-sandbox-nokvm.sh -# docker/start-sandbox-lambda-microvm.sh -# .github/workflows/sync-upstream.yml -# -# The trade-off is that upstream improvements to Dockerfile.worker-sandbox no -# longer arrive here for free. When a sync PR touches that file, port the change -# across by hand — a visible, reviewable step instead of a merge conflict in -# code that decides how untrusted code is confined. -# -# Boots the sandbox server inside a libkrun microVM with its own kernel, -# alongside the worker process managed by supervisor.sh. -# Only requires /dev/kvm on the host — no privileged mode, no capabilities. -# -# Architecture within this container: -# ┌──────────────────────────────────────────────────────────────────────────┐ -# │ Worker-Sandbox Container (Fedora 41, libkrun) │ -# │ │ -# │ ┌─────────────────┐ ┌──────────────────────────────────────────┐│ -# │ │ Worker Process │ ──────▶│ libkrun MicroVM (own kernel) ││ -# │ │ (job processor)│ :2000 │ └─ NsJail Sandbox (code execution) ││ -# │ │ Port 3113 │ │ ││ -# │ │ (health) │ │ ││ -# │ └─────────────────┘ └──────────────────────────────────────────┘│ -# └──────────────────────────────────────────────────────────────────────────┘ -# -# Scale this as a unit - PYTHON_CONCURRENCY = sandbox capacity - -# ============================================================================ -# Stage 1: Build NsJail from source -# ============================================================================ -FROM buildpack-deps:bookworm AS nsjail-builder - -WORKDIR /nsjail - -COPY docker/apt-install.sh /usr/local/bin/apt-install -RUN chmod +x /usr/local/bin/apt-install - -RUN apt-install \ - bison \ - flex \ - libprotobuf-dev \ - libnl-route-3-dev \ - protobuf-compiler \ - pkg-config - -RUN git clone -b master --single-branch https://github.com/google/nsjail.git . \ - && git checkout 66ad78dc361721512fbf9470488e584364c75489 \ - && git submodule update --init --recursive - -COPY docker/nsjail-anonymous-control.patch /tmp/nsjail-anonymous-control.patch -# Upstream hardening, carried over verbatim from docker/Dockerfile.worker-sandbox. -# The patch replaces NsJail's parent/child control socketpair with anonymous -# pipes and makes runChild() refuse the descriptor-passing modes outright -# (seccomp_unotify, user-mode networking). NL3_EXISTS=no drops the libnl -# transport: network-isolated jobs never need it, and removing it keeps sendmsg -# out of the supervisor and fails closed for interface/traffic-rule -# configuration. The NsJail commit pinned above is the same one upstream pins, -# so the patch applies cleanly. -RUN git apply /tmp/nsjail-anonymous-control.patch && make -j$(nproc) NL3_EXISTS=no - -# api/src/entrypoint.sh — the start target for every sandbox stage below — runs -# the NsJail smoke test through sandbox-supervisor-policy and then execs the API -# through it as well, and exports SANDBOX_PIPE_ADDON pointing at -# anonymous-pipes.node. The bundle resolves tool-call-pipe-bridge at run time. -# All three arrived upstream after this file was forked at v1.6.7; without them -# the sandbox dies at startup with "FATAL: NsJail smoke test failed". -COPY api/src/spec-guard.c /tmp/spec-guard.c -COPY api/src/tool-call-pipe-bridge.c /tmp/tool-call-pipe-bridge.c -COPY api/src/anonymous-pipes.c /tmp/anonymous-pipes.c -COPY api/src/supervisor-policy.c /tmp/supervisor-policy.c -COPY --from=node:22.23.4-slim /usr/local/include/node /usr/local/include/node -RUN gcc -shared -fPIC -O2 -Wall -Wextra -Werror -I/usr/local/include/node -o /usr/local/lib/anonymous-pipes.node /tmp/anonymous-pipes.c \ - && gcc -O2 -static -Wall -Wextra -Werror -o /usr/local/bin/sandbox-supervisor-policy /tmp/supervisor-policy.c \ - && gcc -O2 -static -Wall -Wextra -Werror -o /usr/local/bin/tool-call-pipe-bridge /tmp/tool-call-pipe-bridge.c \ - && gcc -O2 -static -o /usr/local/bin/spec-guard /tmp/spec-guard.c \ - && chmod 0111 /usr/local/bin/spec-guard - -# ============================================================================ -# Stage 2: Build worker -# ============================================================================ -FROM oven/bun:1.4.4 AS worker-builder -WORKDIR /app -COPY service/package.json service/bun.lock ./ -# service/package.json declares patchedDependencies (deepmerge, minio), and -# --frozen-lockfile refuses to install without the patch files the lockfile -# records. Upstream copies these for the same reason; api/package.json declares -# none, which is why only this stage needs them. -COPY service/patches ./patches -RUN bun install --frozen-lockfile -COPY service/src ./src -COPY shared /shared -# service/src reaches outside its own tree twice: `../../shared/...` and, since -# upstream v1.6.7, `../../packages/code/src/protocol`. -# Upstream's own service/Dockerfile copies the same two paths for the same reason -# — keep this in step with it, or `bun build` fails with "Could not resolve". -COPY packages/code/src /packages/code/src -COPY service/tsconfig.json ./ -RUN bun build ./src/worker-server.ts --minify --outdir .build --target bun --external '@opentelemetry/*' - -# ============================================================================ -# Stage 3: Build sandbox API -# ============================================================================ -FROM oven/bun:1.4.4 AS sandbox-builder -WORKDIR /app -COPY api/package.json ./ -RUN bun install --frozen-lockfile -COPY api/src ./src -COPY shared /shared -COPY api/tsconfig.json ./ -# Build sandbox API for Bun, plus the tool-call broker for Node (CJS). The -# broker must run under Node, not Bun: Bun's node:http compat layer never fires -# 'connection' events, which silently disables the broker's DoS protections. -# -# Delegate to api/package.json's "build" script rather than inlining the -# commands. This file is a fork of api/Dockerfile, and the inlined form pinned -# the v1.6.7 entry point name: upstream renamed -# src/tool-call-socket-proxy.ts to src/tool-call-pipe-broker.ts, and the merge -# to v1.11.0 broke the build with "ModuleNotFound". Upstream runs -# `bun run build` here for the same reason, so the command now has one -# definition that moves with the code. -RUN bun run build - -# ============================================================================ -# Stage 4: Build sandbox rootfs (full OS layer for the microVM guest) -# ============================================================================ -FROM oven/bun:1.4.4-debian AS sandbox-rootfs - -ENV DEBIAN_FRONTEND=noninteractive - -COPY docker/apt-install.sh /usr/local/bin/apt-install -RUN chmod +x /usr/local/bin/apt-install - -RUN apt-install \ - coreutils \ - util-linux \ - bsdextrautils \ - locales \ - procps \ - iptables \ - bc \ - jq \ - poppler-utils \ - fonts-dejavu \ - fonts-liberation \ - libnl-route-3-200 \ - libprotobuf32 \ - libffi8 \ - ca-certificates \ - && libffi=$(find /usr/lib -name 'libffi.so.8' -print -quit) \ - && { [ -n "$libffi" ] || { echo "libffi.so.8 not found" >&2; exit 1; }; } \ - && ln -sf "$libffi" "${libffi%.so.8}.so.6" - -# Restore the standard Debian `awk` -> `mawk` symlink. See api/Dockerfile -# for the full rationale; in short, mawk's binary ships in slim base -# images (Priority: required) but its postinst's update-alternatives -# step is skipped, so bare `awk` doesn't resolve. Identical security -# surface to sed/tr/coreutils. -RUN [ -x /usr/bin/mawk ] && ln -sf /usr/bin/mawk /usr/bin/awk - -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen - -COPY --from=nsjail-builder /nsjail/nsjail /usr/sbin/nsjail -COPY --from=nsjail-builder /usr/local/bin/spec-guard /usr/local/bin/spec-guard -# The runtime half of the v1.11.0 pipe/supervisor work compiled in -# nsjail-builder. api/src/entrypoint.sh execs the API through -# sandbox-supervisor-policy and defaults SANDBOX_PIPE_ADDON to this path, so -# all three have to be present or the sandbox refuses to start. -COPY --from=nsjail-builder /usr/local/bin/tool-call-pipe-bridge /usr/local/bin/tool-call-pipe-bridge -COPY --from=nsjail-builder /usr/local/bin/sandbox-supervisor-policy /usr/local/bin/sandbox-supervisor-policy -COPY --from=nsjail-builder /usr/local/lib/anonymous-pipes.node /usr/local/lib/anonymous-pipes.node -ENV SANDBOX_PIPE_ADDON=/usr/local/lib/anonymous-pipes.node -RUN chmod +x /usr/sbin/nsjail - -WORKDIR /sandbox_api - -COPY api/package.json ./ -RUN bun install --frozen-lockfile --production -COPY --from=sandbox-builder /app/.build ./.build -COPY api/config ./config -COPY api/src/entrypoint.sh ./entrypoint.sh -RUN chmod +x ./entrypoint.sh - -RUN mkdir -p /pkgs /tmp/sandbox - -RUN find / -xdev -perm /6000 -exec chmod ug-s {} + 2>/dev/null || true -RUN rm -f /usr/bin/nsenter /usr/bin/unshare /usr/bin/chroot /usr/sbin/chroot \ - /usr/bin/perl* /usr/bin/apt /usr/bin/apt-get /usr/bin/dpkg \ - /usr/local/bin/apt-install \ - /usr/sbin/adduser /usr/sbin/useradd /usr/sbin/usermod \ - /usr/sbin/groupadd /usr/sbin/groupmod \ - /usr/bin/su \ - /usr/bin/chfn /usr/bin/chsh /usr/bin/gpasswd /usr/bin/newgrp \ - /usr/bin/passwd /usr/bin/sg \ - /usr/bin/chage /usr/bin/expiry /usr/sbin/unix_chkpwd \ - 2>/dev/null || true - -# ============================================================================ -# Stage 5: Build the Rust launcher binary (Fedora for libkrun ABI) -# ============================================================================ -FROM fedora:43 AS launcher-builder - -RUN dnf install -y \ - rust cargo \ - libkrun-devel \ - gcc \ - && dnf clean all - -WORKDIR /launcher -COPY launcher/Cargo.toml launcher/build.rs ./ -COPY launcher/src/ ./src/ - -RUN cargo build --release - -# ============================================================================ -# Stage 6: Final combined image (Fedora for libkrun runtime) -# ============================================================================ -FROM fedora:43 AS worker-sandbox-kvm - -RUN dnf install -y --setopt=install_weak_deps=False \ - libkrun \ - socat \ - curl \ - unzip \ - util-linux \ - grep \ - gawk \ - findutils \ - ca-certificates \ - && dnf clean all - -# Install Bun runtime (for the worker process on the host side) -RUN curl -fsSL https://bun.sh/install | bash -ENV PATH="/root/.bun/bin:${PATH}" - -# --- Launcher (runs on host, boots microVM) --- -COPY --from=launcher-builder /launcher/target/release/sandbox-launcher /usr/local/bin/launcher - -# --- Sandbox rootfs (becomes the microVM guest filesystem) --- -COPY --from=sandbox-rootfs / /sandbox-rootfs/ - -RUN sed -i '/^cgroup_mem_swap_max/d' /sandbox-rootfs/sandbox_api/config/sandbox.cfg - -RUN mkdir -p /host-packages - -# --- Launcher entrypoint (DNS resolution + socat relay before VM boot) --- -COPY launcher/entrypoint.sh /usr/local/bin/launcher-entrypoint.sh -# The BU copy, not docker/start-direct-sandbox.sh — that file is kept identical -# to upstream so it never conflicts on a sync. The in-image path is unchanged, -# so docker/supervisor.sh (which BU does not modify) still finds it. -COPY docker/start-direct-sandbox-bu.sh /usr/local/bin/start-direct-sandbox.sh -RUN chmod +x /usr/local/bin/launcher-entrypoint.sh /usr/local/bin/start-direct-sandbox.sh - -# --- Worker --- -WORKDIR /worker -COPY service/package.json service/bun.lock ./ -# service/package.json declares patchedDependencies; --frozen-lockfile needs -# the patch files the lockfile records. Upstream copies these here too. -COPY service/patches ./patches -RUN bun install --frozen-lockfile --production -COPY --from=worker-builder /app/.build ./.build -COPY --from=worker-builder /app/src ./src -COPY --from=worker-builder /app/src/matplotlib.py /app/src/matplotlib-async.py ./ - -# --- Supervisor --- -COPY docker/supervisor.sh /supervisor.sh -RUN chmod +x /supervisor.sh - -WORKDIR / -EXPOSE 2000 3113 - -HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \ - CMD curl -f http://localhost:3113/health || exit 1 - -CMD ["/supervisor.sh"] - -# ============================================================================ -# Stage 7: Final combined image for no-KVM/aarch64 environments (Debian-based) -# -# The Fedora-based Stage 6 uses bind mounts to overlay a Debian rootfs over -# the Fedora base for the no-KVM path. This works on x86_64 because Fedora -# keeps 64-bit libraries in /usr/lib64 (separate from /usr/lib), so binding -# Debian's /usr/lib leaves the Fedora runtime intact. On aarch64 (AWS -# Graviton / EKS), Fedora and Debian BOTH use /usr/lib as the primary library -# directory — binding it replaces the Fedora dynamic linker and all runtime -# libraries, crashing every subsequent Fedora binary. -# -# This stage is a pure Debian image where NsJail, the sandbox API, and the -# worker all live at their native Debian paths. No bind mounts or -# architecture-specific compatibility shims are required. -# -# Build with: docker build --target worker-sandbox-nokvm ... -# ============================================================================ -FROM oven/bun:1.4.4-debian AS worker-sandbox-nokvm - -ENV DEBIAN_FRONTEND=noninteractive - -COPY docker/apt-install.sh /usr/local/bin/apt-install -RUN chmod +x /usr/local/bin/apt-install - -RUN apt-install \ - util-linux \ - procps \ - coreutils \ - curl \ - nodejs \ - ca-certificates \ - libnl-route-3-200 \ - libprotobuf32 \ - libffi8 \ - iptables \ - jq \ - bsdextrautils \ - locales - -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen - -# NsJail binary and spec-guard from builder -COPY --from=nsjail-builder /nsjail/nsjail /usr/sbin/nsjail -COPY --from=nsjail-builder /usr/local/bin/spec-guard /usr/local/bin/spec-guard -# The runtime half of the v1.11.0 pipe/supervisor work compiled in -# nsjail-builder. api/src/entrypoint.sh execs the API through -# sandbox-supervisor-policy and defaults SANDBOX_PIPE_ADDON to this path, so -# all three have to be present or the sandbox refuses to start. -COPY --from=nsjail-builder /usr/local/bin/tool-call-pipe-bridge /usr/local/bin/tool-call-pipe-bridge -COPY --from=nsjail-builder /usr/local/bin/sandbox-supervisor-policy /usr/local/bin/sandbox-supervisor-policy -COPY --from=nsjail-builder /usr/local/lib/anonymous-pipes.node /usr/local/lib/anonymous-pipes.node -ENV SANDBOX_PIPE_ADDON=/usr/local/lib/anonymous-pipes.node -RUN chmod +x /usr/sbin/nsjail /usr/local/bin/spec-guard - -# Node binary for tool-call-socket-proxy.cjs (must run under Node, not Bun) -COPY --from=node:22-slim /usr/local/bin/node /usr/local/bin/node - -# libffi.so.6 -> libffi.so.8 compat symlink (NsJail protobuf dep expects .so.6) -RUN libffi=$(find /usr/lib -name 'libffi.so.8' -print -quit) \ - && { [ -n "$libffi" ] || { echo "libffi.so.8 not found" >&2; exit 1; }; } \ - && ln -sf "$libffi" "${libffi%.so.8}.so.6" - -# Restore awk -> mawk symlink (slim image skips postinst update-alternatives) -RUN [ -x /usr/bin/mawk ] && ln -sf /usr/bin/mawk /usr/bin/awk || true - -# Sandbox API -WORKDIR /sandbox_api -COPY api/package.json ./ -RUN bun install --frozen-lockfile --production -COPY --from=sandbox-builder /app/.build ./.build -COPY api/config ./config -COPY api/src/entrypoint.sh ./entrypoint.sh -RUN chmod +x ./entrypoint.sh - -RUN mkdir -p /pkgs /host-packages /tmp/sandbox - -# Worker -WORKDIR /worker -COPY service/package.json service/bun.lock ./ -# service/package.json declares patchedDependencies; --frozen-lockfile needs -# the patch files the lockfile records. Upstream copies these here too. -COPY service/patches ./patches -RUN bun install --frozen-lockfile --production -COPY --from=worker-builder /app/.build ./.build -COPY --from=worker-builder /app/src ./src -COPY --from=worker-builder /app/src/matplotlib.py /app/src/matplotlib-async.py ./ - -# Startup scripts -COPY docker/supervisor.sh /supervisor.sh -COPY docker/start-direct-sandbox-nokvm.sh /usr/local/bin/start-direct-sandbox.sh -RUN chmod +x /supervisor.sh /usr/local/bin/start-direct-sandbox.sh - -WORKDIR / -EXPOSE 2000 3113 - -HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \ - CMD curl -f http://localhost:3113/health || exit 1 - -CMD ["/supervisor.sh"] - -# ============================================================================ -# Stage 8: Sandbox only, for AWS Lambda MicroVMs (arm64) -# -# Build with: docker build --platform linux/arm64 \ -# --target sandbox-lambda-microvm ... -# -# Three things make this different from Stage 7, and each one is forced by the -# Lambda MicroVM environment rather than chosen: -# -# 1. No worker. The worker keeps running in EKS and reaches this over the -# Lambda endpoint, so bundling it here would just be a second copy. -# -# 2. No libkrun, and none is needed. Lambda MicroVMs are Firecracker guests -# and do not expose nested virtualization, so KVM_ENABLED must be false. -# This is not the weaker "NsJail-only" posture that is unacceptable for -# untrusted code: the hardware VM boundary libkrun was providing is still -# there, it is just the Firecracker MicroVM itself, operated by AWS. NsJail -# still runs inside the guest. The layering is the same; the hypervisor -# changed hands. -# -# 3. Packages are baked in. A MicroVM has no PVC to mount, so the ~3 GB -# runtime tree that package-init writes to the PVC in cluster is built at -# image build time instead. Same script, same versions, same /pkgs path, -# so nothing in the sandbox API changes. -# -# arm64 is not a preference — ARM_64 is the only CpuConfigurations value -# AWS::Lambda::MicrovmImage accepts. -# ============================================================================ -FROM oven/bun:1.4.4-debian AS sandbox-lambda-microvm - -ENV DEBIAN_FRONTEND=noninteractive - -COPY docker/apt-install.sh /usr/local/bin/apt-install -RUN chmod +x /usr/local/bin/apt-install - -# Same runtime set as Stage 7, plus the build toolchain package-init needs to -# compile CPython. The toolchain is removed again at the end of this stage. -RUN apt-install \ - util-linux \ - procps \ - coreutils \ - curl \ - wget \ - unzip \ - nodejs \ - ca-certificates \ - libnl-route-3-200 \ - libprotobuf32 \ - libffi8 \ - iptables \ - jq \ - bc \ - poppler-utils \ - fonts-dejavu \ - fonts-liberation \ - bsdextrautils \ - locales - -RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen - -COPY --from=nsjail-builder /nsjail/nsjail /usr/sbin/nsjail -COPY --from=nsjail-builder /usr/local/bin/spec-guard /usr/local/bin/spec-guard -# The runtime half of the v1.11.0 pipe/supervisor work compiled in -# nsjail-builder. api/src/entrypoint.sh execs the API through -# sandbox-supervisor-policy and defaults SANDBOX_PIPE_ADDON to this path, so -# all three have to be present or the sandbox refuses to start. -COPY --from=nsjail-builder /usr/local/bin/tool-call-pipe-bridge /usr/local/bin/tool-call-pipe-bridge -COPY --from=nsjail-builder /usr/local/bin/sandbox-supervisor-policy /usr/local/bin/sandbox-supervisor-policy -COPY --from=nsjail-builder /usr/local/lib/anonymous-pipes.node /usr/local/lib/anonymous-pipes.node -ENV SANDBOX_PIPE_ADDON=/usr/local/lib/anonymous-pipes.node -RUN chmod +x /usr/sbin/nsjail /usr/local/bin/spec-guard - -# tool-call-socket-proxy.cjs must run under Node, not Bun: Bun's node:http -# compat layer never fires 'connection', which silently disables the proxy's -# DoS protections. -COPY --from=node:22-slim /usr/local/bin/node /usr/local/bin/node - -RUN libffi=$(find /usr/lib -name 'libffi.so.8' -print -quit) \ - && { [ -n "$libffi" ] || { echo "libffi.so.8 not found" >&2; exit 1; }; } \ - && ln -sf "$libffi" "${libffi%.so.8}.so.6" - -RUN [ -x /usr/bin/mawk ] && ln -sf /usr/bin/mawk /usr/bin/awk || true - -# Point /usr/bin/which straight at the binary instead of through -# update-alternatives. See api/Dockerfile for the full rationale; in short, -# Debian ships /usr/bin/which -> /etc/alternatives/which -> -# /usr/bin/which.debianutils, and the jail mounts /usr but not -# /etc/alternatives, so inside the sandbox that chain dangles. R needs it: -# base::Sys.which() has "/usr/bin/which" compiled in at configure time, utils' -# .onLoad calls it, and a broken link takes utils down, then stats with it. -RUN [ -x /usr/bin/which.debianutils ] \ - && ln -sf /usr/bin/which.debianutils /usr/bin/which \ - && [ "$(readlink /usr/bin/which)" = /usr/bin/which.debianutils ] - -# --- Sandbox API --- -WORKDIR /sandbox_api -COPY api/package.json ./ -RUN bun install --frozen-lockfile --production -COPY --from=sandbox-builder /app/.build ./.build -COPY api/config ./config -COPY api/src/entrypoint.sh ./entrypoint.sh -RUN chmod +x ./entrypoint.sh - -# --- Runtime packages, baked in --- -# The build toolchain is installed, used, and purged in one layer so the -# compilers never ship inside an image that runs untrusted code. -# -# "core" builds only the first tier of r-packages.txt, for shorter local -# iteration. Image builds for a deployed environment keep the default. -ARG R_PACKAGE_SET=full -ENV R_PACKAGE_SET=${R_PACKAGE_SET} -COPY docker/package-init.sh /package-init.sh -# package-init.sh resolves "${SCRIPT_DIR}/python-runtime/install.py", so this -# tree has to sit beside the script. Upstream added docker/python-runtime after -# this file was forked at v1.6.7, and without it the Python step dies with -# "can't open file '//python-runtime/install.py'" and exits 2. -COPY docker/python-runtime /python-runtime -COPY javascript-packages.txt /javascript-packages.txt -COPY r-packages.txt /r-packages.txt -# The last two install lines are R's toolchain: CRAN ships no arm64 Linux -# binaries, so every R package in r-packages.txt is compiled here from source. -# cmake is for nloptr, which builds a bundled NLopt (and which lme4 and car -# need); libuv1-dev is for fs, which stopped bundling libuv (and which sass, -# bslib, htmlwidgets and plotly need). -# -# Purging these afterwards is safe for R specifically because package-init.sh's -# "Register R" step runs first and copies every shared object R resolves outside -# /pkgs into /pkgs/r//syslib, with LD_LIBRARY_PATH pointing there. That -# is what lets the compilers and -dev packages leave while R keeps running. -RUN chmod +x /package-init.sh \ - && mkdir -p /pkgs \ - && apt-get update \ - && apt-get install -y --no-install-recommends \ - build-essential libssl-dev libffi-dev libsqlite3-dev \ - zlib1g-dev libbz2-dev libreadline-dev libncurses-dev \ - tk-dev xz-utils libcurl4-openssl-dev libfontconfig1-dev \ - libudunits2-dev libpng-dev libxml2-dev libcairo2-dev \ - libfreetype6-dev \ - gfortran libblas-dev liblapack-dev libicu-dev libpcre2-dev \ - liblzma-dev libjpeg-dev libtiff-dev cmake libuv1-dev \ - && JS_PACKAGE_MANIFEST=/javascript-packages.txt \ - R_PACKAGE_MANIFEST=/r-packages.txt /package-init.sh \ - && test -s /pkgs/.initialized \ - && ls /pkgs/r/*/.package-installed >/dev/null \ - && apt-get purge -y --auto-remove \ - build-essential libssl-dev libffi-dev libsqlite3-dev \ - zlib1g-dev libbz2-dev libreadline-dev libncurses-dev \ - tk-dev libcurl4-openssl-dev libfontconfig1-dev \ - libudunits2-dev libpng-dev libxml2-dev libcairo2-dev \ - libfreetype6-dev \ - gfortran libblas-dev liblapack-dev libicu-dev libpcre2-dev \ - liblzma-dev libjpeg-dev libtiff-dev cmake libuv1-dev \ - && rm -rf /var/lib/apt/lists/* /package-init.sh /javascript-packages.txt \ - /r-packages.txt /python-runtime - -RUN mkdir -p /tmp/sandbox - -# Same hardening Stage 4 applies to the microVM guest rootfs. The guest here -# is the whole image, so it applies to the whole image. -RUN find / -xdev -perm /6000 -exec chmod ug-s {} + 2>/dev/null || true -RUN rm -f /usr/bin/nsenter /usr/bin/unshare /usr/bin/chroot /usr/sbin/chroot \ - /usr/bin/perl* /usr/bin/apt /usr/bin/apt-get /usr/bin/dpkg \ - /usr/local/bin/apt-install \ - /usr/sbin/adduser /usr/sbin/useradd /usr/sbin/usermod \ - /usr/sbin/groupadd /usr/sbin/groupmod \ - /usr/bin/su \ - /usr/bin/chfn /usr/bin/chsh /usr/bin/gpasswd /usr/bin/newgrp \ - /usr/bin/passwd /usr/bin/sg \ - /usr/bin/chage /usr/bin/expiry /usr/sbin/unix_chkpwd \ - 2>/dev/null || true - -COPY docker/start-sandbox-lambda-microvm.sh /usr/local/bin/start-sandbox.sh -RUN chmod +x /usr/local/bin/start-sandbox.sh - -WORKDIR / -EXPOSE 2000 - -CMD ["/usr/local/bin/start-sandbox.sh"] diff --git a/docker/start-direct-sandbox-bu.sh b/docker/start-direct-sandbox-bu.sh deleted file mode 100755 index c7c7902a..00000000 --- a/docker/start-direct-sandbox-bu.sh +++ /dev/null @@ -1,105 +0,0 @@ -#!/bin/bash -# -# BU copy of docker/start-direct-sandbox.sh, installed by -# docker/Dockerfile.bu-sandbox as /usr/local/bin/start-direct-sandbox.sh — the -# same in-image path, so the unmodified docker/supervisor.sh still finds it. -# -# It exists so docker/start-direct-sandbox.sh can stay byte-identical to -# LibreChat-AI/code-interpreter. Upstream edits that file often and BU's changes -# to it are substantial (the Fedora usr-merge library-path handling below), so -# holding them here keeps upstream syncs and release builds conflict-free. See -# the header of docker/Dockerfile.bu-sandbox for the full rationale. - -echo "Starting Sandbox (direct NsJail, no microVM) on port 2000..." - -ROOTFS="${SANDBOX_ROOTFS:-/sandbox-rootfs}" - -mkdir -p /sandbox_api /pkgs - -if mount -o remount,rw /sys/fs/cgroup 2>/dev/null; then - echo "[sandbox] Remounted cgroupfs as rw" -else - echo "[sandbox] WARNING: could not remount cgroupfs rw - NsJail cgroup isolation may fail" -fi - -mkdir -p /sys/fs/cgroup/init -echo "[sandbox] Draining root cgroup ($(wc -w < /sys/fs/cgroup/cgroup.procs 2>/dev/null || echo '?') procs) into init/..." -_root_procs=$(cat /sys/fs/cgroup/cgroup.procs 2>/dev/null || true) -for _pid in $_root_procs; do - echo "$_pid" > /sys/fs/cgroup/init/cgroup.procs 2>/dev/null || true -done -_remaining=$(wc -w < /sys/fs/cgroup/cgroup.procs 2>/dev/null || echo "?") -echo "[sandbox] Root cgroup procs after drain: $_remaining" - -if echo "+memory +pids" > /sys/fs/cgroup/cgroup.subtree_control 2>/dev/null; then - echo "[sandbox] Enabled +memory +pids on root cgroup.subtree_control" -else - echo "[sandbox] WARNING: could not enable controllers on root ($_remaining procs remain)" -fi - -PROC_SUBMOUNTS=$(awk '$5 ~ /^\/proc\/./ {print $5}' /proc/self/mountinfo 2>/dev/null | sort -r) -if [ -n "$PROC_SUBMOUNTS" ]; then - echo "[sandbox] Removing $(echo "$PROC_SUBMOUNTS" | wc -l) /proc submounts for fresh procfs support..." - for mnt in $PROC_SUBMOUNTS; do - umount "$mnt" 2>/dev/null || true - done - REMAINING=$(awk '$5 ~ /^\/proc\/./ {print $5}' /proc/self/mountinfo 2>/dev/null | wc -l) - if [ "$REMAINING" -eq 0 ]; then - echo "[sandbox] All /proc submounts removed" - else - echo "[sandbox] WARNING: $REMAINING /proc submounts remain" - fi -else - echo "[sandbox] No /proc submounts to remove" -fi - -export SANDBOX_ROOTFS="$ROOTFS" - -# On Fedora 43 (usr-merge), /usr/sbin → /usr/bin, so bind-mounting $ROOTFS/usr/sbin -# actually replaces Fedora's /usr/bin with Debian's. All subsequent calls to Debian -# binaries require /lib/x86_64-linux-gnu/ which does not exist via Fedora paths. -# -# Key fact: /usr/lib64 on Fedora x86_64 is a REAL directory (not merged with /usr/lib). -# Fedora binaries link against /usr/lib64/ which none of the bind mounts below touch. -# Copying Fedora's mount and bash to /tmp preserves working Fedora binaries that can -# be called after the Debian rootfs is overlaid. Debian binaries (nsjail, etc.) use -# their own embedded linker (/lib/x86_64-linux-gnu/ld-linux-x86-64.so.2) which knows -# its own multiarch library paths (/usr/lib/x86_64-linux-gnu) without LD_LIBRARY_PATH. -cp "$(command -v mount)" /tmp/.sandbox-mount -chmod +x /tmp/.sandbox-mount -cp "$(command -v bash)" /tmp/.sandbox-bash -chmod +x /tmp/.sandbox-bash - -exec unshare --mount bash -c ' - ROOTFS="${SANDBOX_ROOTFS:-/sandbox-rootfs}" - MOUNT=/tmp/.sandbox-mount - echo "[unshare] starting in new mount namespace, ROOTFS=$ROOTFS" - - "$MOUNT" -o bind,ro "$ROOTFS/usr/sbin" /usr/sbin && echo "[unshare] mounted /usr/sbin" || { echo "FATAL: cannot bind /usr/sbin"; exit 1; } - "$MOUNT" -o bind,ro "$ROOTFS/usr/local" /usr/local && echo "[unshare] mounted /usr/local" || { echo "FATAL: cannot bind /usr/local"; exit 1; } - "$MOUNT" -o bind,ro "$ROOTFS/sandbox_api" /sandbox_api && echo "[unshare] mounted /sandbox_api" || { echo "FATAL: cannot bind /sandbox_api"; exit 1; } - "$MOUNT" -o bind,ro "$ROOTFS/pkgs" /pkgs && echo "[unshare] mounted /pkgs" || { echo "FATAL: cannot bind /pkgs"; exit 1; } - - if [ -d /host-packages ]; then - "$MOUNT" --bind /host-packages /pkgs 2>/dev/null && echo "[unshare] overlaid /host-packages" || \ - echo "WARNING: could not bind /host-packages" - fi - - "$MOUNT" -o bind,ro "$ROOTFS/usr/bin" /usr/bin && echo "[unshare] mounted /usr/bin" || { echo "FATAL: cannot bind /usr/bin"; exit 1; } - "$MOUNT" -o bind,ro "$ROOTFS/usr/lib" /usr/lib && echo "[unshare] mounted /usr/lib" || { echo "FATAL: cannot bind /usr/lib"; exit 1; } - - if [ -d "$ROOTFS/usr/lib64" ] && ! [ -L "$ROOTFS/usr/lib64" ]; then - "$MOUNT" -o bind,ro "$ROOTFS/usr/lib64" /usr/lib64 && echo "[unshare] mounted /usr/lib64" || \ - echo "[sandbox] WARNING: could not bind /usr/lib64" - else - echo "[unshare] skipping /usr/lib64 (not present or is symlink in sandbox-rootfs)" - fi - - export PATH="/root/.bun/bin:$PATH" - - echo "[unshare] bind mounts done — execing /tmp/.sandbox-bash /sandbox_api/entrypoint.sh" - ls -la /tmp/.sandbox-bash /sandbox_api/entrypoint.sh || echo "[unshare] WARN: file(s) missing" - - exec /tmp/.sandbox-bash /sandbox_api/entrypoint.sh - echo "[unshare] FATAL: exec returned (should be unreachable)" -' diff --git a/docker/start-direct-sandbox-nokvm.sh b/docker/start-direct-sandbox-nokvm.sh deleted file mode 100644 index 61769820..00000000 --- a/docker/start-direct-sandbox-nokvm.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash -# Direct sandbox start script for no-KVM environments where the container is -# already Debian-based (worker-sandbox-nokvm stage). No bind mounts or -# architecture-specific chroot tricks are needed — NsJail, the sandbox API, -# and all their libraries are at their correct Debian paths. -# -# This is installed as /usr/local/bin/start-direct-sandbox.sh in the -# worker-sandbox-nokvm Dockerfile stage and invoked by supervisor.sh. - -echo "Starting Sandbox (direct NsJail, no microVM) on port 2000..." - -# Remount cgroupfs rw so we can manipulate cgroups below. -if mount -o remount,rw /sys/fs/cgroup 2>/dev/null; then - echo "[sandbox] Remounted cgroupfs as rw" -else - echo "[sandbox] WARNING: could not remount cgroupfs rw - NsJail cgroup isolation may fail" -fi - -# cgroup v2 delegation: drain all root-cgroup processes into an 'init/' sub-cgroup -# so that subtree_control can be written (the kernel forbids enabling controllers -# on a cgroup that still has member processes). entrypoint.sh then creates a -# 'sandbox_api/' sub-cgroup for NsJail's per-execution isolation. -mkdir -p /sys/fs/cgroup/init -echo "[sandbox] Draining root cgroup ($(wc -w < /sys/fs/cgroup/cgroup.procs 2>/dev/null || echo '?') procs) into init/..." -_root_procs=$(cat /sys/fs/cgroup/cgroup.procs 2>/dev/null || true) -for _pid in $_root_procs; do - echo "$_pid" > /sys/fs/cgroup/init/cgroup.procs 2>/dev/null || true -done -_remaining=$(wc -w < /sys/fs/cgroup/cgroup.procs 2>/dev/null || echo "?") -echo "[sandbox] Root cgroup procs after drain: $_remaining" - -if echo "+memory +pids" > /sys/fs/cgroup/cgroup.subtree_control 2>/dev/null; then - echo "[sandbox] Enabled +memory +pids on root cgroup.subtree_control" -else - echo "[sandbox] WARNING: could not enable controllers on root ($_remaining procs remain)" -fi - -# Remove /proc submounts that Kubernetes/containerd adds. NsJail needs a clean -# /proc to mount fresh procfs inside each sandbox's PID namespace. -PROC_SUBMOUNTS=$(awk '$5 ~ /^\/proc\/./ {print $5}' /proc/self/mountinfo 2>/dev/null | sort -r) -if [ -n "$PROC_SUBMOUNTS" ]; then - echo "[sandbox] Removing $(echo "$PROC_SUBMOUNTS" | wc -l) /proc submounts for fresh procfs support..." - for mnt in $PROC_SUBMOUNTS; do - umount "$mnt" 2>/dev/null || true - done - REMAINING=$(awk '$5 ~ /^\/proc\/./ {print $5}' /proc/self/mountinfo 2>/dev/null | wc -l) - if [ "$REMAINING" -eq 0 ]; then - echo "[sandbox] All /proc submounts removed" - else - echo "[sandbox] WARNING: $REMAINING /proc submounts remain" - fi -else - echo "[sandbox] No /proc submounts to remove" -fi - -# Exec directly into the sandbox API entrypoint — no bind mounts needed because -# NsJail and the sandbox API already live at their correct Debian paths. -exec /sandbox_api/entrypoint.sh diff --git a/docker/start-sandbox-lambda-microvm.sh b/docker/start-sandbox-lambda-microvm.sh deleted file mode 100755 index 4d4a825e..00000000 --- a/docker/start-sandbox-lambda-microvm.sh +++ /dev/null @@ -1,117 +0,0 @@ -#!/bin/bash -# Sandbox entrypoint for AWS Lambda MicroVMs. -# -# Installed as /usr/local/bin/start-sandbox.sh by the sandbox-lambda-microvm -# stage of docker/Dockerfile.worker-sandbox. -# -# This is start-direct-sandbox-nokvm.sh with the container-specific parts -# removed. There is no supervisor and no worker: the worker stays in EKS and -# talks to this over the Lambda MicroVM endpoint, so this process is the whole -# payload and must be PID 1's exec target. -# -# Two things the container version does are unnecessary here: -# -# * Removing /proc submounts. Those are added by containerd; a Firecracker -# guest boots with a clean /proc. The loop below is kept anyway because it -# is a no-op when there is nothing to remove, and skipping it would make -# this script silently wrong if the guest ever gains submounts. -# -# * Bind-mounting a Debian rootfs over a Fedora base. Not applicable — this -# image is Debian all the way down, same as Stage 7. -# -# One thing is genuinely uncertain: whether the guest gives us a writable -# cgroup2 filesystem with delegable controllers. Every cgroup step below is -# therefore best-effort and logged, and the script fails loudly at the end if -# SANDBOX_USE_CGROUPV2 was requested but the controllers are not actually -# available — silently running without memory limits on untrusted code is the -# one outcome worth refusing to start for. - -set -uo pipefail - -echo "[sandbox] Starting sandbox API (NsJail inside a Lambda MicroVM) on port 2000..." - -if mount -o remount,rw /sys/fs/cgroup 2>/dev/null; then - echo "[sandbox] Remounted cgroupfs as rw" -else - echo "[sandbox] cgroupfs not remounted (may already be rw, or not present)" -fi - -# cgroup v2 delegation: the kernel refuses to enable controllers on a cgroup -# that still has member processes, so drain the root cgroup into init/ first. -mkdir -p /sys/fs/cgroup/init 2>/dev/null -_root_procs=$(cat /sys/fs/cgroup/cgroup.procs 2>/dev/null || true) -for _pid in $_root_procs; do - echo "$_pid" > /sys/fs/cgroup/init/cgroup.procs 2>/dev/null || true -done -_remaining=$(wc -w < /sys/fs/cgroup/cgroup.procs 2>/dev/null || echo "?") -echo "[sandbox] Root cgroup procs after drain: $_remaining" - -if echo "+memory +pids" > /sys/fs/cgroup/cgroup.subtree_control 2>/dev/null; then - echo "[sandbox] Enabled +memory +pids on root cgroup.subtree_control" - CGROUP_OK=true -else - echo "[sandbox] WARNING: could not enable controllers on root ($_remaining procs remain)" - CGROUP_OK=false -fi - -# Kubernetes/containerd artifact; a no-op in a Firecracker guest. -PROC_SUBMOUNTS=$(awk '$5 ~ /^\/proc\/./ {print $5}' /proc/self/mountinfo 2>/dev/null | sort -r) -for mnt in $PROC_SUBMOUNTS; do - umount "$mnt" 2>/dev/null || true -done - -# Refuse to run untrusted code without the memory and pid limits we claimed to -# have. If this fires, the MicroVM guest does not delegate cgroup2 the way the -# in-cluster sandbox node does, and SANDBOX_USE_CGROUPV2 must be revisited -# before this image is used — not quietly dropped. -if [ "${SANDBOX_USE_CGROUPV2:-false}" = "true" ] && [ "$CGROUP_OK" != "true" ]; then - echo "[sandbox] FATAL: SANDBOX_USE_CGROUPV2=true but cgroup v2 controllers are unavailable." >&2 - echo "[sandbox] Per-execution memory and pid limits would not be enforced. Refusing to start." >&2 - exit 1 -fi - -# --------------------------------------------------------------------------- -# RLIMIT_NOFILE: raise the HARD limit so nsjail can grant jobs a real budget. -# --------------------------------------------------------------------------- -# The guest boots with a hard limit of 1024. nsjail sets RLIMIT_NOFILE per job -# to SANDBOX_MAX_OPEN_FILES, and raising a hard limit needs CAP_SYS_RESOURCE, -# which nsjail does not have. So SANDBOX_MAX_OPEN_FILES could never exceed -# 1024 -- asking for more failed every execution before any code ran: -# -# containSetLimits():188 util::setrlimit(0, RLIMIT_NOFILE, 2048): -# Operation not permitted -# runChild():551 Launching child process failed -# -# In cluster this never arose: launcher/src/main.rs raises the limit before -# exec, and that launcher is not used on the MicroVM path (KVM_ENABLED=false). -# This restores parity -- the in-cluster sandbox runs at soft 65536 / -# hard 1048576. -# -# PID 1 here is root in the guest and the image declares -# AdditionalOsCapabilities ALL, so CAP_SYS_RESOURCE should be available. It is -# NOT assumed: the raise is best-effort and logged, exactly like the cgroup -# steps above. If it fails the sandbox still starts, because -# SANDBOX_MAX_OPEN_FILES stays at the old value until a separate change raises -# it -- and that change must only land once the log line below confirms the -# new hard limit. Raising both at once would reintroduce the failure above. -# -# The target is clamped to /proc/sys/fs/nr_open, the kernel ceiling a hard -# limit cannot exceed. -HARD_NOFILE_TARGET="${SANDBOX_HARD_NOFILE:-1048576}" -NR_OPEN=$(cat /proc/sys/fs/nr_open 2>/dev/null || echo "") -if [ -n "$NR_OPEN" ] && [ "$HARD_NOFILE_TARGET" -gt "$NR_OPEN" ] 2>/dev/null; then - echo "[sandbox] Clamping RLIMIT_NOFILE target $HARD_NOFILE_TARGET to kernel nr_open $NR_OPEN" - HARD_NOFILE_TARGET="$NR_OPEN" -fi - -NOFILE_SOFT_BEFORE=$(ulimit -Sn 2>/dev/null || echo "?") -NOFILE_HARD_BEFORE=$(ulimit -Hn 2>/dev/null || echo "?") - -if ulimit -n "$HARD_NOFILE_TARGET" 2>/dev/null; then - echo "[sandbox] Raised RLIMIT_NOFILE from ${NOFILE_SOFT_BEFORE}/${NOFILE_HARD_BEFORE} to $(ulimit -Sn)/$(ulimit -Hn)" -else - echo "[sandbox] WARNING: could not raise RLIMIT_NOFILE above ${NOFILE_SOFT_BEFORE}/${NOFILE_HARD_BEFORE}" >&2 - echo "[sandbox] (CAP_SYS_RESOURCE unavailable). SANDBOX_MAX_OPEN_FILES must stay <= ${NOFILE_HARD_BEFORE}." >&2 -fi - -exec /sandbox_api/entrypoint.sh diff --git a/service/src/config.spec.ts b/service/src/config.spec.ts index 97599bb9..20a345bd 100644 --- a/service/src/config.spec.ts +++ b/service/src/config.spec.ts @@ -107,26 +107,26 @@ describe('R language configuration', () => { // .onLoad fails, stats follows, and every R job dies with the unhelpful // "Function not implemented". const root = path.resolve(__dirname, '../..'); - for (const file of ['api/Dockerfile', 'docker/Dockerfile.bu-sandbox']) { - expect(readFileSync(path.join(root, file), 'utf8')) - .toContain('ln -sf /usr/bin/which.debianutils /usr/bin/which'); - } + expect(readFileSync(path.join(root, 'api/Dockerfile'), 'utf8')) + .toContain('ln -sf /usr/bin/which.debianutils /usr/bin/which'); }); - it('bakes R into the BU sandbox image, not only the upstream one', () => { - // docker/Dockerfile.bu-sandbox is a fork of api/Dockerfile and is what - // actually builds the deployed `sandbox` and `sandbox-microvm` images; - // api/Dockerfile builds neither. Patching only the upstream file leaves - // every other R assertion here green while the shipped image has no R at - // all, so assert the fork carries the manifest and the R toolchain too. + it('bakes R into the image Lambda boots', () => { + // api/Dockerfile --target lambda-microvm-runner is what the MicroVM + // artifact pins, and its package-builder stage is where R is compiled. + // This assertion used to point at docker/Dockerfile.bu-sandbox, a fork + // that built the deployed images while api/Dockerfile built neither; the + // fork is gone and api/Dockerfile is now the only path. Without the + // manifest and the toolchain below, every other R assertion here stays + // green while the shipped image has no R at all. const root = path.resolve(__dirname, '../..'); - const fork = readFileSync(path.join(root, 'docker/Dockerfile.bu-sandbox'), 'utf8'); - expect(fork).toContain('COPY r-packages.txt /r-packages.txt'); - expect(fork).toContain('R_PACKAGE_MANIFEST=/r-packages.txt'); + const dockerfile = readFileSync(path.join(root, 'api/Dockerfile'), 'utf8'); + expect(dockerfile).toContain('COPY r-packages.txt /r-packages.txt'); + expect(dockerfile).toContain('lambda-microvm-runner'); // Compiling the manifest from source needs these; without them // install.packages() fails and package-init.sh exits non-zero. for (const pkg of ['gfortran', 'libblas-dev', 'liblapack-dev', 'cmake', 'libuv1-dev']) { - expect(fork).toContain(pkg); + expect(dockerfile).toContain(pkg); } });