For your question, we're going much more in the direction of current "self-driving" cars and autonomous vehicles. We don't quite have the sort of sentient machines like you might have seen in Pixar's Cars, Herbie, Knight Rider or Thomas the Tank Engine, but there are a lot of companies working on self-driving technology. There's already a lot of mainstream vehicles with advanced lane-keeping features and similar that are doing part of the driving autonomously, Tesla's "self-driving" features are pretty advanced, and we've had some autonomous trains and airport shuttlepods for a while now.
If you're asking how that sort of thing works - it's all about sensors like cameras and LIDAR to "see" what's going on around the vehicle and software to respond to what it's measuring in the appropriate way. A lot of regular human-driven cars are now "drive-by-wire" - controls like the throttle and brake aren't directly connected to a physical throttle or brake pad any more, they're sensors and switches that feed your input into a computer, and the computer sends out control actions to motors and solenoids that make the actual moving parts of the car go. For self driving cars, you simply add in another computer sending the inputs digitally based on sensors and cameras rather than a human pressing buttons and switches.
As to a sentient machine like the stories, that sort of thing is a long way off. We don't have any artificial general intelligence that's anywhere close to sentience. There's some pretty cool AI research like GPT-3 and neural networks, but it's still got a long way to go. Even if we were close, an AI clever enough to be sentient would be capable of a lot more than just being a driver - it starts bringing up questions of whether it would want to just be driving around, and what sort of rights an AI might have.