Fill window gaps with rigid foam board
You can use a box fan with a window gap, but seal it safely with rigid foam insulation board to stop air leaks and prevent the fan from falling out.
The foam board route is simple: buy a 1/2‑inch or 1-inch sheet from any hardware store, cut it into strips, and wedge them around the fan where the window is open. It’s fire-resistant (unlike cardboard), holds its shape, and actually insulates. If the gap is small—like half an inch or less—foam weatherstripping tape works fine
