Tesla Motors makes it clear that an extension cord is not to be used with its UMC. The NEC requires that you follow manufacturer’s instructions, so technically you violate the NEC by using one.
The NEC contains some rules for using extension cords. Some of the rules state that extension cords are not permitted to be used as a substitute for the fixed wiring of a structure; run through holes in walls, structural ceilings, suspended ceilings, dropped ceilings, or floors; run through doorways, windows, or similar openings; or be concealed behind building walls, structural ceilings, suspended ceilings, dropped ceilings, or floors.
However, as to the question of whether it is safe or not… Technically, yes. With the right size conductors, an extension cord, whether 120V or 240V, is relatively safe in limited lengths.
For 120V, to keep the voltage drop within range, you can use a 14 AWG cord if your TOTAL one-way circuit length from the car to the breaker panel is < 50 ft., 12 AWG if your total is < 100 ft., and you'd need to go to 10 AWG if you're at 150 ft. or greater.
For 40A charging @ 240V (NEMA 6-50, 10-50, or 14-50), you should use 6 AWG, and your total one-way circuit length can be 300 ft, with voltage drop at reasonable levels.
For 24A charging @ 240V (NEMA 6-30, 10-30, or 14-30), AWG 10 is good to 200 ft. one-way from breaker panel to the car, go one gauge up (AWG 8) if you need more.
As mentioned, keep your cord to the smallest length possible to reduce voltage drop and increase your charging efficiency.
Keep in mind the potential insurance implications of this, as mentioned above. You are violating the NEC in the US by doing this.