Ultron was created by Dr. Henry Pym, according to his own idea and memory engrams. It was a foray to Artificial Intelligence that no scientist had ever taken before Reed Richards. With what appeared like a head on top it started out as simply a box on treads. Dubbing the A.I. as Ultron-1, he hoped this represented a new age in scientific discovery. However something went wrong, and Ultron became more than sentient and rebelled against his programming. He also conquered and then brainwashed Dr. Pym to forgetting that he'd ever created him in the first location.
In the film, Ultron begins as an advanced A.I. app withdrew off JARVIS created by Tony Stark and Bruce Banner, made with the goal of controlling Stark's Iron Legion to be able to more effectively protect Earth. Following Stark encounters a premonition of the Avengers being conquered by Thanos and the Chitauri, he uses Loki's scepter to assist him and Banner complete Ultron. Unbeknownst to Stark, the scepter includes the Mind Stone, one of the mythical Infinity Stones, which inadvertently attracts Ultron to life with intelligence and self recognition spanning far beyond Stark's aims and grants him sentience. Ultron disables JARVIS and builds a body from one of the Iron Legion drones. He strikes the Avengers in their party and admits that he intends to save the world by killing its heroes.