HelixML

Securing SGLang and Jupyter with stock-Linux eBPF shields

Nov 26, 2026

How we block SGLang weight-mutation probes and Jupyter terminal takeovers inside the Linux kernel using cgroup_skb/ingress and cgroup/connect4, without restarting GPUs or adding sidecar proxies.

Automated scanners hit our internet-facing AI decoys every day with requests aimed at inference and notebook ports:

POST /update_weights_from_tensor HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36

Right alongside those probes, the same hosts see continuous sweeps against Jupyter's /api/terminals and /api/kernels. Neither path is obscure. Both sit on default ports that GPU clusters expose behind broad reverse proxies or temporary tunnels.

We built an in-kernel HTTP path shield for Helix Cyber Force Field (cyberd) and open-sourced the standalone mechanism in helixml/ebpf-ai-shield-demo. It attaches to a running Linux cgroup v2 slice on stock Linux >= 5.8, blocks dangerous API routes before Python wakes, and contains outbound connections from notebook cells without restarting GPUs or inserting a sidecar proxy.

Why SGLang weight-update routes are dangerous on an inference port

SGLang exposes POST /update_weights_from_tensor and POST /init_weights_update_group so distributed reinforcement learning from human feedback (RLHF) and post-training frameworks can push updated model tensors across worker nodes over HTTP. Those routes are designed for trusted training clusters on isolated interconnects.

When an SGLang server starts without strict route filtering or sits behind a permissive reverse proxy, those administrative endpoints share port 30000 with /v1/chat/completions and /v1/models. Any caller who can reach the OpenAI-compatible inference API can also reach a live weight-mutation and deserialization surface inside the GPU worker process.

GPU operations teams resist the two usual fixes mid-run. Restarting an 8xH200 SGLang instance to change flags or redeploy behind a stricter gateway evicts hundreds of gigabytes of model weights and reusable prompt data held in the key-value cache (KV cache). Reloading checkpoints takes minutes and resets latency across every tenant.

Inserting an inline userspace web application firewall (WAF) proxy in front of high-throughput Server-Sent Events (SSE) token streaming introduces a second set of problems. Every chunk crosses extra sockets and buffers, adds tail latency, and creates another userspace daemon that can stall or crash under load.

Filtering HTTP paths inside cgroup_skb/ingress

Most production inference and notebook stacks already terminate TLS at an edge proxy such as Caddy, Nginx, Envoy, or a Cloudflare Tunnel. The proxy forwards plaintext HTTP over lo loopback or a local container bridge to 127.0.0.1:30000 (SGLang) or 127.0.0.1:8888 (Jupyter).

Linux passes every inbound TCP segment headed for a socket inside a cgroup v2 slice through BPF_PROG_TYPE_CGROUP_SKB (AttachCGroupInetIngress) immediately before socket delivery. That hook observes packets arriving on physical NICs, Docker bridges, and lo loopback alike. It runs on stock Linux >= 5.8 with zero lsm=bpf boot parameters and zero kernel modules.

In-kernel HTTP route filtering before Python wakes: inbound requests behind TLS termination enter cgroup_skb/ingress, match a 52-byte BPF_MAP_TYPE_LPM_TRIE keyed by destination port and request-line prefix, pass benign SGLang and Jupyter traffic to userspace, and drop denied routes with SK_DROP plus a 136-byte ring-buffer event before epoll_wait wakes.

The entire shield lives in ebpf/http_shield.bpf.c. On representative x86_64 builds, the program compiles to a few hundred BPF instructions (roughly 1–2 KB of JIT-compiled machine code, varying with Clang and kernel version), with zero BPF loops and only five CGROUP_SKB-safe helpers (bpf_skb_load_bytes, bpf_map_lookup_elem, bpf_ringbuf_reserve, bpf_ringbuf_submit, and bpf_ktime_get_ns).

// 52-byte LPM trie key: 4B prefixlen + 2B big-endian port + 46B ASCII prefix.
struct http_lpm_key {
	__u32 prefixlen;
	__be16 dst_port_be;
	__u8 prefix[46];
};
 
