Say a computer running an AI exists on a planet with no biological life. Say it has access to a rather extensive preexisting manufacturing plant and can control a fleet of machines capable of performing the whole process of mining and transporting raw material to build and assemble more machines, fabricate replacement parts, or build new things of its own design. Can it maintain itself for a long period of time?
What possible challenges and dangers would it need to overcome, and how might it do so?
What natural resources must be available for it to build space traveling vehicles, capable of gathering further resources? Would this even be a feasible course of action for it?
Updates for greater specificity:
Assume its hardware and construction is similar to a present-day earthly supercomputer (just bigger and hand-wavily enough faster to run the AI in real time). For fun, geological stability, and difficulty in resource extraction, lets say it starts out on (or in) a largish asteroid (rather, a smallish moon) in orbit around a the previously mentioned lifeless planet. Lets say the planet is rocky and rich in similar elements as earth. Say this planet had some plant life at one point, so there is carbon and oil which can be extracted for plastics (at least for a little while).
It has access to a nuclear power source, so it isn't necessarily dependent on getting energy from the system's star, but that's an option too.
The AI's goal is to learn as much as it can, so it may have an interest in sending probes to other systems. Or going there itself, if it can fit itself out with ion drives and carry enough $\Delta v$ to escape one system and arrange to be captured by another.