Add v2 sandbox implementation with new API routes and sandbox library

This commit is contained in:
Developers Digest
2025-09-02 19:14:27 -04:00
parent d7ae41ba9d
commit dbf34e2d63
15 changed files with 1978 additions and 0 deletions
+64
View File
@@ -0,0 +1,64 @@
export interface SandboxFile {
path: string;
content: string;
lastModified?: number;
}
export interface SandboxInfo {
sandboxId: string;
url: string;
provider: 'e2b' | 'vercel';
createdAt: Date;
}
export interface CommandResult {
stdout: string;
stderr: string;
exitCode: number;
success: boolean;
}
export interface SandboxProviderConfig {
e2b?: {
apiKey: string;
timeoutMs?: number;
template?: string;
};
vercel?: {
teamId?: string;
projectId?: string;
token?: string;
authMethod?: 'oidc' | 'pat';
};
}
export abstract class SandboxProvider {
protected config: SandboxProviderConfig;
protected sandbox: any;
protected sandboxInfo: SandboxInfo | null = null;
constructor(config: SandboxProviderConfig) {
this.config = config;
}
abstract createSandbox(): Promise<SandboxInfo>;
abstract runCommand(command: string): Promise<CommandResult>;
abstract writeFile(path: string, content: string): Promise<void>;
abstract readFile(path: string): Promise<string>;
abstract listFiles(directory?: string): Promise<string[]>;
abstract installPackages(packages: string[]): Promise<CommandResult>;
abstract getSandboxUrl(): string | null;
abstract terminate(): Promise<void>;
abstract isAlive(): boolean;
// Optional methods that providers can override
async setupViteApp(): Promise<void> {
// Default implementation for setting up a Vite React app
throw new Error('setupViteApp not implemented for this provider');
}
async restartViteServer(): Promise<void> {
// Default implementation for restarting Vite
throw new Error('restartViteServer not implemented for this provider');
}
}