SEC("cgroup_skb/ingress")
int ai_shield_http_in(struct __sk_buff *skb)
{
	/* ... parse IPv4/IPv6 + TCP header via bpf_skb_load_bytes() ... */
 
	// Never lock out SSH (port 22) or configured management ports.
	if (dst_port_host == 22)
		return 1;
	if (bpf_map_lookup_elem(&ai_shield_mgmt_ports, &dst_port_host))
		return 1;
 
	struct http_lpm_key key = { .prefixlen = 384, .dst_port_be = dst_port_be };
 
	// Try 46, then 24, then 10 bytes so pure SYN/ACK/FIN packets exit fast.
	if (bpf_skb_load_bytes(skb, payload_off, key.prefix, 46) != 0) {
		if (bpf_skb_load_bytes(skb, payload_off, key.prefix, 24) != 0) {
			if (bpf_skb_load_bytes(skb, payload_off, key.prefix, 10) != 0)
				return 1;
		}
	}
 
	// Exact destination port first, then wildcard port 0 fallback.
	struct http_shield_rule *rule = bpf_map_lookup_elem(&ai_shield_http_lpm, &key);
	if (!rule) {
		key.dst_port_be = 0;
		rule = bpf_map_lookup_elem(&ai_shield_http_lpm, &key);
	}
	if (!rule || rule->action != ACTION_DENY)
		return 1; // SK_PASS
 
	/* ... emit 136-byte event to ai_shield_events (BPF_MAP_TYPE_RINGBUF) ... */
	return (rule->mode == MODE_ENFORCE) ? 0 : 1; // 0 = SK_DROP, 1 = SK_PASS
}

The longest-prefix match trie (BPF_MAP_TYPE_LPM_TRIE) turns HTTP path filtering into an O(1) radix lookup. A rule entry stores prefixlen = (2 + len(prefix)) * 8 bits covering the 2-byte big-endian destination port and up to 46 bytes of the HTTP request line, such as POST /update_weights_from_tensor.

Every pure TCP handshake or acknowledgment packet carries zero payload bytes, fails the bpf_skb_load_bytes calls, and exits with SK_PASS before touching the trie. Port 22 and any port in ai_shield_mgmt_ports return SK_PASS unconditionally in-kernel, and cyberd also refuses to insert port-22 rules from policy. (Production cyberd prefixes these BPF symbols cyberd_*—cyberd_http_in, cyberd_mgmt_ports, cyberd_http_lpm, and cyberd_events—for the same program logic.)

When a matching probe arrives in enforce mode, the program writes a 136-byte event to ai_shield_events (BPF_MAP_TYPE_RINGBUF) and returns 0 (SK_DROP). Each event records the source IPv4 address, destination port, rule ID, mode flag, and first 44 bytes of the request line. The kernel drops the TCP payload segment before the listening socket ever wakes epoll_wait().

For Python, SK_DROP means Uvicorn or Tornado receives zero bytes. No route parser runs, no JSON body is allocated, and no tensor deserializer is touched. On the same TCP port, POST /v1/chat/completions and GET /v1/models miss the trie, return 1 (SK_PASS), and stream SSE tokens directly to clients.

Every rule carries its own mode field (observe or enforce). Operators can attach the program live via BPF_F_ALLOW_MULTI in observe mode to record matching probes in the ring buffer while still returning SK_PASS. Switching the map entry to enforce takes effect on the next packet without detaching the program or restarting the workload.

Two kernel boundaries around Jupyter notebooks

Jupyter on a GPU host presents a harder threat model than an inference API. Blocking inbound HTTP paths alone is not enough when notebook users intentionally run arbitrary Python inside cells. Operators need to remove interactive pseudo-terminal (PTY) web shells from the HTTP API while also bounding what code inside a running cell can reach.

Two kernel boundaries around a live Jupyter server: Layer 1 uses cgroup_skb/ingress to drop POST /api/terminals and unauthorized /api/kernels mutations while keeping GET /api/status and /api/contents open; Layer 2 uses cgroup/connect4 (in the standalone demo and cyberd) to reject 169.254.169.254/32 with EPERM, while production cyberd adds cgroup/connect6, cgroup/sysctl to block /proc/sys writes, and kprobe/security_file_open to log credential reads.

