Create a .env file in your project folder (if it doesn’t exist), and configure the API key and API domain address.
For JavaScript and TypeScript projects, you need to import the dotenv/config package in your project; for Python projects, you need to import the dotenv library in your project and call the load_dotenv method to load environment variables.
For details, please refer to the example.
.env
NOVITA_API_KEY=sk_*** # Novita API key obtained from previous steps
Or you can configure the API key and API domain address by setting environment variables in your terminal.
Bash
export NOVITA_API_KEY=sk_*** # Novita API key obtained from previous steps
Below is a simple example showing how to create a sandbox through the SDK and run specified commands.
// index.tsimport 'dotenv/config'import { Sandbox } from 'novita-sandbox/code-interpreter'// The .env file should be located in the project root directory// dotenv/config will automatically look for .env in the current working directory// Or // You can set the environment variable in the command line// export NOVITA_API_KEY=sk_***const sandbox = await Sandbox.create()const execution = await sandbox.runCode('print("hello world")')console.log(execution.logs)const files = await sandbox.files.list('/tmp')console.log(files)// Close sandbox when no longer neededawait sandbox.kill()
Execute the following commands to run the above code.