What is eBPF?
eBPF (extended Berkeley Packet Filter) is a Linux kernel technology that lets user-space programs run small verified programs inside the kernel without writing kernel modules or rebooting. It powers modern observability, networking, security, and testing tools including Cilium, Falco, Pixie, Tetragon, and Keploy.
How eBPF works
An eBPF program goes through four phases before it starts running. First, you write it in a restricted C dialect (or a higher-level language like Rust via Aya, or Go via cilium/ebpf) and compile it to eBPF bytecode. Second, you load the bytecode into the kernel via the bpf() syscall, which triggers the verifier. The verifier proves the program terminates (no unbounded loops), stays within memory bounds, and only calls allowed kernel helper functions — this is the safety boundary that makes eBPF different from kernel modules. Third, the kernel JIT-compiles the verified bytecode to native machine code. Fourth, you attach the program to a hook point — a syscall entry, a network device, a kprobe, a tracepoint, a cgroup event — and from that moment on it runs every time the hook fires.
The verifier is the critical piece. Kernel modules run with full privilege and can panic the system if they contain a bug; eBPF programs that would panic simply fail to load. This shifts the risk boundary from "kernel code that production engineers wrote" to "kernel code that the verifier approved" — a much smaller attack surface.
The four main use cases
Networking
High-performance packet filtering, load balancing, service mesh data planes. Cilium replaces iptables for Kubernetes networking; Katran is Facebook's eBPF load balancer handling all edge traffic.
Observability
Syscall tracing, function latency measurement, resource attribution. BCC ships 100+ tools; bpftrace is the awk-for-kernel scripting language; Pixie provides zero-instrumentation observability for K8s.
Security
Runtime threat detection, policy enforcement at syscall level. Falco monitors for suspicious kernel events; Tetragon blocks disallowed operations before they execute; Aqua Security uses eBPF for container runtime protection.
Testing
Capturing real API traffic and replaying it as deterministic tests. Keploy attaches to the syscall boundary for HTTP, gRPC, and database traffic — no SDK, no proxy, no code changes.
How Keploy uses eBPF for API testing
Traditional API testing tools require one of two things: a language-specific SDK that your application links against, or a reverse proxy that your traffic flows through. Both approaches change how your service runs in production — the SDK couples your application to the test framework, and the proxy adds a network hop that affects latency measurements. Keploy takes neither approach. Instead, it attaches eBPF programs to the handful of syscalls that network traffic flows through — accept, read, write, sendto, recvfrom — and captures the full request and response pair at the kernel level.
This means your application does not know Keploy is there. It runs unmodified, with no dependency on any Keploy library. The operator starts Keploy alongside the application (keploy record -c "./your-app") and Keploy captures whatever traffic the app processes. When the capture session ends, Keploy writes YAML test fixtures to disk with auto-generated mocks for every downstream dependency (databases, message queues, external HTTP APIs). During replay, Keploy serves those mocked responses back to the application from the same eBPF hooks, so the application cannot distinguish test runs from production.
For the two hard problems in eBPF-based testing — non-deterministic data (timestamps, UUIDs, session tokens) and secret handling — Keploy ships with auto-detection for the common patterns and a config file for application-specific cases. See Noise & Secret Management for the full mechanism.
eBPF vs kernel modules
| Dimension | eBPF program | Kernel module |
|---|---|---|
| Safety | Verified; cannot panic the kernel | Full privilege; bugs panic the system |
| Kernel version compatibility | Portable via CO-RE / BTF | Must compile per-version |
| Loading | CAP_BPF or CAP_SYS_ADMIN | Root + module signing |
| Typical use case | Observability, networking, security, testing | Device drivers, filesystems |
| Expressiveness | Restricted to verifier-approved ops | Full kernel API |