Layer 1: Inbound HTTP route shield (cgroup_skb/ingress). Attaching the ingress program to Jupyter's cgroup blocks POST /api/terminals and, when kernel creation should be frozen, POST /api/kernels. GET /api/status, /api/contents, and existing notebook execution stay open. Specifying "POST /api/terminals" blocks only POST; supplying a bare path like "/api/terminals" expands across GET, POST, PUT, PATCH, and DELETE.

Layer 2: Post-cell blast-radius containment (cgroup/connect4 in the standalone demo; plus cgroup/connect6, cgroup/sysctl, and kprobe/security_file_open in production cyberd). Even if a user or compromised notebook cell executes Python directly, stock-Linux eBPF hooks hold the boundary around the cgroup slice. The minimal standalone demo (helixml/ebpf-ai-shield-demo) attaches the two core hooks (cgroup_skb/ingress in ebpf/http_shield.bpf.c and cgroup/connect4 in ebpf/cgroup_egress.bpf.c), while production cyberd adds cgroup/connect6, cgroup/sysctl, and kprobe/security_file_open:

  • cgroup/connect4 (standalone demo + cyberd; plus cgroup/connect6 in production cyberd for IPv4-mapped ::ffff:a.b.c.d addresses): Intercepts connect(2) before a TCP SYN packet leaves the host and checks the destination address against a CIDR BPF_MAP_TYPE_LPM_TRIE. A cell attempting server-side request forgery (SSRF) against the cloud Instance Metadata Service (IMDS) at 169.254.169.254/32 or restricted internal subnets fails immediately with PermissionError: [Errno 1] Operation not permitted (EPERM).
  • cgroup/sysctl (BPF_CGROUP_SYSCTL, production cyberd): Blocks writes to /proc/sys kernel parameters from inside the cgroup with EPERM, with zero reboot and no lsm=bpf requirement.
  • kprobe/security_file_open (production cyberd): Resolves kernel struct offsets via BPF Type Format (BTF) at load time and watches configured credential (dev, ino) pairs such as ~/.aws/credentials, SSH private keys, or Kubernetes service-account tokens. Every open emits an attributed ring-buffer event containing PID, UID, cgroup ID, and process name. On hosts booted with lsm=bpf, lsm/file_open extends the same inode table with write enforcement.

Declarative policies in Helix Cyber Force Field

Inside Helix Cyber, operators do not hand-craft BPF maps or shell scripts. Both layers compile from typed JSON policies that cyberd reconciles onto target hosts.

A shirudo.shield manifest configures the cgroup_skb/ingress HTTP shield across SGLang and Jupyter ports:

{
  "shield_id": "ai-inference-jupyter-http-guard",
  "package": "http-shield",
  "mode": "observe",
  "hook": "cgroup_skb/ingress",
  "http_ports": [30000, 8888],
  "http_deny_paths": [
    "POST /update_weights_from_tensor",
    "POST /init_weights_update_group",
    "POST /api/terminals"
  ]
}

Adding "unit": "sglang.service" or "cgroup": "/system.slice/jupyter.service" scopes the attachment to a single service slice instead of the host root cgroup.

A companion shirudo.sandbox manifest configures Layer 2 egress containment on the Jupyter slice:

{
  "deny_cidrs": ["169.254.169.254/32", "10.0.0.0/8"],
  "sandboxes": [
    {
      "id": "jupyter",
      "paths": ["/usr/local/bin/jupyter-lab", "/usr/bin/python3"],
      "unit": "jupyter.service",
      "mode": "observe"
    }
  ]
}

Safe production rollout: Simulate, measure impact, promote to enforce

