Gates and Boundaries
The Midrash (Bamidbar Rabba 19:2) states, "They asked the snake why it is always found around gates. It replied, 'It is because I broke the gate of the world.'"
The Shevet Mussar (in his sefer חוקת ,חסד של חוט) explains this midrash following the path of drush. "The snake is the Satan. When he entices a person to an aveirah, he doesn't begin with the aveirah itself, because he knows that the person will not listen to him, because a person is afraid to perform the aveirah. Instead, the Satan begins with the gedarim, the gates that are around the mitzvah. He says, 'Transgress this boundary because Hakadosh Baruch Hu didn't forbid it. It is just a gate. You fear Hashem, and you will be cautious to keep Hashem's command even without this gate.'
"The midrash says that people ask the snake, the Satan, 'Why are you always found near a gate?' Why do you always seek to cause people to transgress the gates, the boundaries?' The Satan replies, 'I broke the gate of the world.' He convinced Chavah to eat from the Tree of Knowledge because he told her to transgress a boundary. This is because Chavah made a geder, to distance herself from the aveirah, so that she wouldn't touch the Tree of Knowledge, and the snake convinced her to transgress that geder and to touch the tree. When she saw that she didn't die after she touched the tree, she ate from the fruit. So, we see that the snake 'broke the gate of the world,' which means he convinced Chavah to break the boundary. This is the response the snake gives when it is asked why it stands by the gate and seeks to cause people to transgress the gedarim that are around the mitzvos. It is because if he succeeds in causing someone to transgress the geder, the person will automatically transgress the aveirah, too."
Bilaam led the donkey to a pathway in a vineyard, as it states (22:24) ה ַכְּרָמ ִים בְּמִש ְׁעוֹל. The sefer אריאל חומת writes that בְּמִש ְׁעוֹל is roshei teivos for ליכא עלמא בהאי מצוה שכר (Kiddushin 39b), "There isn't reward for mitzvos in this world." He explains that Bilaam wanted to curse the Jewish nation. He knew that he couldn't stop them from receiving Olam HaBa, so he tried to stop them from receiving Olam HaZeh. He therefore went to בְּמִש ְׁעוֹל ה ַכְּרָמ ִים to hint that the Jewish nation shouldn't receive reward because ליכא עלמא בהאי מצוה שכר, "There isn't reward for mitzvos in this world."
Hashem sent a malach to stop Bilaam. The malach appeared in the vineyard, when Bilaam was between two gates. As it states (22:24) מ ִזֶּה וְגָדֵר מ ִזֶּה גָּדֵר ה ַכְּרָמ ִים בְּמִש ְׁעוֹל 'ה מ ַלְאַ ךְ וַיַּע ֲמֹד, "The angel of Hashem stood in the path of the vineyards, a fence on this side and a fence on that side." The Arugas HaBosem (ה"ד ויעמוד) writes that this was to hint that although there isn't a reward for mitzvos in this world, they will receive reward for the gedarim, fences, they set up, to protect themselves from aveiros, and to ensure that they will keep the mitzvos.
Yesod Yosef (ch.63) writes, "Fortunate is the person who makes gates for himself with matters related to fear of heaven and to serve Hashem. The gates and safeguards are like malachim, which protect him. They will go with his neshamah when he leaves this world after his petirah, and they protect him from the Sitra Achara.
"When Hakadosh Baruch Hu sees a person making plans and gedarim to guard himself from an aveirah that he often transgresses, and he prays with a broken heart, and he requests that he should succeed to keep this geder, this creates a great nachas ruach for Hashem yisbarach. This is more precious to Hakadosh Baruch Hu than all korbanos of the world. Hashem opens up windows to send out malachim to weaken the strength of the Sitra Achara that they shouldn't harm this person or draw him to sin, as they had done until now."