Skip to main content

NexCTF Sandbox

A NexCTF plugin that checks answers by running Python: a code runner that tests players' programs against test cases, and a script checker that validates answers with a function you write. Every run happens in a throwaway microsandbox microVM, booted for the submission and removed right after.

CI PyPI ty uv Ruff Python 3.15 License: MIT

Requirements

  • NexCTF 0.12.5 or later
  • A Linux host with KVM: the NexCTF process that checks submissions needs read and write access to /dev/kvm

Quick Start

Add the plugin to NexCTF's NEXCTF_PLUGINS in its .env, along with the host's kvm group id; NexCTF installs the plugin from PyPI and applies its migrations on start:

NEXCTF_PLUGINS=nexctf-sandbox==1.2.0
KVM_GID=993  # stat -c %g /dev/kvm

The NexCTF process that checks submissions boots the microVMs, so it needs read and write access to /dev/kvm. Nothing else: the network setting is enforced by microsandbox's own network stack, with no extra capability or root.

With NexCTF's compose.yml, that goes on the app service, e.g. in a compose.override.yml. /dev/kvm keeps the host's root:kvm ownership and 0660 mode inside the container, so the image's unprivileged user has to join the kvm group:

services:
  app:
    devices:
      - /dev/kvm
    group_add:
      - "${KVM_GID:?set KVM_GID to the host's kvm group id}"

Restart NexCTF, then, on a question, pick the solution type runner or script.

Features

🏃 Code runner

  • Runs the player's Python 3 code against up to 20 test cases, feeding each one's input on stdin
  • Accepted only when every case's stdout matches the expected output, whitespace stripped
  • A crash or a non-zero exit fails the case
  • All the cases of a submission share one microVM, run one after the other
  • For questions with a code input

✅ Script checker

  • Validates the answer with your own Python function, check(answer, team_id, team_fields) -> bool
  • Hands the checker the team's custom fields, typed, private ones included: per-team flags and seeds work out of the box
  • The starter checker lists the team custom fields that exist
  • Checkers written without team_fields keep working as they are
  • For questions with an input, text or code input

A run that outlasts its timeout is not counted as a wrong answer: the player is told the check timed out and can submit again, and the admin event feed records a solution.timeout.

Writing a checker

The checker is a function named check that returns True to accept the answer. team_id is the team's id as a string, or None; team_fields maps each team custom field name to its value (int, bool or str), and a key is missing when the team left the field empty. Declare team_fields only if you need it:

import hashlib


def check(answer: str, team_id: str | None, team_fields: dict) -> bool:
    seed = team_fields.get("seed", "")
    flag = "FLAG{" + hashlib.sha256(seed.encode()).hexdigest()[:16] + "}"
    return answer.strip() == flag

The checker runs in its own microVM, with the base image's Python and the network access set below.

Settings

Under Settings → Plugins → Sandbox:

Setting Key Default
Base image base_image python:3.14-slim; any OCI image with python3 on PATH
vCPUs cpus 1
Memory memory_mib 256 MiB, plus the root disk
Root disk root_disk_mib 64 MiB, in RAM
Network access network_access disabled; internet for public addresses and the host's DNS, all for unfiltered egress, the host's own network included
Max concurrent microVMs max_concurrent 8 per NexCTF API worker process, across all challenges, so WORKERS × 8 in all; takes effect after a restart

The vCPUs, memory, root disk and max concurrent microVMs settings must be at least 1.

Each setting can also come from NexCTF's environment, as NEXCTF_NEXCTF_SANDBOX_ followed by its key in capitals, e.g. NEXCTF_NEXCTF_SANDBOX_BASE_IMAGE=python:3.13-slim. A value saved under Settings takes precedence over it.

Metadata

Release files for nexctf-sandbox 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nexctf-sandbox 1.2.0
File Size Uploaded Provenance Actions
nexctf_sandbox-1.2.0.tar.gz 11.6 kB With provenance Details for nexctf_sandbox-1.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nexctf-sandbox 1.2.0
File Interpreter ABI Platform Actions
nexctf_sandbox-1.2.0-py3-none-any.whl Python 3 none any Details for nexctf_sandbox-1.2.0-py3-none-any.whl

Total release size: 26.3 kB

Release files / nexctf_sandbox-1.2.0.tar.gz

Download URL nexctf_sandbox-1.2.0.tar.gz
Size 11.6 kB
Tags Source
SHA-256 checksum
How to use checksums
ce392d45df11e7f5b82a104f4da6d055851d3b4c981a16fdcf59942c6e372078
BLAKE2b-256 checksum
How to use checksums
60cb19ff9ba6fc9e5a00034d2506a1cddbbde5e9e7e6f1a4d1024c51fad3bd3d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Release files / nexctf_sandbox-1.2.0-py3-none-any.whl

Download URL nexctf_sandbox-1.2.0-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6c568f7edef33ba60302d0c2fff9aa30d669c957ec1f3972b06941ff31790e06
BLAKE2b-256 checksum
How to use checksums
aedb010b21311a86bd0fe26453d0ba4b0d06360530c311ac74afc088868bcfb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

Security for nexctf-sandbox 1.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for nexctf_sandbox-1.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page