Overhead electrification is a long term goal for the non-Metro UK rail network but it is a long way off.
The other method is an electric train with a diesel generator car.
Given that a considerable amount of the UK rail routes date from the late 1800s there are a lot of places where tracks cross roads and therefore mix with other forms of transport (including pedestrians). It's surprising just how little there is in between a pedestrian and a live rail in these situations, here's an example 5 miles or so away from central London: https://maps.app.goo.gl/nPcJM1YxBexaDDKY6
One of those live third rails start less than 5 yards away from where pedestrians regularly walk, with just some angled planks of wood to stop you walking towards them.
There's a strong "stay away from train tracks" education whilst growing up.
Those who grew up in the 70s/80s had the benefit of some utterly horrific public information safety films such as https://player.bfi.org.uk/free/film/watch-the-finishing-line... (well, that one was never used in the end, but it sets the tone...)
More horror here: https://artofthemovies.co.uk/blogs/original-movie-posters/sc...