If a multi-engine aircraft loses one engine during takeoff, it is still _required_ to maintain a certain rate of climb until it is clear of obstacles. Airline pilots must comply with this, and ensure that conditions exist so that aircraft performance, as well as gravity, will also comply.
In other words, if it is a hot day and you are at a high altitude, you may have to decrease your fuel, passengers, cargo, etc, or wait until it gets cooler before being able to legally take off.
For a given set of weights and temperatures, aircraft performance manuals will also include a OEI (One Engine Inoperative) Service Ceiling chart. If you lose an engine during cruise, this will tell you how high you will be able to remain. Yet another chart (OEI drift-down) will tell you what speed to decrease to before starting your descent to that altitude.
Rules are also in place to ensure your OEI airplane will be able to avoid running into any mountain ranges that exist between departure and destination. Either by turning around, being able to clear the terrain outright (even OEI), or by planning the flight's cruising altitude to be high enough for the aircraft to be able to "drift down" past the mountain range after it loses an engine.