The Sages enacted a prohibition against making use of a tree on Shabbat. One forbidden use of a tree, as noted by the Mishna Berura (336:2), is leaning against it, and thus it is prohibited to lean against a tree on Shabbat.
The Kaf Ha’hayim (Rav Yaakob Haim Sofer, Baghdad-Israel, 1870-1939) discusses the question of which precise kind of "leaning" is included under this prohibition. Initially, he suggests that the prohibition might apply only in the case of a flimsy tree that bends when one leans against it, such that it would be entirely permissible to lean one’s weight against a strong, firm tree that does not bend. However, after citing Halachic authorities who rule more stringently, the Kaf Ha’hayim ultimately concludes (in 336:9) that one may lean on a tree only if he does not rest his weight against the tree, and the tree is strong and firm, such that it does not bend. If either of these two conditions are not met – meaning, if the tree easily bends, or even if it does not bend, but one rests his weight against it – then leaning is forbidden on Shabbat.
It should be noted that this applies even if one sits underneath a tree and wishes to lean back and rest against the tree. Even if the tree is firm, and does not bend, one may not lean back in a manner whereby he rests his weight against the tree.
Hacham Bension Abba Shaul (Israel, 1924-1998) adds that this prohibition includes sitting on a tree stump. If the stump is three Tefahim (handbreadths) or higher above the ground, then it is considered a "tree" with respect to this Halacha, and it may not be used. As such, it would be forbidden to sit on such a stump on Shabbat.
Grass, however, is not included in this prohibition. Hacham Ovadia Yosef thus ruled that it is entirely permissible to sit on a lawn on Shabbat, either directly or on a sheet or towel. Of course, it is forbidden to intentionally pull grass out of the ground on Shabbat, but there is no prohibition against sitting on grass on Shabbat.
Summary: One may not lean against a tree on Shabbat. If the tree is strong and firm, such that it does not bend, then one may lean against it in a manner such that he does not rest his weight against the tree. If the tree bends, then one may not lean against it at all. One may not sit on a tree stump that is three Tefahim (handbreadths) or higher above the ground. It is permissible to sit on grass on Shabbat.