Skip to main content
Setting environment secrets

Goals

  • Make a mathematics code execution environment using OpenReward and Daytona.
  • Deploy the environment to OpenReward.
  • Sample from the environment using a model of your choice.

Prerequisites

  • You have completed the Your First Environment tutorial
  • An OpenReward account
  • An OpenReward API key
  • A Daytona API key
  • An API key and SDK for your model provider of choice (e.g. OpenAI, Anthropic, Google, OpenRouter)

Setup

Environments in OpenReward are written using ORS. ORS is implemented in the OpenReward Python library, and we will use it for this tutorial. You can install the library using pip or uv:
You should also install the daytona Python SDK:

Introduction

ORS environments can be configured to work with any sandbox provider. In this tutorial we will show how to initialise a Daytona sandbox within an ORS environment. We’ll setup a simple mathematics environment and give an agent access to a sandbox for executing code. By the end of this tutorial, you will understand how to use Daytona as an integration for making environments with ORS and OpenReward.

Getting Started

In the Your First Environment tutorial, we built a mathematics environment using the GSM8K dataset. We will use a similar dataset here, but this time we will give an agent an access to a Daytona sandbox for code execution. First, let’s initialise our environment gsm8ksandbox:
Next we’ll download the two parquet files from the GSM8K HuggingFace repository and put them in the root of our project:
A single row of data from the train set looks as follows:
Next we’ll write a new server file. This will involve:
  • Loading the tasks from the parquet files
  • Verifying the answer is correct - we’ll use the MathVerify library for this.
Install the math-verify requirement:
Now we are going to modify our environment by including a Daytona sandbox. First, we’ll adjust our __init__:
Next, we’ll add a setup and teardown method:
These methods ensure that when a session begins, we create a sandbox, and when a session ends, we delete it. Lastly, we can add a tool that relies on code execution. We’ll add a bash tool. First we’ll add the Pydantic model:
and then we’ll add the bash tool to the class:
Now we can test this environment. First run the server as before:
Now choose a model provider of your choice and sample from the environment:
1

Set your API key

Make sure you have an API key for OpenAI, and set the environment variable:
2

Create your code

Save this as sample_agent.py:
3

Run your code

Example output:
Nice one! We have a working ORS environment. Now we’ll see how we can host the environment on OpenReward. The benefits of using OpenReward are:
  • Infrastructure: you do not have to set up infrastructure and compute to host the environment yourself. We take care of this and you are only charged based on your actual usage of the environment.
  • Discovery: your environment can be discovered and used by other users of the platform, helping drive adoption and attention to your work.

Host on OpenReward

Log into OpenReward, press the plus icon in the navbar and press New Environment: New environment button Next, fill in information about the environment and press Create Environment: New environment button You will be redirected to your new environment and will see setup instructions: Environment Setup

Upload environment files

We will need a way to use the train and test parquet files in our environment. We’ll upload these to the environment files: Click on the Files tab and upload each file: Environment Setup Files are mounted to the environment server at the /orwd_data directory. We’ll need to reference this folder in our server.py. Make the following change:
Note: you may want to set an environment variable instead of hardcoding like above so you can continue to test locally (without the /orwd_data prefix).

Write the Dockerfile and requirements

We’ll need a Dockerfile in our repository:
We’ll need to update requirements.txt:

Push to GitHub and connect

Next, push your environment code to a GitHub repository. Once your GitHub repository is ready, go to your OpenReward environment and connect the repository: Connect GitHub You will be given a choice for how much compute you would like to allocate for it. We’ll use a low compute configuration since this is a simple environment. Press Connect GitHub and your first build will begin. To check the progress of the build, click the Deployments tab: Check Builds You can click on the latest build row to see logs: Check Builds The build logs show the progress of building the environment. The runtime logs show any calls to the environment server, and can be useful for diagnosing errors.

Sample from your environment

Now your environment is hosted on OpenReward, we can sample from it:
1

Set your API keys

Make sure you have API keys for OpenReward and OpenAI, and set these as environment variables:
2

Create your code

Save this as quickstart.py:
3

Run your code

Example output:
Importantly, if you are publishing your environment, you should update your SDK example and let users know that your environment needs a DAYTONA_API_KEY. Press Edit Settings near the SDK example then insert the code for environment variables: Setting environment secrets