MCPcopy Create free account
hub / github.com/cloudflare/computer / exec

Method exec

packages/computer/src/runtime/runtime.ts:39–85  ·  view source on GitHub ↗
(
    source: string,
    options: WorkspaceRuntimeExecOptions<E> = {},
  )

Source from the content-addressed store, hash-verified

37 options: WorkspaceRuntimeExecOptions<undefined>,
38 ): Promise<WorkspaceRuntimeExecHandle<undefined>>;
39 async exec<E extends ExecEncoding>(
40 source: string,
41 options: WorkspaceRuntimeExecOptions<E> = {},
42 ): Promise<WorkspaceRuntimeExecHandle<E>> {
43 if (options.id !== undefined) assertExecutionId(options.id);
44 const backend = this.#backend(options.backend);
45 if (options.input !== undefined && !this.#options.callableBackendIds.has(backend)) {
46 throw new Error(
47 `Backend ${JSON.stringify(backend)} is not callable; it does not accept structured input.`,
48 );
49 }
50 if (this.#options.commandBackendIds.has(backend)) {
51 if (options.input !== undefined) {
52 throw new Error(
53 `Backend ${JSON.stringify(backend)} is not callable; it does not accept structured input.`,
54 );
55 }
56 const shell = this.#options.shell();
57 const handle = await (
58 shell.exec as unknown as (
59 command: string,
60 options: Record<string, unknown>,
61 ) => Promise<ExecHandle<E>>
62 )(source, {
63 backend,
64 cwd: options.cwd,
65 encoding: options.encoding,
66 id: options.id,
67 timeoutMs: options.timeoutMs,
68 env: options.env,
69 stdin: options.stdin,
70 });
71 return wrapCommandHandle(handle, backend);
72 }
73
74 const runtime = await this.#options.moduleHandle(backend);
75 const envelope = await runtime.exec({
76 id: options.id,
77 source,
78 cwd: options.cwd,
79 input: options.input,
80 env: options.env,
81 stdin: options.stdin,
82 timeoutMs: options.timeoutMs,
83 });
84 return wrapModuleHandle(runtime, backend, envelope.id, envelope.events, options.encoding);
85 }
86
87 getExec(id: string): Promise<WorkspaceRuntimeExecHandle<undefined>>;
88 getExec(

Callers

nothing calls this directly

Calls 7

#backendMethod · 0.95
wrapCommandHandleFunction · 0.85
wrapModuleHandleFunction · 0.85
hasMethod · 0.80
shellMethod · 0.80
assertExecutionIdFunction · 0.70
execMethod · 0.65

Tested by

no test coverage detected