Problem "defaults write" commands with apps sandboxed

It seems that “defaults write” commands with sandboxed Apple apps (Mail, Safari, etc.) don’t work. even deleting the old plist file (in ~/Library/Preferences).
For example, the following command that enables/disables the preview of attachments in “Mail” works fine in the Terminal but not via the Shell.Execute command!

Shell1.Execute ("defaults write ~/Library/Containers/ DisableInlineAttachmentViewing -bool true")
Shell1.Execute ("defaults delete ~/Library/Containers/ DisableInlineAttachmentViewing")

This is the first time I have faced this kind of problem. Does anyone have an explanation/answer?

I have this error message:

You should never try to manipulate plist files directly. Instead use the NSUserDefaults API, which you can find in the Ohanaware App Kit or the MBSPlugin.

Or MacOSLib (free)