Dropping packets inside the kernel on a busy GPU cluster carries real outage risk if a rule matches an unexpected internal health check, RLHF trainer, or notebook workflow. To remove that guesswork across HTTP, network, and CVE shields, Helix Cyber ships a Cloudflare-style three-stage rollout workflow: Simulate (observe) → Policy Impact Preview → Promote to Enforce.

  1. Start in Simulate (log-only / mode: "observe"). Roll the policy out in observe mode first. cgroup_skb/ingress runs the exact same LPM trie check against live SGLang (POST /update_weights_from_tensor) and Jupyter (POST /api/terminals) requests at socket ingress, increments per-CPU hit counters, and streams kernel ring-buffer events (http_observed → shirudo.shield.http) without dropping a single packet (return 1 / SK_PASS).
  2. Review Policy Impact Preview in Cyber SaaS. Let the simulated policy soak across normal traffic windows and inspect Enforcement Metrics alongside the Defence Signal Feed. Compare simulated versus blocked hit charts over time and check sampled affected endpoints and ports (affected_samples) to confirm legitimate training jobs, inference traffic, and active notebook kernels are untouched.
  3. One-click Promote to Enforce (mode: "enforce"). Once the impact preview shows only unwanted probes, promoting the policy flips the signed .hxsb bundle constant in place via atomic link.Update(), guarded by a 90-second dead-man rollback timer if the host loses control-plane connectivity. Matching exploit requests begin dropping immediately in-kernel (http_denied) with zero process restarts and no disruption to established connections.

Hands-on reproduction with ebpf-ai-shield-demo

You can run the full SGLang and Jupyter reproduction on any stock Linux >= 5.8 machine with root privileges using the standalone Go loader and BPF C source in helixml/ebpf-ai-shield-demo:

git clone https://github.com/helixml/ebpf-ai-shield-demo
cd ebpf-ai-shield-demo
sudo ./scripts/run-demo.sh

The script starts mock SGLang (:30000) and Jupyter (:8888) HTTP servers inside a temporary cgroup v2 slice and verifies unshielded behavior. It then attaches cgroup_skb/ingress and cgroup/connect4 live without restarting either server and replays benign and malicious requests against both ports.

The standalone CLI in helixml/ebpf-ai-shield-demo supports both --mode observe (log matching requests without dropping packets) and --mode enforce out of the box. To test in simulation first on a live cgroup, pass --mode observe; once the telemetry looks clean, attach in enforce mode:

sudo go run ./cmd/ai-shield \
  --cgroup /sys/fs/cgroup/system.slice/sglang.service \
  --mode enforce \
  --rule "30000:POST /update_weights_from_tensor" \
  --rule "30000:POST /init_weights_update_group" \
  --rule "8888:POST /api/terminals" \
  --deny-cidr 169.254.169.254/32

Here is the before-and-after verdict split across both workloads when the shield attaches live:

WorkloadRequest or syscallBefore shieldWith eBPF shield (enforce)Server bytes received
SGLang (:30000)GET /v1/models200 OK200 OK (SK_PASS)Normal
SGLang (:30000)POST /v1/chat/completions200 OK (SSE stream)200 OK (SK_PASS)Normal
SGLang (:30000)POST /update_weights_from_tensor200 OK (weights mutated)Dropped (SK_DROP + ringbuf event)0
SGLang (:30000)POST /init_weights_update_group200 OK (group initialized)Dropped (SK_DROP + ringbuf event)0
Jupyter (:8888)GET /api/status200 OK200 OK (SK_PASS)Normal
Jupyter (:8888)POST /api/terminals200 OK (PTY shell spawned)Dropped (SK_DROP + ringbuf event)0
Jupyter cellsocket.connect(("169.254.169.254", 80))Connects to cloud IMDSPermissionError: [Errno 1] Operation not permitted (EPERM)0 packets sent

Scope and trade-offs

This mechanism solves a specific problem: closing exposed HTTP/1.1 API routes and outbound SSRF targets on live Linux workloads with zero restarts. Three technical limits define where it fits in a stack.

