Take in code and execute it in a sandbox. The output will be the result of the code execution. An example of how it can be used would be to run code generated by a LLM in a safe environment.
Create a reusable service configuration that points to the MCP server and standardizes how you pass arguments and read results. This lets your agent easily interact with the Code tools in a consistent manner.
Create a client using an ATXP account by importing the ATXP client SDK and other dependencies.
Copy
Ask AI
// Import the ATXP client SDKimport { atxpClient, ATXPAccount } from '@atxp/client';// Read the ATXP account details from environment variablesconst atxpConnectionString = process.env.ATXP_CONNECTION;// Create a client using the `atxpClient` functionconst client = await atxpClient({ mcpServer: codeService.mcpServer, account: new ATXPAccount(atxpConnectionString),});
3
Use the Code service in your agent
Call the Code tool by passing your natural‑language instruction as the argument the getArguments method.Read the response using the getResult method.
Copy
Ask AI
const code = "print('Hello, world!')";const language = "python";try { const result = await client.callTool({ name: codeService.executeCodeToolName, arguments: codeService.getArguments(code, language), }); const result = codeService.getResult(result); console.log('Status:', result.status); console.log('Output:', result.output); console.log('Exit code:', result.exitCode);} catch (error) { console.error(`Error with ${codeService.description}:`, error); process.exit(1);}
You should see the result of the code printed in your console.