Evaluating LLM-generated code safely with promptfoo

Run generated code in isolated Docker containers during promptfoo evals so tests verify it works without executing untrusted output on your CI host.

On this page

Why run LLM-generated code in a sandbox during evals

Generated code should be executed inside isolated Docker containers during promptfoo evals so that tests can check whether the code works without running it on the CI host. Consider a team whose promptfoo suite asks a model to write a Python function, then runs that function in the same CI job that builds the company's software. The model may produce code that reads environment variables holding cloud credentials, deletes files in the workspace, opens network connections or simply loops forever. Any of these actions happen on a machine with access to repository tokens and deployment secrets, so the test becomes the attack path. The risk is not hypothetical, because the model's output is shaped by prompts, retrieved documents and user input that the team does not fully control.

Promptfoo publishes a guide to this pattern, Sandboxed code evals, which describes evaluating LLM-generated code in isolated Docker containers to prevent security risks. The core decision is whether your eval needs the generated code to run at all. If the assertion can be satisfied by inspecting the text, such as a regex or an is-json check, a sandbox adds cost without adding protection. If the question is whether the function returns correct results for a set of inputs, execution is required and the sandbox becomes necessary. Confirm the container image, network policy, resource limits and file system mounts with your own security team before the first run.

This approach does not make untrusted code safe in every sense. A container isolates the process from the CI host, but it does not automatically prevent every escape, resource exhaustion or misuse of any credentials you mount into it. Keep secrets out of the container environment, disable outbound network access unless a test needs it, and set time and memory limits. Also check which Docker runtime and host hardening your CI runners use, since a shared runner with a permissive daemon weakens the boundary. Treat the sandbox as one control among several, and record in your evaluation design which risks it addresses and which remain with your team.

When sandboxed code evals are worth the setup

Running generated code in an isolated container adds setup, so it pays off only when a check depends on the code actually running. The cards below cover the situations where that is true and the ones where a string or regex assertion is enough.

Coding assistant output tests

A coding assistant is judged on whether its code compiles, passes unit tests and handles edge cases, not on how it reads. Run the generated function against a test suite inside a container so a failing or malicious snippet cannot touch the CI host. Check that the harness captures stdout, exit codes and timeouts so a hung process fails the case instead of stalling the pipeline.

Sandboxed code evals guide

Text-to-code generation features

When a product turns natural language into scripts, queries or configuration that users run, the risk lies in the behavior of the output. Execute the generated artifact against sample inputs and compare results to an expected outcome. Confirm that the sandbox has no network access and no mounted secrets, because generated code often reaches for both.

Code review and refactoring assistants

A refactoring suggestion can look correct and still change behavior. Run the original and rewritten code against the same inputs and assert that outputs match. Regex checks cannot catch this kind of semantic drift, so this is a case where execution is the only reliable grader.

Format and syntax checks

If the requirement is that output is valid JSON, a specific header or a particular function signature, a regex or is-json assertion is enough and avoids container overhead. Reserve execution for outputs whose correctness cannot be read from their text. Keep this boundary explicit in the suite so reviewers know which assertions need the sandbox.

Agents that run tools and code

Coding agents that write and execute files create a larger attack surface than single completions, including file writes outside the workspace and network calls. Evals for these systems should exercise the tool execution path inside a container with restricted filesystem and network policy. Ask your team which permissions the agent holds before deciding what the eval container may access.

Shared CI runners and multi-team pipelines

When several teams share runners that hold deployment credentials or access to internal networks, executing model output directly on the host widens the blast radius of one bad generation. Isolated containers per eval run keep each team's generated code separate. Confirm with your platform team how runners are provisioned and what credentials they can reach before deciding how much isolation to build.

How the Docker sandbox fits into a promptfoo eval

On a developer laptop, the eval runs from the promptfoo CLI on your machine, and promptfoo calls the model from that same host. The sandbox question is whether generated code runs on that machine with your user's files, SSH keys and environment variables within reach. Routing execution through a Docker container moves that code into a separate filesystem and process space, so a test can exercise the code without reaching into the rest of the workstation. Because developers rerun evals often, the container step also determines how cheap it is to iterate.

  • Runtime requirement: the container runtime must be installed and running on each laptop that executes the eval.
  • Base image: confirm which image the guide uses and how to swap in one that matches your project's language versions.
  • Mounted paths: check whether any host directory is mounted into the container, and mount only what the test needs.
  • Model calls: the provider request still leaves from the host, so the container covers generated code execution, not the model traffic.
  • Resource limits: confirm whether the guide sets CPU, memory and time limits, since a runaway loop slows the whole machine.

