In the general theory of relativity, gravity is not explained simply as an attraction as in the description of classical physics. Mass and energy can influence the shape of space-time, while objects move according to the structure of space-time. The simple description is often analogous to a heavy object bending a flexible surface, although this analogy does not fully describe actual four-dimensional space-time. So planets orbit the Sun not because they are pulled by a mysterious force from a distance, but because they move according to the geometry of space-time which is influenced by the mass of the Sun.
Another interesting thing is that gravity also affects time. Clocks that are in different gravitational fields can run at different rates when compared to clocks that are in different gravitational conditions. This effect is not just a theory on paper because it needs to be taken into account in technology such as satellite navigation systems so that the calculations remain accurate. General relativity has also succeeded in explaining various phenomena such as the bending of light by gravity and the existence of gravitational waves. So when we say gravity affects space and time, we don't mean space and time as two completely separate things, but parts of the structure of space-time that can change due to the distribution of mass and energy.