First of all you will need a Development Environment with SharePoint 2010 and Visual Studio 2010.
Download and install SharePoint 2010 SDK.
Download and install Visual Studio 2010 SharePoint Power Tools.
Then you have to enable Microsoft SharePoint Foundation Sandboxed Code Service in Central Administration. Go to Central Administration and then click Manage services on server.
Start Microsoft SharePoint Foundation Sandboxed Code Service.
Open Visual Studio 2010 and create a new Empty SharePoint Project.
Right Click the Project, then Add -> Add Existing Item. In the new dialog just choose Visual Web Part (Sandboxed).
Add code into the Web Part, build the project and then right click on the project and click Package. You should find into the project’s folder \bin\debug WSP file.
Login with a user which has administrative privileges into your Office 365. Go to the Home page. Then under Team sites and documents click Manage Team Sites.
Under Site Collection Administration click Go to top level site settings. Under Galleries click Solutions.
Upload here your WSP file and then Activate the Solution. Now when you Edit a Page in any of your SharePoint Sites you should see your Web Part in the Custom Web Parts Section.
Trackback from your site.