Confirm these settings in the guide before copying its configuration into a shared repository.

How a generated code test flows through the sandbox

The flow starts when the promptfoo CLI on the CI host sends a test prompt to the model under test. The generated code comes back to the CLI, which hands it to a Docker container that has no access to the CI host. The container runs the code, returns results, and promptfoo applies assertions to those results. Check that the container boundary is the only path the code can reach, and confirm which files, network routes and credentials the container receives before you trust the run.

Generated code runs in a container outside the CI host trust zone.

Configuration options and when each fits

This table compares the main choices for running generated code in Docker containers during promptfoo evals, with the trade-off between safety and test fidelity for each. Read each row as a setting to decide before the first run. The main takeaway: start with the smallest image, no network and tight limits, then loosen one setting only when a test fails for a reason you can name.

ChoiceWhen it fitsSafety versus fidelity trade-offWhat to confirm
Container image and dependenciesGenerated code needs specific libraries or a fixed toolchain versionLarger images run more tests but add more software the code can reachWhich base images the guide uses and how to set one per eval
Network accessOff for pure logic tests; on only when code must call an API or package indexNetwork on lets generated code send data out of the containerWhether networking is off by default and the setting that enables it
Resource limitsTests with loops, large inputs or heavy computationTight limits stop runaway code but can fail correct, slow solutionsAvailable CPU, memory and process limit settings and their units
TimeoutsEvery eval, to stop infinite loops and hung processesShort timeouts end bad code quickly but may mark slow correct code as failedThe timeout setting, its default, and how an expired run is reported
Language runtimesOne image per language suits suites that test several languagesSeparate images are easier to reason about but add maintenance workWhich runtimes ship in the guide's examples and how versions are pinned
Test input mountingPassing test files and fixtures into the containerRead-only mounts keep test data unchanged; writable mounts let code alter it between runsWhether mounts are read-only by default and how to mark one writable
Container user and filesystemAny CI host, so generated code cannot touch host pathsA non-root user and limited writable paths reduce damage from a bad runThe user the container runs as and which paths are writable

Setting up a sandboxed code eval, step by step

This sequence takes a CI runner from no container setup to a promptfoo eval that executes model-generated code inside a Docker container. It ends with a test that confirms hostile code cannot reach the host, so the team can rely on the eval in its pipeline.

  1. Install and verify Docker on the runner

    The platform or CI team installs Docker Engine on the runner or on a dedicated sandbox host that the pipeline can reach. Confirm that the CI user can start containers without sudo workarounds that would give the job root on the host. Run a throwaway container from a public base image and confirm it exits cleanly. Done means the runner reports a healthy Docker daemon and a test container runs and is removed afterward. Ask your security team whether the runner's Docker access is acceptable under your policy, because access to the Docker socket is itself a privilege.

  2. Build a minimal runtime image

    The engineer who owns the eval builds a small image that contains only the language runtime the generated code needs, plus any test libraries. Leave out credentials, SSH keys, cloud CLIs and build tools that the code under test does not require. Run the container as a non-root user with a fixed working directory. Done means the image starts, runs a one-line script that prints the runtime version, and contains no secret files when you list its filesystem. Record the image digest so the eval always runs the same image.

  3. Install promptfoo and pin its version

    The engineer installs promptfoo on the CI image with Node.js 22.22.0 or newer, which is the minimum the npm package requires. Pin the exact promptfoo version in the lockfile or pipeline configuration so results stay comparable between runs. The npm package for the 0.124.1 release was published on 8 October 2026, and you should choose the version your team has tested. Done means the pinned version prints from the command line and the same version runs in CI as on the developer's machine.

  4. Configure promptfoo to execute code in the container

    The engineer follows the promptfoo sandboxed code evals guide to point code execution at the Docker image. Set the container options the guide documents for the runtime, such as the image reference, network access, filesystem mode and resource limits. Confirm each option name against the current guide, since names can change between releases. Done means a dry run completes and docker ps or the container logs show the generated code running inside the container, not on the host.

  5. Write a small test with a code-running assertion

    The eval author writes a prompt that asks the model for a short function, along with a test case that supplies known inputs and expected outputs. Use a code-running assertion so promptfoo executes the returned code in the container and compares the result. Keep the first suite to a few cases with clear expected values. Done means one correct reference implementation passes and one deliberately wrong implementation fails, which shows the assertion can detect faulty code.

  6. Test that a hostile snippet cannot reach the host

    The security engineer writes an illustrative malicious test that tries to read a marker file placed on the host, write to a mounted path, and open an outbound connection. Run it through the same eval configuration. Done means the snippet fails inside the container, the host marker file is unchanged, no write appears on the host, and the outbound attempt is blocked or logged. Keep this test in the suite so every change to the image or configuration is checked against it. If any attempt succeeds, stop and fix the container options before the eval runs in CI.

  7. Add the sandboxed eval to the pipeline

    The CI engineer adds the eval job to the pipeline, scheduled on the sandbox runner with the pinned image and promptfoo version. Store any model API keys as protected pipeline variables, and make sure the code-execution container does not receive them. Done means a pipeline run executes the eval, the hostile-snippet test still fails safely, and the job log shows the same results as a local run. Ask your vendor or internal platform team to confirm how the runner is isolated from other workloads.

