4. Inside a cube with edge length $a$, there is an inscribed sphere. A line is drawn through the midpoints of two skew edges of the cube. The length of the segment of this line that is intercepted by the sphere is
(A) $(\sqrt{2}-1) a$
(B) $\frac{\sqrt{2}}{2} a$
(C) $\frac{1}{4} a$
(D) $\frac{1}{2} a$
4. (B).

As shown in Figure 2, M and N are the midpoints of two skew edges of a cube. The line $MN$ intersects the surface of the inscribed sphere $O$ at points $E$ and $F$. Connecting $MO$ intersects the opposite edge at $P$, making $P$ the midpoint of the opposite edge. Taking the midpoint $G$ of $EF$, we have $OG \perp EF$. It is also easy to see that $PN \perp MN$, thus $OG \parallel PN$, and $OG = \frac{1}{2} PN = \frac{\sqrt{2}}{4} a$.
In the right triangle $\triangle OGE$, $OE = \frac{a}{2}$, so
$EG = \sqrt{OE^2 - OG^2} = \frac{\sqrt{2}}{4} a$.
Therefore, $EF = \frac{\sqrt{2}}{2} a$.