pythonlinuxcopy-protection

Keeping Python Code Private On Controlled Linux Server


I am trying to see if I can protect my python source code in the following scenario:

  1. I am managing a linux server, where I am the only one to have root privileges
  2. My users have separated user accounts on this server
  3. I want to find a way to install a private pure-python module on this server so that my users may import that module, without them being able to access the code

Is there a way to do such a thing?


Solution

  • It sounds like you want a code obfuscation tool, which makes code unreadable without some very dedicated reverse engineering by renaming variables, functions, modules, etc., replacing their names with gibberish.

    If a computer can execute code, then someone with admin access to that computer can also read the compiled code, no exceptions. If you don't want someone to steal your logic, you obfuscate. If you don't want people to pirate your software (use it without paying), you can add some software protections (research how other subscription software is protected) and obfuscate those as well, so that it's hard to bypass the restrictions and clearly in breach of IP laws.

    Alternatively (if suitable, which it usually is), you might want to run the code on your own server and publish an API for your customers to use. For their convenience, you might also develop an abstraction of the public API for clients to use. This won't let clients access code at all; clients indirectly ask the server to do something, and the server does it if everything is in order (the client has a valid subscription, for example).