Security and operational considerations

Docker isolation lowers the risk of running generated code, but it does not remove that risk. The cards below cover the places where a container can still fail, from escape paths and secrets to network reach, image trust, resource limits and logs. Confirm each hardening choice with your security team before the eval runs against real models or real repositories.

Container escape risk

Generated code is untrusted input, so assume it will try to break out of its container. Isolation depends on the container runtime, the kernel and any privileges you grant. Avoid running eval containers as root or in privileged mode, and drop Linux capabilities the tests do not need. Ask the security team whether a stronger runtime or a dedicated build host is required for your CI runners.

Secrets kept out of the container

Model API keys and repository tokens should never be passed into the container where generated code runs. Generated code can print environment variables or read mounted files. Pass only the inputs each test needs, and keep provider credentials in the promptfoo process that calls the model, outside the sandbox.

Network egress

Generated code that makes outbound calls can exfiltrate data, download payloads or reach internal services. Run eval containers on a network with no route to internal systems, and allow egress only where a test truly needs it. Confirm the allowed destinations with your network team, and test that the block is actually enforced.

Image provenance and updates

The sandbox image is part of your trusted computing base. Build it from a pinned base image, record where each layer came from, and rebuild on a schedule so known vulnerabilities are patched. Store the image in a registry your organization controls, and limit who can push new tags.

Resource exhaustion

Generated code can loop forever, allocate large amounts of memory or fork many processes, which slows the CI host and can hide real failures. Set CPU, memory, process count and wall-clock timeouts on each container, and treat a timeout as a failed test rather than a retry. Agree these limits with the team that owns the CI capacity.

Log handling for generated code

Eval logs can capture generated code, its output and sometimes sensitive prompt data. Decide what is written to logs and how long it is kept, and review whether logs are shared with people outside the team. Confirm with your security and privacy teams how eval artifacts are stored, who can read them, and when they are deleted.

Sandboxed code evals guide

What buyers ask before running sandboxed code evals

What drives the effort and cost of sandboxed code evals?

The main drivers are how many languages and runtimes the generated code uses, how many test cases need to execute code, and how much of the sandbox must be built from your own images and dependencies. Each container image that has to match your language versions, libraries and internal packages adds design and testing work. Cost also rises with the number of CI runners that must run Docker safely and with the amount of review your security team needs before the setup is approved. Ask for a quote that separates the one-time design and build from any recurring maintenance of images and eval suites.

How long does a sandboxed code eval setup usually take?

Duration depends on the scope agreed in writing before work starts, not on a fixed template. The biggest timing factors are the number of runtimes, whether your CI system already runs Docker on isolated hosts, and how long your security and platform teams take to review the container configuration. Work that needs new runner hosts or network policy changes will take longer than changes to an existing pipeline. Ask for milestones tied to specific deliverables so you can see where time is spent.

What does our team need to provide for the engagement?

You will need to provide access to the CI system, the eval repository, the models and applications under test, and a named contact who can approve container images and network rules. Your platform team should confirm which Docker host or runner pool is allowed to execute generated code and what outbound network access it may have. Your security team should state which data may appear in test inputs and logs. Missing decisions on these points are the most common reason a setup stalls.

Can our own engineers build sandboxed code evals without a partner?

Yes, if your team already runs Docker in CI and has someone who can write promptfoo configurations and review container isolation. The work is mostly configuration, image maintenance and verification that generated code cannot reach the CI host or sensitive networks. A partner is typically worth considering when the team lacks container security experience, needs independent review of the isolation before approval, or must cover many runtimes at once. Confirm your own skills against the scope before deciding.

Is promptfoo free to use for sandboxed code evals?

