@anek-codes/vm
v0.1.2
Published
Common sandbox provider SDK for Anek VM
Maintainers
Readme
Anek VM TypeScript SDK
@anek-codes/vm provides a common sandbox provider interface for Daytona, Anek, Vercel, and E2B. It exposes shared types, command helpers, and provider implementations.
Install
npm install @anek-codes/vmProvider SDKs are optional peer dependencies. Install the providers you need:
npm install @daytonaio/sdk
npm install @vercel/sandbox
npm install @e2b/sdkQuick start
import { DaytonaSandboxProvider, SandboxLogger } from '@anek-codes/vm'
const provider = new DaytonaSandboxProvider()
const logger: SandboxLogger = {
info: async () => {},
error: async () => {},
}
const result = await provider.createSandbox(
{
taskId: 'task-123',
repoUrl: 'https://github.com/acme/repo',
apiKeys: {
OPENAI_API_KEY: process.env.OPENAI_API_KEY,
},
},
logger,
)
if (result.success && result.instance) {
await result.instance.runCommand('npm', ['install'])
const url = await result.instance.getDomain(3000)
await result.instance.stop()
}Streaming and PTY
Use stdout and stderr to stream output when supported. Set pty to force PTY execution.
await result.instance.runCommand('npm', ['run', 'build'], {
stdout: process.stdout,
stderr: process.stderr,
pty: true,
})Provider registry
import { getSandboxProvider } from '@anek-codes/vm'
const provider = getSandboxProvider('vercel')
const result = await provider.createSandbox(config, logger)Environment variables
- Daytona:
DAYTONA_API_KEY, optionalDAYTONA_API_URL,DAYTONA_TARGET,DAYTONA_SNAPSHOT - Anek:
ANEK_API_KEY, optionalANEK_API_URL,ANEK_TARGET,ANEK_SNAPSHOT - Vercel:
SANDBOX_VERCEL_TEAM_ID,SANDBOX_VERCEL_PROJECT_ID,SANDBOX_VERCEL_TOKEN - E2B:
E2B_API_KEYorE2B_ACCESS_TOKEN
Provider config overrides
You can pass provider specific settings through providerConfig.
await provider.createSandbox(
{
taskId: 'task-123',
repoUrl: 'https://github.com/acme/repo',
providerConfig: {
snapshot: 'my-snapshot',
autoStopInterval: 30,
},
},
logger,
)Build
cd vm-sdk/typescript
npm install
npm run buildTesting
The SDK includes comprehensive tests using Node.js's built-in test runner:
# Run all tests
npm test
# Run unit tests only
npm run test:node
# Type check
npm run type-checkTests cover:
- Provider interfaces and type definitions
- Command utilities and project directory mapping
- Provider registry and factory functions
- Streaming and PTY support
- Lifecycle management (start, stop, archive, delete)
- Error handling
API Reference
Providers
| Provider | Class | Required Env Vars |
|----------|-------|-------------------|
| Daytona | DaytonaSandboxProvider | DAYTONA_API_KEY |
| Anek | AnekSandboxProvider | ANEK_API_KEY |
| Vercel | VercelSandboxProvider | SANDBOX_VERCEL_TEAM_ID, SANDBOX_VERCEL_PROJECT_ID, SANDBOX_VERCEL_TOKEN |
| E2B | E2BSandboxProvider | E2B_API_KEY or E2B_ACCESS_TOKEN |
ISandboxInstance Methods
| Method | Description |
|--------|-------------|
| runCommand(cmd, args, options?) | Execute a command in the sandbox |
| getDomain(port) | Get public URL for a port |
| start() | Start a stopped sandbox |
| stop() | Stop the sandbox |
| delete() | Permanently delete the sandbox |
| archive() | Archive sandbox to storage (Daytona/Anek only) |
| isHealthy() | Check if sandbox is responsive |
| getMetadata() | Get sandbox metadata |
| getProviderInstance() | Get underlying SDK object |
CommandOptions
interface CommandOptions {
cwd?: string // Working directory
detached?: boolean // Run in background
env?: Record<string, string>
stdout?: NodeJS.WritableStream
stderr?: NodeJS.WritableStream
timeout?: number // Timeout in seconds
stream?: boolean // Enable streaming
pty?: boolean | PtyOptions // Use PTY
}
interface PtyOptions {
cols?: number // Terminal columns (default: 200)
rows?: number // Terminal rows (default: 50)
timeoutMs?: number
}Helper Functions
// Get project directory for a provider
getProjectDir('daytona') // '/home/developer'
getProjectDir('e2b') // '/home/user'
getProjectDir('vercel') // '~'
// Run command in project directory
await runInProject(sandbox, 'npm', ['install'])
// Get provider by type
const provider = getSandboxProvider('daytona')
// Get available provider types
const types = getAvailableProviderTypes()
// Register custom provider
registerSandboxProvider(myCustomProvider)Contributing
- Fork the repository
- Create a feature branch
- Make changes and add tests
- Run
npm testto verify - Submit a pull request
License
MIT
