How does it work?
All matter is made of positive nuclei and negative electrons. Usually there are equal amounts of each and the body is neutral. When an object gains or loses electrons, it has an electric charge, measured in coulombs (C). One electron carries −1.602·10−19 C, so 1 µC is an excess of about 6 trillion electrons. Like charges repel, opposite charges attract.
Coulomb's law and the field
The electric field tells you what force would act on a small test charge at each point. Field lines start on positive charges, end on negative ones and never cross; where they are dense, the field is strong. The potential V is energy per unit charge, and voltage is a potential difference. Surfaces of constant potential always cross the field lines at right angles.
Conductors, insulators, induction
In a conductor (metal, salty water, the human body) some of the electrons move freely; in an insulator (rubber, glass, plastic) they are bound to their atoms. A body can be charged by friction (electrons move from one material to the other), by contact (the charge spreads over both bodies) and by induction (a nearby charge pushes electrons around in a conductor; grounding lets some of them flow away). In an insulator the charge doesn't flow, but the molecules polarize — which is why a balloon attracts a neutral wall.
Capacitor
Lightning
In a cumulonimbus cloud the updraft carries ice crystals upward while heavier graupel (soft hail pellets) falls. When they collide in the presence of supercooled water, charge passes between them: in a typical storm positive charge gathers at the top of the cloud, the main negative region lies at the height where it is about −10…−20 °C, and near the base there is sometimes a small positive pocket. The details of this mechanism are still being researched. When the field is strong enough to ionize the air, a stepped leader sets off downward — in jumps of several tens of meters, branching as it goes. Upward streamers rise to meet it from tall objects. When they connect, a bright return stroke surges through the channel; more strokes may follow. Within microseconds the air heats up to about 30,000 K, expands violently, and thunder is born.
Simplifications: the sandbox computes the field in 2D from point charges (smoothed right at each charge); the conductor and the cage are a two-dimensional grid model; the amounts of charge from rubbing are approximate; lightning and Lichtenberg figures grow by a simplified breakdown model on a grid, with exaggerated object sizes and slowed-down time.