Test Code Remotely with Ratio1 – Build Your Own Sandbox in Minutes
Education
Introduction
Imagine that you can test your code remotely in a secure, decentralized environment. Well, that is not only possible but also incredibly easy with the Ratio1 Protocol. Today, I’m going to show you how to use the web app at sandbox.ratio1.ai, where you can play with code using our ready-made templates or create something from scratch. I’ll also guide you on how to build your own sandbox in just a few steps.
To put that into perspective, here is a screenshot of the web app interface:
Getting Started with sandbox.ratio1.ai
The web app offers users a variety of ready-to-use code templates, making it simple to get started. You can either modify these templates to suit your needs or write your own code from scratch.
Code Example: Fibonacci Sequence Prediction
Here’s an example of a template that calculates the Fibonacci sequence and predicts the next elements:
With just a few lines of code, you can run a predictive analysis and even calculate the error of the prediction.
Safety and Security: What Happens if You Run Harmful Code?
For security reasons some operations are not allowed. For example code which attempts to delete files from the processing node will be rejected as will specific imports such as os. To offer some degree of flexibility, though we have made accessible a range of utility functions via our API – as you saw in the Fibonacci example above. Here is an example of a script which would not pass:
The system is designed to block such unsafe operations while still providing users with powerful tools to experiment within the sandbox.
Build Your Own Code Sandbox in Minutes
Let’s now walk through how you can quickly deploy your own code sandbox using the PyE2 library. No need to clone a GitHub repository—just follow the simple steps below.
Step-by-Step Guide to Deploying Your Own Sandbox
1. Install the PyE2 Library
2. Connect to the network
Use the PyE2 library to connect to a node and deploy your code execution and interface endpoints:
3. Create your Custom WebApp
After connecting to the node we need to define a WebApp instance:
The code above will create a WebApp instance that will be accessible through an Ngrok edge at https://naeural-001.ngrok.app/docs .
4. Define an endpoint
We have the domain, let’s create an endpoint.
This method will receive some code and will attempt to execute it and return the result. We can attach it to the domain created before as follows:
After this it will be accessible at https://naeural-001.ngrok.app/remote_execute .
5. Create our interface
Up until now we successfully wrote a WebAPI on which one can execute code. Now let’s attach an interface to it.
And just like that, you have got an interface where users can write code.
6. Finally deploy
All is left now is just one line of code to start the magic:
Full Example Code
Below is the complete code to deploy your custom sandbox web app:
Conclusion
Testing code remotely was never easier, and with Ratio1, fast and secure, too. Give the templates available in the sandbox.ratio1.ai a try or create your own sandbox in a few lines of code.
Feel free to give that a shot and share with the community! If you have any questions, go ahead and comment or reach out to us. Happy coding!
Andrei Ionut Damian
Dec 13, 2024
©Ratio1 2024. All rights reserved.