I first need to know if starman is a real human or a robot. If he is a real human, how does he live? How many years can he live in that car?
'Starman' is a mannequin (store dummy) wearing a real SpaceX developed space suit that was a qualification unit, used in designing the space suit for the Commercial Crew program.
During the SpaceX Grasshopper program, where they tested landing a first stage in McGregor Texas they mounted a dummy with a cowboy hat on the base of the Grasshopper vehicle.
Thus SpaceX has a history of employing dummies.
I first need to know if starman is a real human or a robot.
Starman is the name given to the mannequin/space suit occupying the driver's seat of the car. It is not human nor is it a robot.
If he is a real human, how does he live?
If it were human, the spacex suit is meant to be used pressurized. Details about the suit have not been provided other than it's designed to support brief depressurization events - emergencies, typically - that might be encountered in the Dragon spacecraft. It's not intended for spacewalks, moon walks, or mars use. Therefore it's unlikely to be equipped with means for eating or drinking, and diapers are likely to be used for urinating or defecating while in suit.
None of the images provided so far suggest a method or means to carry oxygen or power directly on the suit, or carbon scrubbing apparatus, so it's likely meant to be plugged into support systems.
How many years can he live in that car?
As long as the required supplies were available - air, energy to operate suit systems, etc - a human could survive for as long as one would on earth given lack of food and water. There's no evidence that the suit is connected to anything inside the vehicle, and no obvious support equipment for the suit, so unless it was very cleverly hidden there is no reason to believe that this could happen.
As such if there's a human in there they would live for a matter of minutes as the CO2 levels inside the suit rise to levels which would prevent normal respiration.
If they did hide support systems in the vehicle and connect to the suit through a hidden means, the supply of oxygen and power for the CO2 scrubbers would take up a lot of space, but without extensive engineering the total time would probably be measured in hours and days, and not weeks, months, or years. The lack of food and water may become an issue if the supplies lasted more than a few days.
We don't know anything about the heating/cooling capability of the suit, but if it doesn't manage temperature regulation then it's likely that a human passenger would die of temperature extremes in a matter of hours, possibly days depending on suit insulation.
Regarding cosmic radiation, once you leave the Earth's very protective magnetic field you start to receive gamma rays and other cosmic radiation. While this isn't insignificant, it isn't enough to result in illness or death more quickly than lack of food or water:
Estimates are that humans unshielded in interplanetary space would receive annually roughly 400 to 900 mSv (compared to 2.4 mSv on Earth) and that a Mars mission (12 months in flight and 18 months on Mars) might expose shielded astronauts to roughly 500 to 1000 mSv. These doses approach the 1 to 4 Sv career limits advised by the National Council on Radiation Protection and Measurements (NCRP) for low Earth orbit activities in 1989, and the more recent NCRP recommendations of 0.5 to 2 Sv in 2000 based on updated information on dose to risk conversion factors.
However, you might start having your vision clouded as your eyes become damaged by the radiation. How quickly this happens, and whether it's effects are significant enough for you to notice is still unknown:
To date, however, the only pathology associated with space radiation exposure is a higher risk for radiation cataract among the astronaut corps.
Nonetheless, radiation is not going to kill a human in this situation, they would die of other causes first.