Any container that doesn't belong to the player, IE is not in a player-owned house can be considered unsafe for storing gear. If you leave stuff in a container you don't own, chances are it'll vanish after a few game-days. No-one is stealing it, just the contents of most containers are refreshed every so often. The new contents are selected by the game from a predefined list. Anything not on that list wont appear in the container when the contents are refreshed. So say you stored a unique sword in a random barrel somewhere. The sword will most likely disappear after either 24 hours or 3 days (the standard pre-set refresh intervals). Next time you visit the barrel, there might only be apples in it. Sometimes your item might survive a refresh and still be there when you look back... but don't count on it.
Player-owned containers do not have their contents refreshed, hence the stuff you leave in it will stay there until you remove it yourself. If things are missing from a player-owned container, it's either because you forgot that you moved them somewhere else or due to a bug in one or more of your saved games.
As for NPC theives; Some people believe that NPCs exchange objects with containers as a matter of course. They don't. An NPC can only exchange items in & out of a container if they are specifically scripted to do so. 99% of NPCs are not scripted to do this. The remaining 1% constitutes quest-specific NPCs (who only exchange pre-defined items from pre-defined containers) and traders. Traders do not normally exchange items with containers that are visible in the game world. Most have their own special containers which are positioned outside of the bitmap where they can't be seen. Sometimes it is possible for the player character to enter "Blue Hell" (fall outside the bitmap), where if you search carefully, you might find one of these special trader chests. Take care what you steal from these chests if you ever find one. Anything you take will never appear in that traders barter menu again. This includes gold. If you steal all the gold from a traders secret chest he'll never have any to trade with, unless you put gold back in the chest again.
Regards to NPCs found in the players home; no, they are not stealing anything. If an NPC is speaking to you as you enter a door, they will often spawn into the new cell with you to finish speaking their line. Sometimes the game will have difficulty knowing where in the cell to spawn them, in which case you may find them... in your bedroom, say.
Most times they will leave straight away. Some NPCs do wander in & out of buildings at random. Although player homes aren't strictly part of the AI wander package (the thing that controls where an NPC can & can't go), the thing with random generators is that they're random. An NPC with a random wander package can effectively go anywhere within the parameters defined by that package. For example, an NPC with a wander package specifically for "Whiterun, Dragonsreach" may enter unlocked cells within Dragonsreach only. An NPC with a wander package for "Whiterun" may enter any unlocked cells within Whiterun, including dragonsreach (and the players home). Wander packages do not negate locked doors, meaning that NPCs can't wander in & out of locked rooms or buildings unless or until the door is unlocked by the player or by a script.
When things in your house get strewn about the place... this isn't because an NPC wandered in and threw all your cabbages on the floor! It's just a glitch in the game. If things are missing they probably fell through the bitmap or were respawned outside of it thanks to a bug in your save game. When items fall through the bitmap they "C.O.W"... go to the Centre Of World. When this happens it's tough luck I'm afraid. You've lost that thing. Either learn the objectID and give it back to yourself using the command console or reload a saved game & hope the bug that caused the problem wasn't present when you saved it.
NPC theives? Yes, there are thief characters but no, they don't actually steal anything. Why they're appearing for you in Riverwood is anyone's guess. Random spawners, saved game bugs, who knows. These things happen!
Most recently, I entered my house in Whiterun to find Lydia and Uthgerd the barbarian stood either side of a seated Faendal. All three butt-ass naked, the cooking pot obscuring Faendal's bits...
"Are you lost" says Lydia!
Erm... yes... I think I'll just go back outside now!
No rhyme or reason for this happening. It just did. All part of what makes Skyrim great!
For those playing on a games console & wondering what the hell a "script" is, or an "AI package"... it's part of the program (game). You can't see it or edit it on a console though. You need a PC to do that!