@agentuity/sandbox
v3.1.9
Published
Readme
@agentuity/sandbox
Standalone package for the Agentuity Sandbox service. Provides a simple, ergonomic client for creating and managing sandbox environments for code execution.
Installation
npm install @agentuity/sandboxQuick Start
import { SandboxClient } from '@agentuity/sandbox';
const client = new SandboxClient();
// Create a sandbox
const sandbox = await client.create();
console.log(`Created sandbox: ${sandbox.id}`);
// Execute a command
const execution = await sandbox.execute({
command: ['node', '-e', 'console.log("Hello from sandbox!")']
});
console.log(`Execution status: ${execution.status}`);
// Write files to the sandbox
await sandbox.writeFiles([
{ path: '/app/index.js', content: 'console.log("Hello!")' }
]);
// Read a file
const stream = await sandbox.readFile('/app/index.js');
// Clean up
await sandbox.destroy();One-Shot Execution
Use the run() method for a create-execute-destroy lifecycle in one call:
const result = await client.run({
runtime: 'node',
code: 'console.log("Hello!")'
});
console.log(result.stdout);API Reference
SandboxClient
Main client for interacting with the sandbox service.
Constructor
new SandboxClient(options?: SandboxClientOptions)Options:
apiKey- API key (defaults toAGENTUITY_SDK_KEYenv var)url- Sandbox API URL (defaults toAGENTUITY_SANDBOX_URLenv var)orgId- Organization IDlogger- Custom logger instance
Methods
create(options?)- Create a new sandbox, returnsSandboxInstanceconnect(sandboxId)- Connect to an existing sandbox, returnsSandboxInstanceget(sandboxId)- Get sandbox infodestroy(sandboxId)- Destroy a sandboxrun(options, io?)- One-shot create-execute-destroypause(sandboxId)- Pause a sandboxresume(sandboxId)- Resume a paused sandbox
SandboxInstance
Represents a specific sandbox. Returned by create() and connect().
Properties
id- Sandbox IDstatus- Current status
Methods
execute(options)- Execute a commandwriteFiles(files)- Write files to the sandboxreadFile(path)- Read a file from the sandboxlistFiles(path?)- List files in the sandboxmkDir(path, recursive?)- Create a directoryrmFile(path)- Remove a filermDir(path, recursive?)- Remove a directorysetEnv(env)- Set environment variablesget()- Get sandbox infopause()- Pause the sandboxresume()- Resume the sandboxdestroy()- Destroy the sandbox
License
Apache-2.0
