When we shrink a box containing a gas, does the increased frequency of molecule impacts on the box cause the rise of its temperature? When we shrink a box containing a gas, does the increased frequency of molecule impacts on the box cause the rise of its temperature? I assume the kinetic energy of the molecules shouldn't change because we haven't added it to the gas by just shrinking the box. Maybe only if we hit the box with a very fast object...

 A: To shrink the box you need to move one (or more) of its walls inwards. In microscopic terms, the molecules that collide with this wall are no longer hitting a stationary target, they are now rebounding from a moving object. This increases their kinetic energy, which is why the temperature of the gas increases.
In macroscopic terms, the work done to move the wall inwards against the pressure of the gas raises the temperature of the gas.
A: There are two main ways you can change the energy content of a "box" of particles. Adiabatically and isothermally. You are likely talking about an adiabatic change:
$$
dU = dW +dQ=-PdV+dQ
$$
If $dQ=0$ (no heat added), then,
$$
dU = -PdV
$$
If we're talking about an ideal gas then,
$$
dU = \left(\frac{3}{2}Nk_B\right)dT=-PdV=-\frac{Nk_B T}{V}dV
$$
$$
\frac{3}{2}\int_{T_1}^{T_2}\frac{1}{T}dT=-\int_{V_1}^{V_2}\frac{1}{V}dV
$$
Integrating,
$$
\frac{3}{2}\left(\ln\frac{T_2}{T_1}\right)=-\ln\frac{V_2}{V_1}
$$
$$
T_2=T_1 \left(\frac{V_1}{V_2}\right)^{2/3}
$$
So if $V_2$ is smaller than $V_1$, then consequently $T_2$ will be larger than $T_1$. Temperature rise means the average kinetic energy of the particles has increased. So this results in an increased frequency of collision.
A: Gandal answered the question. He answered the question because he gave an explanation in microscopic terms
I want to add that from the point of view of the second law as you move the wall the volume is decreased. Entropy is decreased because it depends on volume. So we expect that the entropy of the surroundings will be increased. The only way is through the transfer of heat .
But this is only a law and a law is something different from an explanation.
