Writing Service in Native Python

TEEX secure service can be written in native Python2.7. We already provide a usable Python environment, including standard Python libraries, in the container. Developers can directly execute a Python script in a container by:

  $ python2.7 path/of/script/your_python.py

Currently, we support all Python grammar (e.g., while, for, List, Tuples) and all standard libraries of Python (e.g., string, re, mutex, math, random, hmac and so on). For the security reason, we forbid or limit some functionalities of standard python libraries, for example, the disk write operation is forbidden.

More details can be found in Restriction.

The details of how to use Python2.7 can be found in Python2.7 documentation,

Getting Input and Returning Result

TEEX secure service is a stateless service. Each time when the service is invoked, it receives the input of the user, performs the service functionalities and returns the result to the user. To help the service get user input and return the result, we provide a Python library called teex. There are two interfaces provided by teex:

  • TEEX_getinput: which gets the input string parsed by user.
  • TEEX_return: which takes a string as an argument and return it to the user

TEEX_getinput only allows the user to parse one input string to the service. If the service needs more than one argument, it should provide a encode method to encode all the arguments into one string and decode the input string by the service logic. The TEEX_return can only be executed once and requires a string variable. Only the first invocation returns the result to the user and all the later invocations will be ignored.


Returning a non-string result may cause runtime error.

Getting Data from Data Provider

A service provider can assign required data to her TEEX secure service (details in Deploying TEEX Secure Service, and a client can also assign data to a task (details in Invoking TEEX Secure Service).

To help the service get these data, we provide a interface in Python library teex.

  • TEEX_getdata(data_index): which gets the data indexed by data_index.

The TEEX_getdata will first get the data from the required data list, including both the service data and the task data. The service data has the smaller index than the task data. For example, if the there are 3 entries in service data list and 4 in task data list. The data with index 0 means the first entry of service data list and the data with index 4 means the second entry in task data list.


In consideration of the security and resource limitation of our TestNet, we have several restrictions on the interfaces used by the security services.

  • Network Restriction
  • File System Restriction
  • Process Restriction
  • Memory and CPU Restriction

Network Restriction: Although the user input and return string are delivered through the network, we forbid the secure service to use the network (e.g., listening on a local port or connect to a remote machine).

File System Restriction: First, the secure service cannot write any file on the worker's machine. Then, we limit the service to read the libraries (e.g., Python standard library). Performing write operation on any file or read operation on an illegal file will be ignored.

Process Restriction: We forbid the secure service to create a new process (by fork syscall) or load a new application in the current process (by exec syscall). Developers can still use the thread to speed up his service.

Memory and CPU Restriction: Due to the resource limitation of the TestNet, we limit the maximal runtime memory which can be used by a secure service to 3GB. This memory including the Python 2.7 runtime. We also limit the CPU execution time of a service. For each invocation, the secure service can run at most 30 minutes.