novita-sandbox
Novita Agent Sandbox JS SDK
A TypeScript/JavaScript SDK for Novita Agent Sandbox environments that provides code execution, desktop automation, and cloud computing capabilities..
Table of Contents
Installation
npm install novita-sandbox
Features
- Code Interpreter: Execute Python, JavaScript, and other languages in isolated environments
- Desktop Automation: Control desktop applications and GUI interactions
- Cloud Computing: Scalable sandbox environments for various computing tasks
- Data Visualization: Built-in charting and visualization capabilities
- File System Operations: Complete file system management and monitoring
Authentication
Get your Novita API key from here.
Usage
Core Sandbox
Use the high-level Novita client to share one set of credentials across namespaces.
import { Novita } from 'novita-sandbox';
const novita = new Novita({
apiKey: process.env.NOVITA_API_KEY || '',
});
// Using the official template `base` by default.
const sandbox = await novita.sandbox.create('base');
// File operations
await sandbox.files.write('/tmp/test.txt', 'Hello, World!');
const content = await sandbox.files.read('/tmp/test.txt');
// Command execution
const result = await sandbox.commands.run('ls -la /tmp');
console.log(result.stdout);
// Real-time monitoring
sandbox.files.watchDir('/tmp', (event) => {
console.log(`File ${event.name} was ${event.type}`);
});
Code Interpreter
The Code Interpreter sandbox is available through the same client.
import { Novita } from 'novita-sandbox';
const novita = new Novita({
apiKey: process.env.NOVITA_API_KEY || '',
});
const sandbox = await novita.codeInterpreter.create();
// Execute Python code
const result = await sandbox.runCode('print("Hello, World!")');
console.log(result.logs);
Desktop Automation
The Desktop sandbox is available through the same client.
import { Novita } from 'novita-sandbox';
const novita = new Novita({
apiKey: process.env.NOVITA_API_KEY || '',
});
const desktop = await novita.desktop.create();
// Take a screenshot
const screenshot = await desktop.screenshot();
// Automate mouse and keyboard
await desktop.leftClick(100, 200);
await desktop.press('Enter');
await desktop.write('Hello, World!');
Documentation
For comprehensive guides and API reference, visit the official documentation.
Template environment scope
setEnvs({...}) adds build-only variables. To retain values in the sandbox, use
setEnvs({...}, { runtime: true }). Dockerfile ENV is persisted at runtime;
Dockerfile ARG remains build-only. Declarations are evaluated in order, with
values in one group reading the preceding environment. Image ENV is literal,
and inherited WORKDIR applies before caller steps.
const template = Template().fromImage("python:3.12-slim");
template.setEnvs({ BUILD_MODE: "release" });
template.setEnvs({ PATH: "/app/bin:$PATH", APP_MODE: "worker" }, { runtime: true });
Mutable image tags are refreshed for each serialization/build. Only successful digest-pinned registry reads are cached, and failed reads are retryable on the same builder. Explicit caller commands and settings override image defaults.
Job.wait(jobId, { timeoutMs }) applies a deadline to polling, request timeouts,
and returned results. A successful response arriving after the deadline is
reported as a timeout.