Skip to main content

Goals

  • Make an accounting environment using the OpenReward library.
  • Deploy the environment to OpenReward.
  • Sample from the environment using a model of your choice.

Prerequisites

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

Setup

First, make sure you’ve installed the openreward library:
In the Your First Environment tutorial, we made a mathematics environment. But the environment was simple; the agent did not, for example, have access to a computer to perform a task. In this tutorial we will make an environment that requires an agent to use a computer. More specifically, we give the agent access to a Sandbox. Sandboxes support an extremely wide range of possible environments. In this tutorial we’ll setup a simple accountancy task where an agent has access to files and has use sandbox tools to find the answer. To begin we’ll initialise our project with a sandbox template:
The template contains server.py, sandbox_env.py, Dockerfile and requirements.txt. If you look inside sandbox_env.py, you can see a SandboxEnv is defined. It looks very similar to any other ORS environment, but the key addition is a sandbox:
You should read the Sandboxes docs for a full rundown of how this works. Note that you must use the AsyncOpenReward client for sandbox environments. The key thing to note is that a sandbox is tied to an environment on OpenReward, so unlike the ordinary ORS servers, we’ll need to connect our server to an OpenReward environment space to utilise this compute. To do this, let’s create our environment on OpenReward. We’ll create an environment called AccountantEnv. New environment Once you’ve done this, let’s alter our sandbox_env.py (make sure to replace with your username):
Now we can run the ORS server locally. First, install the requirements and run server.py:
This environment is now running on port 8080. We will leave this running. Now let’s see how we can interact with the SandboxEnv. Choose your model provider of choice and write the following file to test_agent.py:
1

Set your API keys

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

Create your code

Save this as test_agent.py:
3

Run your code

As we can see the agent utilises the bash tool and is able to explore a file system with the environment. But as we can see, there is nothing in the file system right now. Let’s now give the agent access to a file in the file system. We’ll use this transactions.csv. Let’s upload it to a folder called agent in the Files tab of our environment: Uploading agent files Now we want to mount this specific folder to the sandbox for the agent to use, we can do this as follows:
We’ll also update the prompt to let the agent know where to find the files:
Now let’s rerun the test_agent.py file:
As we can see, the agent now has access to the transactions.csv file and managed to open to see its contents. Now the agent has access to this file, we can construct a task for the agent that has a reward. In the transactions spreadsheet, we have a list of transactions. We’ll task the agent with calculating the total balance. The reward in this case is easy to verify: the agent either gets the right balance, or it doesn’t. Here is an implementation for this type of environment. Copy it (replacing with your username) to sandbox_env.py:
We’ll also update server.py with the new name:
Run the new server and then run test_agent.py:
Great! We can see that the agent successfully managed to process the file and calculate the correct answer.

Conclusion

This concludes this tutorial. If you want to host your environment on OpenReward, then the steps are the same as with any other environment.