West Ham boss Slaven Bilic went into the game allegedly under pressure to keep his job at the London Stadium, but the Croatian will be relieved to avoid an upset at Whaddon Road.
West Ham dominated the opening stages at the League Two outfit but it took until 13 minutes for a shot to be registered as Ayew dragged a weak shot wide of the near post from 14 yards out.
Will Boyle headed over for the hosts shortly before the half-hour mark, but the remainder of the first half belonged to West Ham, with Pedro Obiang having a header cleared off the line by Kyle Storer and Sakho being denied from close range.
With five minutes of the first half remaining, West Ham finally had their goal through Sakho, who received the ball from Mark Noble before scuffing a shot into the far corner from 16 yards out.
Cheltenham needed to reach the break without conceding again, but they lasted just three minutes as Ayew found the bottom corner from an acute angle after being teed up by a clever pass from Sakho.
After the restart, West Ham looked in full control and James Collins soon came close to adding to the East London side's advantage with a header which went marginally over the crossbar.
However, that reprieve sparked a response from Cheltenham, with Eisa first being denied by a terrific double block from Sam Byram and Collins, before the Sudanese forward struck an attempt straight at Adrian.
Time was beginning to run out for the home team but after Ayew had curled just wide for West Ham, Cheltenham's Harry Pell fired a low volley agonisingly wide of the far post.
Jordan Foster wasted a late opportunity for Cheltenham, but West Ham were full value for their victory and Bilic will hope that this result gets their season fully up and running.