The Mishna in Masechet Shabbat (chapter 22) states that it is permissible to apply oil to one’s skin on Shabbat, but "Lo Mit’amelim" – it is forbidden to "exert oneself." Rashi explains this to mean that although it is permissible to apply oil or ointment to one’s skin on Shabbat, one may not rub the ointment vigorously, with a lot of effort, because of "Ubdin De’hol" – this is regarded as a weekday activity. This interpretation of the Mishna is accepted also by Rav Ovadia of Bartenura (1445-1515).
Rabbenu Hananel (d. 1053), however, explains differently, interpreting "Lo Mit’amelim" as referring to various kinds of stretches or motions with one’s hands and legs which are done for health reasons, as some kind of exercise routine. This is forbidden on Shabbat, Rabbenu Hananel writes, because it falls under the category of Refu’a – medicine on Shabbat, which is prohibited. The Sages enacted a law forbidding the use of medication on Shabbat (under certain conditions) because in ancient times, people would produce their own medicine by grindings herbs, and the Sages were concerned that people might do so on Shabbat. Rabbenu Hananel explains that the exercises described are forbidden for the same reason, because they are done for medicinal purposes. This explanation is followed by the Rambam (Rav Moshe Maimonides, Spain-Egypt, 1135-1204).
However, Rabbenu Hananel and the Rambam add one important phrase in giving this explanation – "Kedeh Le’hazia." This means that exercise is forbidden if it is done for the purpose of perspiring. People with certain health conditions would work up a sweat in order to improve their health, and this is what is forbidden on Shabbat.
The Mishna Berura (Rav Yisrael Meir Kagan of Radin, 1839-1933) explains that since the entire enactment forbidding Refu’a on Shabbat was made because of the concern of Shabbat violation when making medication, only those procedures which involve medicine are included in this prohibition. Exercise, of course, does not involve any medication. However, the Mishna Berura writes, there was, apparently, some medication that people would take to cause them to perspire, and so for this reason, Rabbenu Hananel and the Rambam maintained that exercise intended to work up a sweat is forbidden on Shabbat, as one might then also produce a medication which has this effect, in violation of Shabbat.
The Shulhan Aruch cites the Rambam’s formulation, and therefore, according to Sephardic practice, exercise is forbidden on Shabbat only if it is done for the purpose of perspiring. Some have raised the question of whether nowadays, when medicine does not recognize health benefits to perspiring per se, perhaps this prohibition would not apply, but contemporary Poskim have ruled that exercise performed for the purpose of causing perspiration is forbidden on Shabbat, in accordance with the Shulhan Aruch’s ruling.
Thus, Hacham Bension Abba Shaul (Israel, 1924-1998) rules in his Or Le’sion that it is permissible to lift weights on Shabbat. Likewise, one may take a brisk walk on Shabbat, as this is not done in order to perspire. Pushups and similar exercises are also allowed. Jogging and running are permissible so long as there is no intent to build a sweat. Of course, one must wear Shabbat clothing out of the house on Shabbat, and so one must ensure that he is properly dressed when walking for exercise.
The Mishna Berura cites the Shilteh Ha’gibborim (Rav Yehoshua Boaz, d. 1557) as raising the question of whether it is permissible to have a massage on Shabbat to alleviate tension, and the Mishna Berura concludes that this would be forbidden. However, Hacham Bension, as well as Hacham Yishak Yosef, disagree, and rule that a massage is allowed on Shabbat, provided that it is not intended to cause perspiration, which massages of course generally aren’t. (It goes without saying that the massage is given under conditions that are appropriate, irrespective of the Shabbat prohibitions.) By the same token, Hacham Bension maintained that physical therapy exercises are permissible on Shabbat, since they are not done for the purpose of causing perspiration.
The Mishna in Pirkeh Abot (1:10) urges, "Ehab Et Ha’melacha" – "Love work," and the Yabetz explains this to mean that one should accustom himself to exercise. He writes that physicians have determined that most illnesses from which people suffer result from a lack of physical activity, and so the Sages urge us to "love work" – to regularly exercise, in order to maintain our health. Each day, at the end of the Amida prayer, we pray for "Hilus Asamot," which refers to good physical health. In order for us to pray to Hashem to bless us with physical strength, we must make an effort and do what we can to care for our health. Given the unanimous view of health experts today that exercise is crucial for maintaining health, it behooves us all to regularly exercise as part of our obligation to care for our physical wellbeing.
Summary: Exercise that is not done for the sake of working up a sweat is allowed on Shabbat. This includes lifting weights, pushups, jogging, running, and brisk walking. There must be no clear intent to build up a sweat. Massages and physical therapy exercises are also allowed. It goes without saying that one must remain dressed in Shabbat clothes outside the home on Shabbat.