Problem "defaults write" commands with apps sandboxed

Hello,
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/com.apple.mail/Data/Library/Preferences/com.apple.mail.plist DisableInlineAttachmentViewing -bool true")
and
Shell1.Execute ("defaults delete ~/Library/Containers/com.apple.mail/Data/Library/Preferences/com.apple.mail.plist DisableInlineAttachmentViewing")

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

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)