In this paper, we study the dynamical Casimir–Polder force between an ensemble of identical two-level atoms and the wall of a rectangle waveguide with semi-infinite length. With the presence of both the rotating wave and counter rotating wave terms in the light–matter interaction Hamiltonian, we utilize the perturbation theory to solve the Heisenberg equation. Up to the seconder of coupling strength, we obtain the energy shift analytically and the Casimir–Polder force numerically. Our result shows that the dynamical behavior of the Casimir force is closely connected to the photon propagation in the waveguide. Therefore, we hope this work will stimulate the studies about the quantum effect in waveguide scenario.