The promptfoo software is licensed under the MIT license, so you can use and modify it without a license fee. The Community edition is free and includes all LLM evaluation features and all model providers and integrations. Enterprise and On-Premise editions add team sharing, SSO, access control and dedicated support at custom pricing. Sandboxed code evals run through the open-source CLI, so they do not require an Enterprise plan. Confirm the current license terms in the promptfoo repository before you rely on them for a commercial rollout.

What recurring costs should we expect after the setup is live?

Recurring work includes rebuilding container images when runtimes or libraries are updated, updating promptfoo to new releases, reviewing new test cases and keeping runner hosts patched. Promptfoo 0.124.1 was published on 8 October 2026 and requires Node.js 22.22.0 or newer, so Node version changes will affect your images. Ask any partner to state whether ongoing upgrades and continuous testing are covered by a retainer or billed separately.

Does sandboxing guarantee that generated code is safe to run?

No setup can guarantee that. A container reduces the blast radius by limiting filesystem, network and host access, but its safety depends on the image, the runtime configuration and the network policy around it. Ask for a written test of the isolation, including attempts to reach the CI host, credentials and internal services from inside the container. Treat the sandbox as one control among several, and review its settings whenever the eval suite or runner changes.

Limits and what to confirm in your environment

The sandboxed approach depends on details that change between promptfoo releases and between CI platforms. The cards below list what to verify before you commit to a design, and who on your side should answer each question.

Node.js and promptfoo versions

The current npm release of promptfoo requires a minimum Node.js version, and the sandboxed eval setup may add its own runtime expectations. Confirm the exact promptfoo release you will pin and the Node.js version it needs against the release notes and the npm package page before you write the CI image. Record both versions in the pipeline configuration so a later upgrade does not silently change how generated code runs.

Minimum Node.js version
22.22.0
promptfoo on npm

Docker version and runtime support

Confirm which Docker Engine and container runtime versions the sandboxed eval guide expects, and whether your host supports the isolation settings it relies on, such as dropped capabilities and restricted network access. Ask your platform team whether the runner image ships with a working Docker daemon or whether you need a separate build image. Test the exact container flags on a non-production runner before you rely on them.

Sandboxed code evals guide

Languages the guide covers

The guide describes evaluating LLM-generated code in isolated containers, but the supported languages and the test harness for each one should be confirmed in the document itself. If your application generates code in a language the guide does not cover, you will need your own container image, dependency set and test runner. Confirm which compilers, interpreters and package managers must be present inside the image before you start.

Sandboxed code evals guide

Container support on your CI platform

Hosted and self-managed CI systems differ in whether jobs can start containers, mount sockets and use privileged builds. Check with your CI administrators whether your runners allow Docker commands, whether the daemon is shared across jobs, and whether build caches can leak files between runs. Document the answers, because the sandbox is only as isolated as the runner that hosts it.

Docker-in-CI policy

Many security teams prohibit running a Docker daemon inside CI jobs, or allow it only on dedicated, isolated build hosts. Ask your security and platform owners whether Docker-in-CI is permitted, whether rootless or user-namespace modes are required, and who approves exceptions. If the policy forbids it, decide whether to run the sandboxed evals on a separate, ephemeral host instead of the shared CI fleet.

Network and secret exposure rules

A container that runs generated code can still reach the network, read mounted files or receive API keys from environment variables. Confirm which egress rules, volume mounts and secret scopes your policy allows for eval jobs, and whether the model provider key must stay outside the sandbox. Ask your security team to review these settings with a test payload that tries to read the host environment before the pipeline goes live.

How DeployOpen scopes and delivers sandboxed promptfoo evals

DeployOpen approaches sandboxed promptfoo evals as a scoped piece of work inside your own infrastructure. We agree what generated code will be executed, where the containers run, and which checks gate a release, then build and document that setup so your security and engineering teams can review it before it runs on a CI host.

How we scope

  • Inventory which generated code languages, test runners and dependencies the evals must execute
  • Define the container boundary, network egress rules and resource limits in the written scope
  • Agree which CI runners, registries and secrets the eval jobs may touch before work starts

How we build

  • Configure promptfoo code-execution assertions to run inside isolated Docker containers, not on the host
  • Test that a deliberately malicious generated sample cannot reach host files, credentials or the network
  • Document image build steps, pinned versions and the eval configuration for your engineering team

How we hand over

  • Deliver the container images, eval configs and CI job definitions in your own repositories
  • Provide a runbook covering how to add test cases, rotate images and read sandbox failure output
  • Walk your security and platform teams through the isolation controls and the evidence they produce

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts
  • Ongoing support, upgrades of promptfoo and container images, and continuous testing are available as retainers
  • Confirm during scoping how your own environment, runner type and Docker policy affect the final design

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.