Haven't really thought about it, to be honest.
But I imagine you could do quite a bit using calibre's APIs from a custom calibre-debug script. Of course it only supports EPUB2.
Scripted creation of EPUBs seems a bit counterintuitive, since at it's core an EPUB GUI like Sigil or calibre's ebook-edit is an API for automatically resolving name changes, wrapped around a plaintext editor and a ZIP compressor.
And it doesn't get much more basic than a plaintext editor.