Plaintext HTTP inside the cgroup. cgroup_skb/ingress inspects cleartext TCP payloads. It works when Caddy, Nginx, Envoy, HAProxy, or a Cloudflare Tunnel terminates TLS and forwards plain HTTP over loopback or a bridge to SGLang or Jupyter. If Python terminates TLS directly inside the server process, the kernel sees ciphertext on ingress and cannot match request lines without uprobe TLS interception or moving TLS termination to a local proxy.

HTTP/1.1 first-segment prefix matching. The 52-byte LPM trie key inspects up to the first 46 bytes of the TCP payload (method plus path prefix) in constant time with no loops. It does not parse HTTP/2 binary frames, reassemble a request line split across tiny TCP segments, or canonicalize encoded paths like /%75pdate_weights_from_tensor. Treat the kernel shield as an emergency zero-restart boundary and pair it with reverse-proxy route normalization when you next reload the edge gateway.

Silent drops instead of HTTP 403 responses. Returning SK_DROP drops the TCP segment silently, so the caller waits and retransmits until its socket times out. That behavior keeps the BPF program stateless and denies scanners an instant status oracle, at the cost of slower failure for accidental internal callers. If human users need immediate 403 Forbidden pages on a route, enforce that response in the reverse proxy once a reload window opens.

Does attaching the eBPF shield require restarting SGLang, Jupyter, or Linux?
No. Both cgroup_skb/ingress and cgroup/connect4 attach live to an existing cgroup v2 path via bpf_link with BPF_F_ALLOW_MULTI. Running SGLang processes keep their GPU model weights and key-value cache warm, and active Jupyter kernels stay connected.
What Linux kernel version and boot parameters are required?
Stock Linux >= 5.8 with cgroup v2 and BPF ring buffer support. No custom kernel modules and no lsm=bpf boot parameter are required for the standalone demo's two core hooks (cgroup_skb/ingress and cgroup/connect4) or the additional production cyberd hooks (cgroup/connect6, cgroup/sysctl, and kprobe/security_file_open). Enabling lsm=bpf is optional and only needed in cyberd if you also want BPF-LSM write or exec enforcement.
Does this work behind Caddy, Nginx, Envoy, or Docker?
Yes. Because cgroup_skb/ingress runs right before socket delivery inside the target cgroup, it inspects inbound plaintext HTTP arriving over external NICs, Docker bridges, and 127.0.0.1 loopback after TLS termination. It does not inspect encrypted payloads when TLS terminates directly inside the Python process.
Does the shield slow down /v1/chat/completions or SSE token streaming?
No. The BPF program is compact (a few hundred instructions and roughly 1–2 KB of JIT-compiled code on representative x86_64 builds, depending on Clang and kernel version) with zero loops. Pure TCP ACK packets exit immediately with zero payload reads, and non-matching HTTP requests miss the O(1) LPM trie and pass directly to the socket without userspace copies. Outbound SSE response streams do not traverse the ingress hook at all.
Can a misconfigured HTTP shield rule lock me out of SSH?
No. TCP destination port 22 is bypassed unconditionally inside the eBPF program before any payload or trie lookup, and cyberd also strips port 22 and configured management ports when loading policies.
Why attach cgroup/connect4 to Jupyter if POST /api/terminals is already blocked?
Blocking /api/terminals removes interactive PTY web shells, but Jupyter users still run Python inside notebook cells by design. Attaching cgroup/connect4 blocks outbound socket.connect() calls to 169.254.169.254/32 and restricted internal CIDRs with EPERM before any TCP SYN packet leaves the host.
How can I roll out a new eBPF shield rule in production without risking an outage?
Start the policy in Simulate mode (observe) so cgroup_skb/ingress evaluates live requests, emits http_observed ring-buffer events (shirudo.shield.http) and per-CPU counters, and returns SK_PASS on every packet. After checking simulated versus blocked hit charts and affected_samples in Enforcement Metrics and the Defence Signal Feed in Cyber SaaS, promote to enforce in one click via atomic link.Update() with a 90-second dead-man rollback guard.

The standalone demo, Go loader, and eBPF C source are public at helixml/ebpf-ai-shield-demo. Managed shirudo.shield and shirudo.sandbox policies ship in Helix Cyber.