240. Given a cube $A B C D A_{1} B_{1} C_{1} D_{1}$ with edge $a$. Find the radius of the smallest sphere that touches the lines $A B_{1}, B_{1} C$, $C D$ and $D A$.
240. Extend the edge $B_{1} B$ beyond point $B$ and take a point $K$ on the extension such that $|B K|=a$. It is not difficult to see that $K$ is equidistant from all sides of the quadrilateral $A B_{1} C D$. Now, take a point $L$ on the diagonal $B_{1} D$ such that $\frac{\left|B_{1} L\right|}{|L D|}=\sqrt{2}$. Point $L$ is the foot of the angle bisectors of triangles $B_{1} A D$ and $B_{1} C D$, and thus $L$ is also equidistant from the sides of the quadrilateral $A B_{1} C D$. Now, it can be proven that all points on the line $K L$ are equidistant from the sides of the quadrilateral. Therefore, the desired radius is the shortest distance between the line $K L$ and any of the lines forming the quadrilateral $A B_{1} C D$. Find the distance, for example, between the lines $K L$ and $A D$. Project $K$ and $L$ onto the plane $C D D_{1} C_{1}$. We get points $K_{1}$ and $L_{1}$. The desired distance is equal to the distance from point $D$ to the line $K_{1} L_{1}$.

Answer: $a \sqrt{1-\frac{\sqrt{2}}{2}}$.